All labs

Regression Is a Projection

The hat matrix, orthogonal residuals, leverage, and why the least-squares line is not the principal axis.

Ch 3 3.5
Explorer
Mathematical Core
16 mindifficulty 3/5

Controls

1.200
2
2

Larger noise widens the gap between the OLS line and PC1.

Add one high-leverage point

A single observation far out in x.

16
4
Show vertical residuals

The distances OLS minimizes.

Overlay PC1

The line minimizing perpendicular distance.

60
Random seed

Every result on this page is a deterministic function of the seed and the controls.

The fit as a projection

ŷ = Hy is the orthogonal projection of y onto the column space of X.

0510150246810xy
OLS fitPC1 (total least squares)vertical residualshigh leverage

Residuals against fitted

Structureless if the model is right.

-6-4-2024624681012fitted ŷresidual e

Leverage and influence

hᵢᵢ against Cook's distance.

00.020.040.060.080.100.1200.020.040.060.080.10leverage hᵢᵢCook's D
β̂₀
2.175
true 2
β̂₁
1.120
true 1.20
PC1 slope
1.417
perpendicular-distance line
0.698
r = 0.835
σ̂
2.186
true 2
tr(H)
2
equals p = 2 exactly
Σeᵢ
-1.55e-13
orthogonal to the intercept column
Σxᵢeᵢ
-3.77e-13
orthogonal to the x column
Why both dot products are zero

The normal equations are exactly the statement Xᵗe = 0. Every column of X is orthogonal to the residual vector, which is why the residuals sum to zero whenever an intercept is included — that is a consequence of the geometry, not an assumption.