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 b1 and b2 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

How the exam asks it: four core exam templates

Midterm exams on OLS estimation test four standard formats: hand-calculating b1b_1 and b2b_2 from small datasets, computing R2R^2 via ANOVA decompositions, estimating parameters from given deviation sums, and interpreting regression output tables.

Exam template 1: Full hand calculation of the OLS line from raw data

Question: Five students report study hours XX and exam scores YY: X=(1,2,3,4,5)X = (1, 2, 3, 4, 5) and Y=(3,5,4,6,7)Y = (3, 5, 4, 6, 7). a) Calculate the sample means Xˉ\bar{X} and Yˉ\bar{Y}.
b) Calculate Sxy=∑xiyiS_{xy} = \sum x_i y_i and Sxx=∑xi2S_{xx} = \sum x_i^2, and solve for the slope b2b_2.
c) Calculate the intercept b1b_1, write the estimated regression line Y^i\hat{Y}_i, and interpret the slope.

Worked example · Full step-by-step solution for Template 1 (Hand OLS estimation)0/9

Data: X=(1,2,3,4,5)X = (1, 2, 3, 4, 5) and Y=(3,5,4,6,7)Y = (3, 5, 4, 6, 7) (n=5n = 5).

Exam template 2: Computing R-squared from residuals and total variation

Question: For the five students in Template 1, the residuals are e=(−0.2,0.9,−1.0,0.1,0.2)e = (-0.2, 0.9, -1.0, 0.1, 0.2) and Yˉ=5\bar{Y} = 5. a) Compute the residual sum of squares SSR=∑ei2SSR = \sum e_i^2.
b) Compute the total sum of squares TSS=∑(Yi−Yˉ)2TSS = \sum (Y_i - \bar{Y})^2.
c) Compute R2R^2 and interpret its value.

Worked example · Full step-by-step solution for Template 2 (Goodness of fit R-squared)0/9

Residuals e=(−0.2,0.9,−1.0,0.1,0.2)e = (-0.2, 0.9, -1.0, 0.1, 0.2), actual Y=(3,5,4,6,7)Y = (3, 5, 4, 6, 7), Yˉ=5\bar{Y} = 5.

Exam template 3: Estimating from summary sums

Question: An exam problem provides summary statistics for an empirical dataset: ∑xi2=92.50\sum x_i^2 = 92.50, ∑xiyi=590.20\sum x_i y_i = 590.20, Xˉ=10.35\bar{X} = 10.35, and Yˉ=169.4\bar{Y} = 169.4. a) Calculate the OLS slope coefficient b2b_2.
b) Calculate the OLS intercept b1b_1.
c) State the estimated regression equation and predict YY when X=15X = 15.

Worked example · Full step-by-step solution for Template 3 (Estimating from summary sums)0/9

∑xi2=92.50\sum x_i^2 = 92.50, ∑xiyi=590.20\sum x_i y_i = 590.20, Xˉ=10.35\bar{X} = 10.35, Yˉ=169.4\bar{Y} = 169.4.

Exam template 4: Reading and interpreting an EViews output table

Question: An EViews regression table reports: Constant C=24.45455C = 24.45455 (SE=6.413817SE = 6.413817), regressor X=0.509091X = 0.509091 (SE=0.035743SE = 0.035743), SSR=337.2727SSR = 337.2727, R2=0.962062R^2 = 0.962062, n=10n = 10. a) Compute the t-statistics for the constant and slope.
b) Calculate the estimated error variance σ^2\hat{\sigma}^2 and standard error of regression σ^\hat{\sigma}.
c) Interpret the coefficient of determination R2R^2.

Worked example · Full step-by-step solution for Template 4 (Reading regression output)0/9

Constant b1=24.45455b_1 = 24.45455 (SE=6.413817SE = 6.413817); slope b2=0.509091b_2 = 0.509091 (SE=0.035743SE = 0.035743); SSR=337.2727SSR = 337.2727; n=10n = 10.

Cheat-sheet & the 4-step method

The least-squares principle

On the slides: OLS is a regression estimation technique that calculates the bb‘s so as to minimise the sum of the squared residuals, where ei=Yi−Y^ie_i = Y_i - \hat Y_i is the gap between the actual YY and the YY estimated by the regression.

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⁡b1, b2  SSR=∑i=1n(Yi−b1−b2Xi)2\min_{b_1,\,b_2} \; SSR = \sum_{i=1}^n \big(Y_i - b_1 - b_2X_i\big)^2
SSRSSR
sum of squared residuals
b1,b2b_1, b_2
the candidate intercept and slope being chosen

Use it when you need to explain what OLS is actually optimizing, before deriving the formulas for b1 and b2.

Diagram · Ordinary least squaresŶ = 24.45 + 0.509X, n = 10
801201602002406090120150weekly income X (dollars)weekly consumption Y (dollars)SRFe₂ = −10.36e₉ = +8.36
OLS line (SRF)e > 0e < 0

