Phase 11 - Lesson 11.2

Linear Regression: OLS, Geometry, Gauss-Markov, and Inference vs Prediction

The normal equations, least squares as an orthogonal projection, when OLS is best, and the crucial split between explaining and forecasting.

⏱ 55 min● Intermediate🔗 Prereqs: 11.1, 4.x linear algebra
↖ Phase 11 hub
Builds on: 11.1 gave estimators, MSE, and the bias-variance split.
Leads to: Regularization (11.4) modifies these normal equations; CV (11.3) evaluates prediction.

Learning Objectives

Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.

Key Vocabulary

Design matrix
The \(n\times p\) matrix \(X\) of predictors (often with a leading column of ones for the intercept).
Normal equations
The linear system \(X^\top X\beta=X^\top y\) whose solution is the OLS estimate.
Hat matrix
The projection \(H=X(X^\top X)^{-1}X^\top\) mapping \(y\) to fitted values \(\hat y=Hy\).
Residual
The gap \(e=y-\hat y=(I-H)y\), orthogonal to every column of \(X\).
BLUE
Best Linear Unbiased Estimator: minimum variance among all linear unbiased estimators.
Homoscedasticity
Constant error variance \(\Var(\varepsilon_i)=\sigma^2\) across observations.
Standard error
The estimated standard deviation of a coefficient estimate, the basis of \(t\)-tests and intervals.

Intuition & Motivation

Intuition
Least squares answers a geometry question. You have a target vector \(y\) in \(\R^n\) and a subspace - all vectors you can build as linear combinations of your predictors, the column space of \(X\). The best linear fit is the shadow of \(y\) on that subspace: the point in the span closest to \(y\). That closest point is the orthogonal projection, and ‘orthogonal’ is the whole content of the normal equations - the residual must be perpendicular to every predictor.

Two very different jobs share this machinery. Inference asks what the coefficients are and how sure we are - we need unbiasedness, standard errors, and honest assumptions. Prediction asks only whether \(\hat y\) is accurate on new data - biased coefficients are fine if they forecast better. Confusing the two is one of the most common and most expensive errors in applied quant work.

The model and the least-squares problem

Assume \(y=X\beta+\varepsilon\) with \(X\in\R^{n\times p}\) of full column rank and \(\E[\varepsilon]=0\). OLS chooses \(\beta\) to minimize the residual sum of squares:

\[\hat\beta=\argmin_\beta \|y-X\beta\|_2^2 = \argmin_\beta \sum_{i=1}^n\big(y_i-x_i^\top\beta\big)^2.\] (11.4)
Worked Example - Deriving the normal equations
1
Expand the objective: \(\|y-X\beta\|^2=y^\top y-2\beta^\top X^\top y+\beta^\top X^\top X\beta.\)
2
Gradient in \(\beta\): \(\nabla=-2X^\top y+2X^\top X\beta.\) Set to zero.
3
Normal equations: \(X^\top X\hat\beta=X^\top y.\) Full rank makes \(X^\top X\) invertible.
4
Solve: \(\hat\beta=(X^\top X)^{-1}X^\top y.\) The Hessian \(2X^\top X\succeq0\) confirms a minimum.

Geometry: least squares is a projection

Fitted values are \(\hat y=X\hat\beta=X(X^\top X)^{-1}X^\top y=Hy\). The hat matrix \(H\) is the orthogonal projector onto \(\text{col}(X)\): it is symmetric, idempotent (\(H^2=H\)), and \(Hx=x\) for any column of \(X\). The residual \(e=(I-H)y\) lives in the orthogonal complement, so

\[X^\top e = X^\top(I-H)y = 0 \quad\Longleftrightarrow\quad \text{residuals are orthogonal to every predictor.}\] (11.5)
Key Idea
The Pythagorean split \(\|y\|^2=\|\hat y\|^2+\|e\|^2\) is exactly the ANOVA decomposition (total = explained + residual sum of squares). \(R^2=\|\hat y-\bar y\mathbf1\|^2/\|y-\bar y\mathbf1\|^2\) is the cosine-squared of an angle.

