Given paired data (x1,y1),(x2,y2),…,(xn,yn), the least-squares regression line is the line y^=b0+b1x that minimizes the sum of the squared vertical distances from the data points to the line.
The slope b1 and intercept b0 are given by
b1=i=1∑n(xi−xˉ)2i=1∑n(xi−xˉ)(yi−yˉ),b0=yˉ−b1xˉ,
where xˉ and yˉ are the sample means of the x- and y-values.
For instance, consider the three points (1,2),(2,2),(3,5). We have xˉ=2 and yˉ=3, so
b1b0=(−1)2+02+12(−1)(−1)+(0)(−1)+(1)(2)=23=1.5,=3−1.5⋅2=0.
The least-squares regression line is y^=1.5x.