chickadee » statistics » linear-regression

linear-regression line-defnprocedure

Given a line definition as a list of point pairs, first prints to the terminal and then returns 5 values for the best fitting line through the points:

  • the y-intercept
  • the slope
  • the correlation coefficient, r
  • the square of the correlation coefficient, r^2
  • the significance of the difference of the slope from zero, p

(This is also called the Pearson correlation; used when relation expected to be linear. Also see spearman-rank-correlation.)

> (linear-regression '((1.0 0.1) (2.0 0.3) (3.0 0.8)))
Intercept = -0.3, slope = 0.35, r = 0.970725343394151, R^2 = 0.942307692307692, p = 0.154420958311267
-0.3
0.35
0.970725343394151
0.942307692307692
0.154420958311267
; 5 values