Sample 1 (Table 2.4) with the OLS line Ŷ = 24.45 + 0.509X. Each residual eᵢ = Yᵢ − Ŷᵢ is the vertical distance from the point to the line: green above the line (e > 0), red below (e < 0). Positive and negative residuals cancel: Σeᵢ = 0.

Deriving the normal equations

This is exactly the unconstrained optimization technique from the Mathematics I course, applied to a function of two variables b1b_1 and b2b_2: set each partial derivative to zero.

Worked example · Minimising SSR0/6

Minimise SSR=∑(Yi−b1−b2Xi)2SSR = \sum(Y_i - b_1 - b_2X_i)^2 with respect to b1b_1 and b2b_2.

OLS estimatorsKey formulasFormula sheet →
b2=∑(Xi−Xˉ)(Yi−Yˉ)∑(Xi−Xˉ)2=SxySxxb1=Yˉ−b2Xˉb_2 = \frac{\sum(X_i-\bar X)(Y_i-\bar Y)}{\sum(X_i-\bar X)^2} = \frac{S_{xy}}{S_{xx}} \qquad b_1 = \bar Y - b_2\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.

The slides write the same slope in two equivalent ways, with small letters for deviations from the mean (xi=Xi−Xˉx_i = X_i - \bar X, yi=Yi−Yˉy_i = Y_i - \bar Y):

OLS slope, two forms (slides)Key formulaFormula sheet →
b2=∑xiyi∑xi2=∑XiYi−nXˉYˉ∑Xi2−nXˉ2b_2 = \frac{\sum x_i y_i}{\sum x_i^2} = \frac{\sum X_iY_i - n\bar X\bar Y}{\sum X_i^2 - n\bar X^2}
xi,yix_i, y_i
deviations from the means
∑XiYi,∑Xi2\sum X_iY_i, \sum X_i^2
sums of the raw values
nn
sample size

Use it when you are given raw sums (the second form) or a deviation table (the first form); both give the same number.

A full hand-worked example

Worked example · Computing b1 and b2 by hand0/6

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.

The lecture’s numerical example

Worked example · The worked example from the slides0/6

The lecture slides report, for a dataset, ∑xi2=92.50\sum x_i^2 = 92.50 and ∑xiyi=590.20\sum x_i y_i = 590.20, with Xˉ=10.35\bar X = 10.35 and Yˉ=169.4\bar Y = 169.4. The raw observations are not shown in the notes — only these sums are available.

Algebraic properties of the OLS line

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/6

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².

Reading EViews output

The lecture tests Keynes’s consumption function on Gujarati’s Table 2.4 data: weekly income X=80,100,…,260X = 80, 100, \ldots, 260 and weekly consumption Y=70,65,90,95,110,115,120,140,155,150Y = 70, 65, 90, 95, 110, 115, 120, 140, 155, 150, with n=10n = 10. Keynes predicted that consumption rises with income but by less — a marginal propensity to consume between 0 and 1. EViews estimates the line by OLS and prints:

VariableCoefficientStd. Errort-StatisticProb.
C24.454556.4138173.8127910.0051
X0.5090910.03574314.243170.0000
StatisticValueStatisticValue
R-squared0.962062Mean dependent var111.0000
Adjusted R-squared0.957319Sum squared resid337.2727
S.E. of regression6.493003F-statistic202.8679
Interactive · EViews output, line by lineGujarati Table 2.4 · n = 10
507510012515017520080100120140160180200220240260weekly family income X (dollars)weekly consumption Y (dollars)Ŷ = 126.27(X̄, Ȳ)
C (intercept b₁)24.45455
X (slope b₂)0.509091
Std. error of b₂0.035743
t-statistic of b₂14.24317
R-squared0.962062
Adjusted R-squared0.957319
S.E. of regression6.4930
Sum squared resid337.2727
Mean dependent var111.00
F-statistic202.868

b₂ = Σxy / Σx² = 16,800 / 33,000 = 0.5091: each extra 1 dollar of weekly income raises mean weekly consumption by about 51 cents (within incomes 80–260). It is the MPC, between 0 and 1 as Keynes said.

Interpreting the slope. b2=0.5091b_2 = 0.5091: within the sample range of X between 80 and 260 dollars per week, a one-dollar increase in weekly income is associated with an estimated increase of about 51 cents in average weekly consumption expenditure.

Interpreting the intercept. b1=24.4545b_1 = 24.4545: mechanically, the average weekly consumption when weekly income is zero. Taken literally this is not always meaningful, but it can be argued that a family with no income (unemployment, layoff) maintains some minimum consumption financed by borrowing or dissaving.

Interpreting R². R2=0.9621R^2 = 0.9621 means about 96 percent of the variation in weekly consumption expenditure is explained by income. Since R² can be at most 1, the sample regression line fits the data very well.

Checking the printed numbers.

Akaike info criterion, Schwarz criterion and Durbin-Watson appear in fuller output; what they mean comes later in the course.

Your turn

