Lecture 3 · Week 3 · Gujarati ch. 3 · about 50 min
Estimation: OLS
The least-squares principle derived from scratch with ordinary calculus, the resulting formulas for the intercept and slope, a full hand-worked numerical example, and R-squared as a measure of fit.
By the end you can
State the least-squares criterion and derive the normal equations by minimising SSR
Compute OLS estimates b0 and b1 by hand from a small dataset
List the key algebraic properties of the OLS fitted line
Compute and interpret R-squared as a measure of goodness of fit
The least-squares principle
Infinitely many lines could be drawn through a scatter of points. Ordinary least squares (OLS) picks the one specific line that makes the residuals, as a whole, as small as possible — precisely by minimising the sum of squared residuals.
Use it when you need to explain what OLS is actually optimizing, before deriving the formulas for b0 and b1.
Deriving the normal equations
This is exactly the unconstrained optimization technique from the Mathematics I course, applied to a function of two variables b0 and b1: set each partial derivative to zero.
Worked example · Minimising SSR0/3
Minimise SSR=∑(Yi−b0−b1Xi)2 with respect to b0 and b1.
1.∑ei=02.∑Xiei=03.the fitted line passes through (Xˉ,Yˉ)
Use it when you need to check whether a claimed fitted line could actually be the OLS line, or explain a stated algebraic fact about residuals.
These are not assumptions — they are automatic mathematical consequences of the two normal equations derived above (the first normal equation directly implies property 1; combined with property 1, the second implies property 2).
Check your understanding
For the worked example, the residuals were −0.2, 0.9, −1.0, 0.1, 0.2 at X = 1 through 5. What should their sum equal, and does it?
Try it: drag the data, watch OLS refit
Interactive · OLS fitted linedrag any point
data pointsOLS fitted lineresiduals
Drag any black point. OLS chooses the line minimising the sum of squared residuals (red dashed segments).
Intercept b0
2.268
Slope b1
0.857
SSR (Σ residuals²)
3.018
R²
0.911
Y^=2.27+0.86X. Drag a point far off the trend and watch SSR rise and R² fall: OLS still fits the BEST line through the new configuration, but that best line explains the data less well.
the proportion of the total variation in Y explained by the regression, 0 \leq R^2 \leq 1
Use it when a question asks how well the fitted line explains the data — the standard, single-number goodness-of-fit measure for a two-variable regression.
Worked example · Computing R-squared for the worked example0/4
Using the same data and residuals (−0.2, 0.9, −1.0, 0.1, 0.2) with Yˉ=5, find R².
Your turn
A different regression has SSR = 45 and TSS = 200. Find R².
Exam practice
Exam question 1
X = 2, 4, 6, 8 and Y = 5, 7, 8, 12. Find X̄ and Ȳ, then report X̄.
Exam question 2
Continuing: X = 2,4,6,8, Y = 5,7,8,12, with X̄=5 and Ȳ=(5+7+8+12)/4=8. Find Sxy.
Exam question 3
Continuing the same data: find Sxx (using X̄=5).
Exam question 4
Using Sxy=22 and Sxx=20 from the last two questions, find the OLS slope b1.
Summary and review
OLS minimises SSR=∑(Yi−b0−b1Xi)2.
Setting ∂SSR/∂b0=0 and ∂SSR/∂b1=0 gives the two normal equations, solved to get b1=Sxy/Sxx and b0=Yˉ−b1Xˉ.
OLS residuals always sum to zero, and the fitted line always passes through (Xˉ,Yˉ) — automatic consequences of the normal equations.
TSS=ESS+SSR; R2=ESS/TSS=1−SSR/TSS, the proportion of variation in Y explained by X.
A high R² does not by itself validate a model’s specification or causal story.