The best fit line (using least squares regression) for the n points (X1,Y1), (X2,Y2),...(Xn,Yn) has the form: y=mx+b
Where
Slope:
m=n(n∑i=1xiyi)−(n∑i=1xi)(n∑i=1yi)n(n∑i=1xi2)−(n∑i=1xi)2
Y-Intercept:
b=(n∑i=1yi)−m(n∑i=1xi)n
xi is the time of the ith data point
yiis the value of the ith data point
The correlation coefficient quantifies the strength of the linear relationship and is calculated by: r=SSXY√SSX∗SSY
Where SSX=n∑i=1xi2n−(n∑i=1xi)2n2
SSY=n∑i=1yi2n−(n∑i=1yi)2n2
SSXY=n∑i=1xiyin−(n∑i=1xi)(n∑i=1yi)n2