How much do earnings rise with each year of schooling? How much does demand fall when price rises? Regression answers questions like these by fitting a line through data, and ordinary least squares (OLS), the standard way to fit it, is the foundation of almost all empirical economics.
We will see what makes a line fit best, compute the OLS slope and intercept, predict with the line, and finish with how the slope relates to correlation and units.
Step 1: The best-fitting line
OLS chooses the intercept b₀ and slope b₁ of ŷ = b₀ + b₁x that make the sum of squared residuals as small as possible. A residual is the vertical distance between a point and the line. Squaring means big misses count a lot, and positive and negative misses don't cancel.
For the five points shown, the OLS line is ŷ = 1.09 + 0.97x, with a sum of squared residuals of about 0.091. A simpler line, ŷ = 1 + x, misses by 0.1, −0.1, 0.2, −0.2 and 0, a sum of squares of 0.10: close, but worse. No other line does better than OLS.
Step 2: The OLS formulas
Minimizing the sum of squared residuals with calculus gives
The slope is the covariance of x and y divided by the variance of x; the intercept makes the line pass through the point of means. For the plotted data, x̄ = 3 and ȳ = 4, the products of deviations add to 9.7 and the squared x-deviations to 10, so b₁ = 0.97 and b₀ = 4 − 0.97 × 3 = 1.09.
Step 3: Predicting with the line
With the two coefficients in hand, the fitted line predicts y for any x:
In the plotted data, x = 6 gives a prediction of 1.09 + 0.97 × 6 = 6.91. With Cov(x, y) = 30, Var(x) = 10, x̄ = 5 and ȳ = 20, the slope is 3 and the intercept 20 − 15 = 5, so the prediction at x = 7 is 26.
Step 4: Slope, correlation and spread
Since r = sxy ÷ (sxsy), the slope can also be written
Example: r = 0.5, sy = 12 and sx = 4 give b₁ = 1.5. The slope has the sign of the correlation, but a strong correlation doesn't imply a steep slope: steepness depends on the units and spreads of y and x. Measuring x in thousands of dollars instead of dollars divides every x by 1,000 and so multiplies the slope by 1,000.