Linear Regression
Create a set of points like this (all on one line):
p =
[[0, 3.8414709848078967], [0.6931471805599453, 6.6818861490654635], [1.0986122886681098, 7.5355691627323065], [1.3862943611198906, 7.788374949171635], [1.6094379124341003, 8.478827375073264], [1.791759469228055, 9.887622378713294], [1.9459101490553132, 11.440627194940042], [2.0794415416798357, 12.307124413342725]]
Where:
p[i][0] is an x value
and p[i][1] is the corresponding y value
Find the least square curve that best matches these points using linear regression.
I need four outputs:
n = number of points
m = slope
b = y-intercept
r = coefficient of regression.
Formulas that might help:
n = p.length
m = (n * Σxy - Σx * Σy) / (n * Σxx - Σx * Σx)
b = (Σy - m * Σx) / n
r = (n * Σxy - Σx * Σy) / sqrt((n * Σxx - Σx * Σx) * (n * Σyy - Σy * Σy))
PLEASE WRITE THE CODE IN NOTEPAD++ OR TEXTEDIT. WRITE IN JAVASCRIPT. MAKE SURE TO COPY AND PASTE CODE.