Using the estimated line C^=24.45455+0.509091X\hat C = 24.45455 + 0.509091X from the EViews output, predict weekly consumption when income is X=200X = 200.

Your turn

The output reports the intercept 24.45455 with standard error 6.413817. Compute its t-statistic, rounded to two decimals.

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 b2b_2.

Exam question 5

An EViews regression of weekly consumption on weekly income gives C^=24.45455+0.509091X\hat C = 24.45455 + 0.509091X. Predict consumption for a family with weekly income X=150X = 150.

Exam question 6

Same data as questions 1–4 (X=2,4,6,8X = 2, 4, 6, 8; Y=5,7,8,12Y = 5, 7, 8, 12; b2=1.1b_2 = 1.1). Find the intercept b1b_1.

Exam question 7

For the line Y^=2.5+1.1X\hat Y = 2.5 + 1.1X on the same data, find R2R^2 (three decimals).

Exam question 8

Raw sums for n=10n = 10: ∑XiYi=205,500\sum X_iY_i = 205{,}500, ∑Xi2=322,000\sum X_i^2 = 322{,}000, Xˉ=170\bar X = 170, Yˉ=111\bar Y = 111. Find b2b_2 with the slides' second formula (four decimals).

Exam question 9

Which of these is NOT a property of the OLS regression line?

Summary and review

Step-by-step examples

Work through the ladder one level at a time: at every step, try to say what comes next before you reveal it. Easy builds the basic moves, medium combines the formulas, and the exam level has the shape of a real exam question.

Easy

Worked example · Easy 1 · Reading a fitted line0/6

A regression predicts exam score from study hours: Y^=30+0.5X\hat Y = 30 + 0.5X, where XX is hours studied and Y^\hat Y is the predicted score. What score does the line predict for 10 hours of study?

Worked example · Easy 2 · Finding a residual0/6

Same line, Y^=30+0.5X\hat Y = 30 + 0.5X. A student studies 10 hours and scores 34. What is her residual?

Your turn

Using Y^=30+0.5X\hat Y = 30 + 0.5X (score predicted from study hours), find the predicted score for X=8X = 8.

Medium

Worked example · Medium 1 · Computing the OLS line by hand0/6

Five students report study hours X=1,2,3,4,5X = 1, 2, 3, 4, 5 and exam scores Y=4,6,7,8,10Y = 4, 6, 7, 8, 10. Estimate the line Y^=b1+b2X\hat Y = b_1 + b_2X (here b1b_1 is the intercept and b2b_2 the slope, the slides' notation).

Worked graph · the five studentsstep 1/5: Plot the data
12345study hours Xexam score Y
XY
14
26
37
48
510

Each dot is one observation: a pair (X, Y). There are 5 of them. Before any formula, look: do the dots rise from left to right? Then the slope will be positive.

Worked example · Medium 2 · R-squared for the same data0/6

Keep the five students: line Y^=2.8+1.4X\hat Y = 2.8 + 1.4X, actual scores Y=4,6,7,8,10Y = 4, 6, 7, 8, 10, mean Yˉ=7\bar Y = 7. Find R2R^2, where R2=1−SSR/TSSR^2 = 1 - SSR/TSS.

Worked example · Medium 3 · Standard error and t from an output table0/6

The EViews table on this page reports: C = 24.45455 with Std. Error 6.413817; X = 0.509091 with Std. Error 0.035743; Sum squared resid 337.2727; n = 10. Find the two t-statistics and the estimated error variance σ^2\hat\sigma^2.

Your turn

A table reports a coefficient of 8.4 with standard error 2.1. Find its t-statistic.

Exam level

Worked example · Exam 1 · Full hand calculation: price and demand0/6

A cafe records the price PP in TL and cups sold QQ: P=2,3,4,5,6P = 2, 3, 4, 5, 6 and Q=25,19,16,11,9Q = 25, 19, 16, 11, 9. Estimate Q^=b1+b2P\hat Q = b_1 + b_2P by OLS, interpret the slope, and predict sales at a price of 5 TL.

Worked graph · price and demandstep 1/6: Plot the data
23456price P (TL)cups sold Q
XY
225
319
416
511
69

Each dot is one observation: a pair (X, Y). There are 5 of them. Before any formula, look: do the dots rise from left to right? Then the slope will be positive.

Worked example · Exam 2 · Reading the full EViews output0/6

From the EViews consumption table on this page: R² = 0.962062, S.E. of regression 6.493003, Sum squared resid 337.2727, slope t-statistic 14.24317, F-statistic 202.8679. Write up the result as an exam answer.

Worked example · Exam 3 · Written answer on R-squared0/6

A regression of exam score on study hours gives R2=0.98R^2 = 0.98. Write the exam answer: what does this number mean, and what does it not prove?

Check your understanding

In the coffee example the fitted line is Q^=32−4P\hat Q = 32 - 4P. Which statement is the best interpretation of the intercept 32?

Review deck · 12 cards0/12 mastered