Gauss-Markov: when OLS is best

Theorem - Gauss-Markov
If \(\E[\varepsilon]=0\), \(\Var(\varepsilon)=\sigma^2 I\) (uncorrelated, homoscedastic errors), and \(X\) is fixed of full rank, then among all linear unbiased estimators of \(\beta\), OLS has the smallest variance. OLS is BLUE.

Note what is not assumed: normality is not needed for BLUE (only for exact \(t\) and \(F\) distributions in finite samples). And ‘best linear unbiased’ leaves the door open - a biased nonlinear estimator (ridge, lasso) can beat OLS in MSE, which is precisely 11.4.

Inference: coefficients and their uncertainty

Under the Gauss-Markov assumptions plus Gaussian errors, \(\hat\beta\sim\Normal\big(\beta,\ \sigma^2(X^\top X)^{-1}\big)\). Estimating \(\sigma^2\) by \(\hat\sigma^2=\|e\|^2/(n-p)\) gives standard errors \(\mathrm{SE}(\hat\beta_j)=\hat\sigma\sqrt{[(X^\top X)^{-1}]_{jj}}\) and the \(t\)-statistic \(t_j=\hat\beta_j/\mathrm{SE}(\hat\beta_j)\). This is the machinery of ‘is this factor significant?’

Prediction: a different target

For forecasting we do not care whether \(\hat\beta\) is unbiased; we care about \(\E[(y_0-x_0^\top\hat\beta)^2]\) at a new \(x_0\). This equals \(\sigma^2\) (irreducible) plus a model-variance term \(\sigma^2 x_0^\top(X^\top X)^{-1}x_0\) plus any bias-squared. Adding a slightly biased penalty can shrink the variance term and lower total prediction error.

QuestionInferencePrediction
GoalInterpret \(\beta\), test hypothesesAccurate \(\hat y\) on unseen \(x_0\)
Needs unbiasedness?YesNo
Key outputSEs, \(t\)-stats, CIsOut-of-sample error, CV score
DangerMulticollinearity inflates SEsOverfitting, look-ahead bias
FavorsOLS / GLSRegularized / shrunk models

Interactive: OLS from scratch

Common Mistakes to Avoid
  • Inverting \(X^\top X\) explicitly when predictors are collinear - it is near-singular; solve the system or use a QR/SVD instead.
  • Reading a large coefficient as ‘important’ without its standard error; significance is \(\hat\beta_j/\mathrm{SE}\), not \(\hat\beta_j\).
  • Reporting in-sample \(R^2\) as evidence of predictive skill; it never decreases as you add regressors.
  • Assuming Gauss-Markov needs normality - it does not for BLUE; normality is only for exact finite-sample \(t\)/\(F\) inference.
  • Interpreting a regression coefficient causally when predictors are correlated (omitted-variable bias).
Quant Practitioner Tips
  • Decide up front: are you doing inference or prediction? The right model, diagnostics, and validation differ completely.
  • For prediction, judge models by cross-validated error (11.3), never by in-sample fit.
  • Financial predictors are often nearly collinear (many are lagged versions of each other); watch the condition number of \(X^\top X\).
  • Heteroscedastic or autocorrelated errors (the norm in finance) break the naive SE formula - use robust (White/Newey-West) standard errors.

Knowledge Check

Q1 Medium
The normal equations \(X^\top X\hat\beta=X^\top y\) express the condition that:
The fitted values equal the data
The residual vector is orthogonal to the column space of \(X\)
The coefficients are all positive
The design matrix is orthonormal
Q2 Medium
The Gauss-Markov theorem guarantees OLS is best among:
All estimators
All unbiased estimators
All linear unbiased estimators
All linear estimators
Q3 Medium
You want the most accurate forecast of tomorrow's return, not to interpret coefficients. Which matters most?
Unbiasedness of each coefficient
Statistical significance of each factor
Cross-validated out-of-sample error
A high in-sample \(R^2\)

