[Question]
  [
This challenge is a little tricky, but rather simple, given a string `s`:
```
meta.codegolf.stackexchange.com
```
Use the position of the character in the string as an `x` coordinate and the ascii value as a `y` coordinate. For the above string, the resultant set of coordinates would be:
```
0, 109
1, 101
2, 116
3, 97
4, 46
5, 99
6, 111
7, 100
8, 101
9, 103
10,111
11,108
12,102
13,46
14,115
15,116
16,97
17,99
18,107
19,101
20,120
21,99
22,104
23,97
24,110
25,103
26,101
27,46
28,99
29,111
30,109
```
---
Next, you must calculate both the slope and the y-intercept of the set you've garnered using [Linear Regression](https://en.wikipedia.org/wiki/Simple_linear_regression), here's the set above plotted:
[![Plot](https://i.stack.imgur.com/YCujs.png)](https://i.stack.imgur.com/YCujs.png)
Which results in a best fit line of (0-indexed):
```
y = 0.014516129032258x + 99.266129032258
```
Here's the ***1-indexed*** best-fit line:
```
y = 0.014516129032258x + 99.251612903226
```
---
So your program would return:
```
f("meta.codegolf.stackexchange.com") = [0.014516129032258, 99.266129032258]
```
Or (Any other sensible format):
```
f("meta.codegolf.stackexchange.com") = "0.014516129032258x + 99.266129032258"
```
Or (Any other sensible format):
```
f("meta.codegolf.stackexchange.com") = "0.014516129032258\n99.266129032258"
```
Or (Any other sensible format):
```
f("meta.codegolf.stackexchange.com") = "0.014516129032258 99.266129032258"
```
Just explain why it is returning in that format if it isn't obvious.
---
Some clarifying rules:
```
- Strings are 0-indexed or 1 indexed both are acceptable.
- Output may be on new lines, as a tuple, as an array or any other format.
- Precision of the output is arbitrary but should be enough to verify validity (min 5).
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") lowest byte-count wins.
  
[Answer]
# Octave, ~~29~~ ~~26~~ ~~24~~ 20 bytes
```
@(s)s/[!!s;1:nnz(s)]
```
[Try it Online!](https://tio.run/#J806d)
We have the model
```
y= intercept *x^0 + slope * x
 = intercept * 1  + slope * x
```
Here `y` is the ASCII value of string `s`
To find parameters intercept and slope we can form the following equation:
```
s = [intercept slope] * [1 X]
```
so
```
[intercept slope] = s/[1 x]
```
`!!s` converts a string to a vector of ones with the same length as the string.  
The vector of ones is used for estimation of the intercept.  
`1:nnz(s)` is range of values from 1 to number of elements of the string used as `x`.
Previous answer
```
@(s)ols(s'+0,[!!s;1:nnz(s)]')
```
For test paste the following code into [Octave Online](http://octave-online.net)
```
(@(s)ols(s'+0,[!!s;1:nnz(s)]'))('meta.codegolf.stackexchange.com')
```
A function that accepts a string as input and applies ordinary least squares estimation of model `y = x*b + e`
The first argument of ols is `y` that for it we transpose the string `s` and add with number 0 to get its ASCII code.
[Answer]
# TI-Basic, 51 (+ 141) bytes
Strings are 1-based in TI-Basic.
```
Input Str1
seq(I,I,1,length(Str1->L1
32+seq(inString(Str2,sub(Str1,I,1)),I,1,length(Str1->L2
LinReg(ax+b)
```
Like the other example, this outputs the equation of the best fit line, in terms of X. Also, in Str2 you need to have this string, which is 141 bytes in TI-Basic: 
```
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~
```
The reason this cannot be a part of the program is because two characters in TI-Basic cannot be automatically added to a string. One is the `STO->` arrow, but this is not a problem because it is not a part of ASCII. The other is the string literal (`"`), which can be stringified only by typing into a `Y=` equation and using `Equ>String(`.
[Answer]
## R, 46 45 bytes
```
x=1:nchar(y<-scan(,""));lm(utf8ToInt(y)~x)$co
```
Reads input from stdin and for the given test case returns (one-indexed):
```
(Intercept)           x 
99.25161290  0.01451613 
```
[Answer]
# Python, ~~82~~ 80 bytes
-2 bytes thanks to @Mego
Using `scipy`:
```
import scipy
lambda s:scipy.stats.linregress(range(len(s)),list(map(ord,s)))[:2]
```
[Answer]
# Mathematica, 31 bytes
```
Fit[ToCharacterCode@#,{1,x},x]&
```
Unnamed function taking a string as input and returning the actual equation of the best-fit line in question. For example, `f=Fit[ToCharacterCode@#,{1,x},x]&; f["meta.codegolf.stackexchange.com"]` returns `99.2516 + 0.0145161 x`.
`ToCharacterCode` converts an ASCII string to a list of the corresponding ASCII values; indeed, it defaults to UTF-8 more generally. (Kinda sad, in this context, that one function name comprises over 48% of the code length....) And `Fit[...,{1,x},x]` is the built-in for computing linear regression.
[Answer]
# Node.js, 84 bytes
Using [`regression`](https://www.npmjs.com/package/regression):
```
s=>require('regression')('linear',s.split``.map((c,i)=>[i,c.charCodeAt()])).equation
```
## Demo
```
// polyfill, since this is clearly not Node.js
function require(module) {
  return window[module];
}
// test
["meta.codegolf.stackexchange.com"].forEach(function test(string) {
  console.log(string);
  console.log(this(string));
},
// submission
s=>require('regression')('linear',s.split``.map((c,i)=>[i,c.charCodeAt()])).equation
);
```
```
<script src="https://cdn.rawgit.com/Tom-Alexander/regression-js/master/src/regression.js"></script>
```
[Answer]
## Sage, 76 bytes
```
var('m','c')
y(x)=m*x+c
f=lambda x:find_fit(zip(range(len(x)),map(ord,x)),y)
```
Hardly any golfing, probably longer than a golfed Python answer, but yeah...
[Answer]
# [MATL](https://github.com/lmendo/MATL), 8 bytes
```
n:G3$1ZQ
```
1-based string indexing is used.
[Try it online!](https://tio.run/nexus/matl#@59n5W6sYhgV@P@/em5qSaJecn5Kanp@TppecUlicnZqRXJGYl56KlA4Vx0A "MATL – TIO Nexus")
### Explanation
```
n:     % Input string implicitly. Push [1 2 ... n] where n is string length.
       % These are the x values
G      % Push the input string. A string is an array of chars, which is
       % equivalent to an array of ASCII codes. These are the y values
3$     % The next function will use 3 inputs
1      % Push 1
ZQ     % Fit polynomial of degree 1 to those x, y data. The result is an
       % array with the polynomial coefficients. Implicitly display
```
[Answer]
# [J](http://jsoftware.com/), 11 bytes
```
3&u:%.1,.#\
```
This uses one-based indexing.
[Try it online!](https://tio.run/nexus/j#@5@mYGulYKxWaqWqZ6ijpxzDlZqcka@QpqCem1qSqJecn5Kanp@TpldckpicnVqRnJGYl54KFM5V//8fAA "J – TIO Nexus")
## Explanation
```
3&u:%.1,.#\  Input: string S
         #\  Get the length of each prefix of S
             Forms the range [1, 2, ..., len(S)]
      1,.    Pair each with 1
3&u:         Get the ASCII value of each char in S
    %.       Matrix divide
```
[Answer]
# JavaScript, ~~151~~ 148 bytes
```
s=>([a,b,c,d,e]=[].map.call(s,c=>c.charCodeAt()).reduce(([a,b,c,d,e],y,x)=>[a+1,b+x,c+x*x,d+y,e+x*y],[0,0,0,0,0]),[k=(e*a-b*d)/(c*a-b*b),(d-k*b)/a])
```
More readable:
```
function f(s) {
  var [n, sx, sx2, sy, sxy] = [].map.call(s, c => c.charCodeAt(0))
    .reduce(([n, sx, sx2, sy, sxy], y, x) => [
      n + 1,
      sx + x,
      sx2 + x * x,
      sy + y,
      sxy + x * y
    ], [0, 0, 0, 0, 0]);
  var k = (sxy * n - sx * sy) / (sx2 * n - sx * sx);
  return [k, (sy - k * sx) / n];
}
$(() => $('#run').on('click', () => console.log(f($('#input').val()))));
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="input" style="width: 100%">meta.codegolf.stackexchange.com</textarea>
<button id="run">Run</button>
```
[Answer]
# Javascript (ES6), 112 bytes
```
s=>[m=(a=b=c=d=0,([...s].map((u,x)=>{a+=n=x,b+=y=u.charCodeAt(),c+=x*x,d+=x*y}),++n)*d-a*b)/(n*c-a*a),b/n-m*a/n]
```
```
F=s=>[m=(a=b=c=d=0,([...s].map((u,x)=>{a+=n=x,b+=y=u.charCodeAt(),c+=x*x,d+=x*y}),++n)*d-a*b)/(n*c-a*a),b/n-m*a/n]
const update = () => {
  console.clear();
  console.log(F(input.value));
};
input.oninput = update;
update();
```
```
#input {
  width: 100%;
  box-sizing: border-box;
}
```
```
<input id="input" type="text" value="meta.codegolf.stackexchange.com" length=99/>
<div id="output"></div>
```
[Answer]
# Haskell, ~~154~~ 142 bytes
```
import Statistics.LinearRegression
import Data.Vector
g x=linearRegression(generate(Prelude.length x)i)$i.fromEnum<$>fromList x
i=fromIntegral
```
It is far too long for my likings because of the imports and long function names, but well. I couldn't think of any other Golfing method left, although I'm not expert on the area of golfing imports.
Stripped 12 bytes by replacing `ord` and the import of `Data.Char` by fromEnum thanks to nimi.
[Answer]
# SAS Macro Language, 180 bytes
Uses 1-based indexing.
The solution gets to be pretty wordy when the output is only the slope and intercept.
```
%macro t(a);data w;%do i=1 %to %length(&a);x=&i;y=%sysfunc(rank(%substr(&a,&i,1)));output;%end;run;proc reg outtest=m;model y=x/noprint;run;proc print data=m;var x intercept;%mend;
```
[Answer]
## Clojure, 160 bytes
No built-ins, uses the iterative algorithm described at [Perceptron article](https://en.wikipedia.org/wiki/Perceptron#Steps). Might not converge on other inputs, in that case lower the learning rate `2e-4` and maybe increase the iteration count `1e5`. Not sure if the non-iterative algorithm would have been shorter to implement.
```
#(nth(iterate(fn[p](let[A apply e(for[x(range(count %))](-(int(get % x))(*(p 1)x)(p 0)))](mapv(fn[p e](+(* e 2e-4)p))p[(A + e)(A +(map *(range)e))])))[0 0])1e5)
```
Example:
```
(def f #( ... ))
(f "meta.codegolf.stackexchange.com")
[99.26612903225386 0.014516129032464659]
```
[Answer]
## Maple, 65 bytes
```
Statistics:-LinearFit(b*x+a,[$(1..length(s))],convert(s,bytes),x)
```
Usage:
```
s := "meta.codegolf.stackexchange.com";
Statistics:-LinearFit(b*x+a,[$(1..length(s))],convert(s,bytes),x);
```
Returns:
```
99.2516129032259+0.0145161290322573*x
```
Notes: This uses the [Fit](http://www.maplesoft.com/support/help/Maple/view.aspx?path=Statistics/Fit) command to fit a polynomial of the form a\*x + b to the data. The ASCII values for the string are found by [convert](http://www.maplesoft.com/support/help/Maple/view.aspx?path=convert/bytes)ing to bytes.
]