How squared residuals turn a cloud of observations into an estimated line or linear model.
By Theory Commons Editors4 min readPublished Aug 22, 2026
No straight line will usually pass through every noisy observation. Least squares replaces the demand for a perfect match with a precise compromise: choose the parameters whose predictions have the smallest total squared discrepancy.
The objective
For the line y^i=β0+β1xi, define
S(β0,β1)=i=1∑n[yi−(β0+β1xi)]2.
The least-squares estimates β^0 and β^1 minimize S.
The slope is large when x and y vary together relative to the variation in x. The intercept places the fitted line through (xˉ,yˉ).
The matrix view
Many linear models can be written as
y=Xβ+ε.
Least squares minimizes ∥y−Xβ∥2. Its solution satisfies the normal equations
XTXβ^=XTy.
Geometrically, the fitted vector Xβ^ is the projection of y onto the space of predictions the model can produce.
Assumptions and uncertainty
Least squares can calculate a line without a probability model. Statistical intervals and tests additionally rely on assumptions such as independent errors, constant error variance, and an appropriate mean structure. Normal errors are commonly assumed for exact small-sample inference.
Derive the simple-regression normal equations
Differentiate S(β0,β1) with respect to both coefficients and set the derivatives to zero:
∑(yi−β0−β1xi)=0,∑xi(yi−β0−β1xi)=0.
The first equation says residuals sum to zero; the second says residuals are orthogonal to x. Solving gives the familiar formulas for slope and intercept.
Check your understanding
Why does rescaling x from meters to centimeters change the numerical slope but not fitted values?
Show the reasoning
One meter equals 100 centimeters, so a one-centimeter change is 1/100 as large. The slope per centimeter is the slope per meter divided by 100; multiplying by the rescaled x restores the same predictions.