Practical Exercise

With \(\hat\beta=(X^\top X)^{-1}X^\top y\) and \(y=X\beta+\varepsilon\), \(\E[\varepsilon]=0\), \(\Var(\varepsilon)=\sigma^2 I\): (a) show OLS is unbiased; (b) derive \(\Var(\hat\beta)\); (c) explain why near-collinear predictors make individual coefficients unreliable but need not hurt prediction.

▶ Show full solution

(a) \(\E[\hat\beta]=(X^\top X)^{-1}X^\top\E[y]=(X^\top X)^{-1}X^\top X\beta=\beta\). Unbiased.

(b) \(\hat\beta-\beta=(X^\top X)^{-1}X^\top\varepsilon\), so \(\Var(\hat\beta)=(X^\top X)^{-1}X^\top(\sigma^2 I)X(X^\top X)^{-1}=\sigma^2(X^\top X)^{-1}\).

(c) Collinearity makes \(X^\top X\) nearly singular, so \((X^\top X)^{-1}\) has huge entries and coefficient variances blow up - individual \(\hat\beta_j\) are unstable and can swap signs across samples. But the fitted values \(\hat y=Hy\) depend only on the column space, which is well-defined even when the basis is ill-conditioned; prediction can remain accurate. This is exactly why we shrink coefficients (ridge) when we only need \(\hat y\).

After the reveal, answer for yourself: Unstable coefficients with stable predictions is the signature of collinearity - and the motivation for the next two lessons.

Lesson Summary

OLS solves the normal equations \(X^\top X\hat\beta=X^\top y\), equivalently projecting \(y\) orthogonally onto the column space via the hat matrix. Under uncorrelated homoscedastic errors it is BLUE (Gauss-Markov). Inference cares about unbiased coefficients and their standard errors; prediction cares only about out-of-sample accuracy and often prefers deliberately biased, lower-variance estimators.

Formula Sheet Additions

OLS estimator
\[\hat\beta=(X^\top X)^{-1}X^\top y\]
Solution of the normal equations; solve, don't invert, when collinear.
Coefficient covariance
\[\Var(\hat\beta)=\sigma^2(X^\top X)^{-1}\]
Basis of standard errors; explodes under collinearity.
Error Log Checklist
  • Did I check the condition number of \(X^\top X\) before trusting individual coefficients?
  • Am I doing inference or prediction, and did I use the matching validation?
  • Did I use robust SEs if errors look heteroscedastic or autocorrelated?
  • Did I avoid reporting in-sample \(R^2\) as predictive evidence?

Retrieval Practice

Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.

▶ Show retrieval prompts & answers
Q: Write the OLS estimator and the geometric meaning of the fit.
A: \(\hat\beta=(X^\top X)^{-1}X^\top y\); fitted values \(\hat y=Hy\) are the orthogonal projection of \(y\) onto \(\text{col}(X)\).
Q: What does Gauss-Markov claim and what does it not require?
A: OLS is minimum-variance among linear unbiased estimators (BLUE), assuming zero-mean uncorrelated homoscedastic errors; it does not require normality.
Q: Give a case where individual coefficients are unreliable but predictions are fine.
A: Near-collinear predictors: \((X^\top X)^{-1}\) blows up so coefficient variances explode, yet \(\hat y\) depends only on the column space and stays stable.

Flashcards

Click to flip. These feed the site-wide spaced-repetition queue.

Normal equations
\(X^\top X\hat\beta=X^\top y\); residuals orthogonal to all predictors.
Hat matrix
\(H=X(X^\top X)^{-1}X^\top\), symmetric idempotent projector onto \(\text{col}(X)\).
Inference vs prediction
Inference: unbiased \(\beta\) + SEs. Prediction: out-of-sample accuracy, biased models allowed.

Completion Checklist

Confidence / mastery rating
Personal notes

Source References

This lesson synthesizes and paraphrases concepts from the sources below. No copyrighted text, problem sets, or solutions are reproduced. Return to the originals for full depth.