MathorynMathematical Formula Database

Statistics & Probability

Least-Squares Regression Line

The least-squares line is the straight line that minimises the sum of squared vertical distances to the data points. It is used to describe linear trends, to make predictions and as the simplest regression model.

y^=a+bx,b=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2,a=yˉ−bxˉ\hat y=a+bx,\qquad b=\frac{\sum(x_i-\bar x)(y_i-\bar y)}{\sum(x_i-\bar x)^2},\quad a=\bar y-b\bar x
LaTeX\hat y=a+bx,\qquad b=\frac{\sum(x_i-\bar x)(y_i-\bar y)}{\sum(x_i-\bar x)^2},\quad a=\bar y-b\bar x

Variables

y^\hat y
predicted value
bb
slope
aa
intercept
xˉ, yˉ\bar x,\ \bar y
means of x and y

Example

Fit a line to (1,2),(2,4),(3,5)(1,2),(2,4),(3,5).

  1. ∑(x−xˉ)(y−yˉ)=3\sum(x-\bar x)(y-\bar y)=3, ∑(x−xˉ)2=2\sum(x-\bar x)^2=2, so b=1.5b=1.5.
  2. a=113−1.5⋅2≈0.6667a=\frac{11}{3}-1.5\cdot2\approx0.6667.

Answer: y^≈0.6667+1.5x\hat y\approx0.6667+1.5x.

Related formulas