Steady State
İKT379 / Lecture 3
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.

OLS objectiveKey formulaFormula sheet →
min⁡b0, b1  SSR=∑i=1n(Yi−b0−b1Xi)2\min_{b_0,\,b_1} \; SSR = \sum_{i=1}^n \big(Y_i - b_0 - b_1X_i\big)^2
SSRSSR
sum of squared residuals
b0,b1b_0, b_1
the candidate intercept and slope being chosen

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 b0b_0 and b1b_1: set each partial derivative to zero.

Worked example · Minimising SSR0/3

Minimise SSR=∑(Yi−b0−b1Xi)2SSR = \sum(Y_i - b_0 - b_1X_i)^2 with respect to b0b_0 and b1b_1.

OLS estimatorsKey formulasFormula sheet →
b1=∑(Xi−Xˉ)(Yi−Yˉ)∑(Xi−Xˉ)2=SxySxxb0=Yˉ−b1Xˉb_1 = \frac{\sum(X_i-\bar X)(Y_i-\bar Y)}{\sum(X_i-\bar X)^2} = \frac{S_{xy}}{S_{xx}} \qquad b_0 = \bar Y - b_1\bar X
Xˉ,Yˉ\bar X, \bar Y
the sample means of X and Y
SxyS_{xy}
sum of products of deviations from the means
SxxS_{xx}
sum of squared deviations of X from its mean

Use it when you need to compute the OLS intercept and slope by hand from raw (X,Y) data — the single most-used formula pair in this course.

A full hand-worked example

Worked example · Computing b0 and b1 by hand0/7

Data: X = 1, 2, 3, 4, 5 and Y = 3, 5, 4, 6, 7. Find the OLS fitted line.

Your turn

Using the fitted line Y^=2.3+0.9X\hat Y = 2.3 + 0.9X from the worked example, find the fitted value Y^\hat Y at X=4X = 4.

Your turn

Continuing the example, the actual value at X = 4 is Y = 6. Find the residual eie_i at this point.

Algebraic properties of the OLS line

Properties of OLSKey propertiesFormula sheet →
1. ∑ei=02. ∑Xiei=03. the fitted line passes through (Xˉ,Yˉ)1.\ \sum e_i = 0 \qquad 2.\ \sum X_ie_i = 0 \qquad 3.\ \text{the fitted line passes through } (\bar X, \bar 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\hat 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.

R-squared: goodness of fit

Decomposition of variationKey formulaFormula sheet →
∑(Yi−Yˉ)2⏟TSS=∑(Y^i−Yˉ)2⏟ESS+∑(Yi−Y^i)2⏟SSR\underbrace{\sum(Y_i-\bar Y)^2}_{TSS} = \underbrace{\sum(\hat Y_i-\bar Y)^2}_{ESS} + \underbrace{\sum(Y_i-\hat Y_i)^2}_{SSR}
TSSTSS
total sum of squares
ESSESS
explained sum of squares
SSRSSR
residual (unexplained) sum of squares

Use it when you need to break down the total variation in Y into the part the regression line explains and the part it leaves unexplained.

R-squaredKey formulaFormula sheet →
R2=ESSTSS=1−SSRTSSR^2 = \frac{ESS}{TSS} = 1 - \frac{SSR}{TSS}
R2R^2
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\bar 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 SxyS_{xy}.

Exam question 3

Continuing the same data: find SxxS_{xx} (using X̄=5).

Exam question 4

Using Sxy=22S_{xy}=22 and Sxx=20S_{xx}=20 from the last two questions, find the OLS slope b1b_1.

Summary and review

Review deck · 10 cards0/10 mastered