Linear Model Theory: Gauss-Markov, the Hat Matrix, and BLUE
Anchor (Master): Seber & Lee 2003 Linear Regression Analysis 2e (Wiley) Ch. 2-4 (estimation, the distribution of quadratic forms, hypothesis testing, generalized least squares); Rao 1973 Linear Statistical Inference and Its Applications 2e (Wiley) Ch. 4 (the general Gauss-Markov model and the BLUE); Hastie, Tibshirani & Friedman 2009 The Elements of Statistical Learning 2e (Springer) §3.2-3.4
Intuition Beginner
You have a stack of measurements, and you suspect that one number (the response) is built up out of a few other numbers (the predictors) plus some random noise. The linear model is the simplest honest way to write that down: the response is a weighted sum of the predictors, and whatever the weighted sum misses is chalked up to error. The whole game is to recover the weights from noisy data and to say how much you should trust them.
The recipe for the weights is least squares: pick the weights that make the total squared miss as small as possible. Squaring the misses means that being off by 4 on one point costs the same as being off by 2 on each of two points only when the misses are equal; large misses are punished much harder than small ones. This single choice turns out to have a clean geometry and a clean statistical pay-off.
The geometry is a shadow. Imagine your response values as the coordinates of one point floating in a high-dimensional space, and imagine all the response patterns your model could possibly produce as a flat sheet (a plane) inside that space. Least squares drops a perpendicular from your point straight down onto the sheet. The foot of that perpendicular is the model's best guess; the leftover vertical drop is the part the model cannot reach, the residual.
Why squared error and not, say, absolute error? Because under a mild and very common set of assumptions about the noise, least squares is provably the best you can do within a fair contest. The contest restricts attention to weight-recipes that are unbiased (right on average) and that combine the data in a straight linear way. Among all such recipes, least squares has the smallest spread. That is the promise this unit makes precise, and it is the reason linear models are the bedrock of statistics.
Visual Beginner
| Object | Plain meaning | Lives where |
|---|---|---|
| Response vector | the column of measured outcomes | a point in -dimensional space |
| Model plane | every outcome pattern the weights could produce | a flat sheet through the origin |
| Fitted values | the model's best reconstruction of the outcomes | the foot of the perpendicular |
| Residual | the part the model cannot reach | the perpendicular drop itself |
| Hat matrix | the machine that drops the perpendicular | a square table of numbers |
| Leverage | how much one point pulls its own fit | one number per data point |
The single picture to carry forward: the fitted values are a shadow of the data cast straight down onto the sheet of reachable patterns, and the residual is the gap between the data and its shadow. Everything else in this unit is bookkeeping about that shadow.
Worked example Beginner
Take four data points with one predictor and an intercept. The predictor values are and the responses are . We fit .
First the averages: and .
Now the slope. The numerator is the sum of :
.
The denominator is the sum of .
So the slope is , and the intercept is .
The fitted line is . The fitted values at the four predictors are . The residuals (observed minus fitted) are .
Two checks confirm the geometry. The residuals add to : the perpendicular drop has no leftover component along the all-ones direction. And the sum of times the residuals is : no leftover component along the predictor either. What this tells us is that the residual is genuinely perpendicular to the model plane, exactly as the shadow picture demands.
Check your understanding Beginner
Formal definition Intermediate+
Fix a design matrix of full column rank , and consider the linear model
where is the observed response, is the unknown parameter, and is a random error vector. The two moment conditions — zero mean and the scalar covariance — are the second-order or Gauss-Markov assumptions: the errors are uncorrelated (off-diagonal covariances vanish) and homoscedastic (equal variances down the diagonal). No distributional form is assumed yet.
The ordinary least-squares (OLS) estimator is any minimizer of the residual sum of squares . Setting the gradient to zero gives the normal equations . Full column rank makes invertible, so
The numerical algorithms that solve this system stably (QR, SVD) belong to the computational treatment 43.04.01; here the object of study is the estimator's statistical behaviour, sharpening the elementary survey 26.06.01.
The fitted values are where
is the hat matrix (it puts the hat on ). is symmetric and idempotent, , hence it is the orthogonal projection onto the column space — the same projection structure as the spectral/projection theory 01.01.13. Its complement projects onto the orthogonal complement, and the residual vector is . The diagonal entries of are the leverages; since is a projection, and .
The residual sum of squares is , and the unbiased variance estimator is . The coefficient of determination is with , the fraction of response variance the model captures.
Counterexamples to common slips
- Idempotence is not optionality. being a projection does not make ; that holds only when already lies in , i.e. the residual is zero. In general is the nearest point of the column space.
- BLUE is not BUE. Dropping the linearity restriction breaks the optimality claim: under normal errors a nonlinear estimator cannot beat OLS, but the Gauss-Markov theorem itself never promises that — it only ranks OLS first among linear unbiased estimators.
- Leverage is not residual size. A point with near has high leverage (an extreme predictor configuration) regardless of whether its residual is large; high leverage with a small residual still signals an influential point.
- does not validate a model. A high is compatible with a badly mis-specified mean function; it measures variance explained under the fitted model, not correctness of the model.
Key theorem with proof Intermediate+
Gauss-Markov theorem. Under the linear model with and and of full column rank, the OLS estimator is the best linear unbiased estimator (BLUE): for every linear unbiased estimator , the difference is positive semidefinite. The proof follows Hastie, Tibshirani & Friedman [Hastie 2009] §3.2.2 and Seber & Lee [Seber 2003] Ch. 3.
Proof. A linear estimator is for some fixed . Unbiasedness requires for every , which forces the constraint . Write , so that and , and set . The unbiasedness constraint gives .
Because , the covariance of any linear estimator is . Expand with :
The cross terms vanish. Indeed since , and is its transpose, also zero. Therefore
using , which is exactly . The matrix is positive semidefinite, so . Equality in the Loewner order holds for a given direction iff the corresponding rows of vanish, and recovers , so OLS is the unique BLUE up to almost-sure equality.
Bridge. The proof's engine is the orthogonal decomposition with : the deviation from the least-squares recipe is forced into the orthogonal complement of the column space, where it can only add variance. This is exactly the projection geometry of 01.01.13 wearing statistical clothing, and it is the foundational reason least squares is optimal rather than merely convenient. The result builds toward the distribution theory below — once normal errors are added, the same splits the variance into independent chi-squared pieces — and it appears again in the regularized estimators of 45.06.03, where deliberately accepting bias (so the unbiasedness constraint is dropped) buys a variance reduction that beats the BLUE in mean squared error. Putting these together, Gauss-Markov is the optimality benchmark that shrinkage methods are measured against; the central insight is that the theorem's hypotheses, not its conclusion, are where modern high-dimensional statistics intervenes.
Exercises Intermediate+
Lean formalization Intermediate+
Mathlib does not yet host the statistical linear model, so no module is wired in (lean_status: none). The intended statement of the Gauss-Markov theorem, once a multivariate-Gaussian-with-given-covariance API exists, would read roughly as follows.
-- Intended shape; not part of the current Babel Bible Lean build.
-- Requires: a `Cov` operator on random vectors and the Loewner order `⪯`.
variable {n p : ℕ} (X : Matrix (Fin n) (Fin p) ℝ)
variable (hX : (Xᵀ * X).det ≠ 0) -- full column rank
-- OLS estimator as a fixed linear map applied to y
noncomputable def olsHat : Matrix (Fin p) (Fin n) ℝ :=
(Xᵀ * X)⁻¹ * Xᵀ
-- Gauss-Markov: for any linear unbiased C (i.e. C * X = 1),
-- Cov (C y) - Cov (olsHat y) is positive semidefinite.
theorem gauss_markov
(C : Matrix (Fin p) (Fin n) ℝ) (hC : C * X = 1)
(σ2 : ℝ) (hσ : 0 ≤ σ2) :
(olsHat X) * (olsHat X)ᵀ ⪯ C * Cᵀ := by
sorrythe Mathlib gap analysis records what is missing: the random-vector covariance operator, the Loewner-order API on covariance matrices (Mathlib has Matrix.PosSemidef but not the named statistical model), and the chi-squared/F distribution layer needed for the inference half.
Advanced results Master
Assume henceforth normal errors, . The estimator is then a linear image of a Gaussian, hence Gaussian:
The residual quadratic form is governed by the projection , which is idempotent of rank . Writing and diagonalizing (its eigenvalues are ones and zeros), the standardized residual sum of squares is a sum of independent squared standard normals:
This is the distributional core of the theory: a quadratic form in a Gaussian vector with idempotent kernel of rank is exactly . Crucially and are independent. The estimator depends on only through and the residuals only through ; the two projections are orthogonal (), and orthogonal linear images of a single Gaussian are independent. This is Cochran's theorem specialized to the regression decomposition .
Independence is what makes the -test valid. For a single coordinate, . Dividing the standardized coefficient (which uses the unknown ) by the independent converts a normal over a scaled independent chi root into Student's distribution:
For a linear hypothesis with of rank , the same machinery yields the -test. The numerator measures how far the constrained fit lies from the unconstrained fit, scaled by ; the denominator is . Concretely,
because the numerator quadratic form is , independent of the denominator's . Setting and recovers the overall regression -statistic, and a single-row recovers .
When the homoscedasticity assumption fails — for known positive-definite — OLS remains unbiased but loses optimality. Aitken's theorem restores it: the GLS estimator is BLUE, with covariance , the latter being the (inflated) true covariance of the OLS estimator under correlated errors. Feasible GLS plugs an estimate into the formula and is the workhorse for serially correlated and heteroscedastic data.
Synthesis. The hat matrix is the foundational reason the whole edifice coheres: it is simultaneously the least-squares solver, the variance-decomposition operator, and the independence-generator. Putting these together, the decomposition into orthogonal projections is dual to the additive split , and this is exactly what licenses every - and -statistic — the central insight is that normality plus orthogonality equals independence, so the inference layer is forced by the geometry rather than assumed. The same projection generalises: replacing by in the inner product turns OLS into GLS and Gauss-Markov into Aitken, and the bridge is the whitening transform that maps the correlated problem back to the canonical one. This theory grounds the regularized estimators of 45.06.03, where shrinking trades the BLUE's unbiasedness for lower variance, and the discriminant and additive-model methods of 45.08.01 that reuse the projection and quadratic-form distribution theory verbatim.
Full proof set Master
Proposition 1 (Sampling distribution of ). Under and full column rank , .
Proof. . The second term is a fixed linear map applied to the Gaussian , so is Gaussian. Its mean is , and its covariance is .
Proposition 2 (Distribution of RSS). .
Proof. From Exercise 5, with symmetric idempotent of rank (rank equals trace for a projection, and ). Write the spectral decomposition with orthogonal and carrying ones. Put ; since is orthogonal and , also . Then , a sum of independent squared standard normals, which is .
Proposition 3 (Independence of and RSS). Under normality, and are independent.
Proof. depends on through (since ), i.e. through , while depends on through . The pair is jointly Gaussian with cross-covariance . Jointly Gaussian and uncorrelated implies independent, so ; any measurable function of one is independent of any measurable function of the other, giving .
Proposition 4 (-distribution of the coefficient statistic). .
Proof. Let . By Proposition 1, . By Proposition 2, , and by Proposition 3, . Now , a standard normal divided by the square root of an independent chi-squared over its degrees of freedom — the definition of Student's .
Proposition 5 (Aitken / GLS optimality). If with known, then is BLUE.
Proof. Factor (Cholesky, invertible) and set , , . Then with . The starred model meets the Gauss-Markov assumptions, so by the theorem its OLS estimator is BLUE in the starred parametrization. Substituting and and using gives . Because is an invertible linear map, the class of linear unbiased estimators is preserved, so BLUE-ness transfers back to the original model.
Connections Master
The hat matrix is the orthogonal projection of the spectral/projection theory
01.01.13; the idempotent self-adjoint characterization of projections used in Propositions 2 and 3 is precisely the finite-dimensional spectral statement, here carrying the variance decomposition.The elementary regression survey
26.06.01introduces the slope, intercept, and at the scatter-plot level; this unit supplies the matrix-form estimator, the Gauss-Markov optimality proof, and the exact sampling distributions that the survey states without derivation.The random-variable and multivariate-normal machinery of
26.03.01— expectation, covariance, the Gaussian transformation rule — is the engine behind every distributional result here.The numerical least-squares unit
43.04.01solves the same normal equations but worries about conditioning and backward stability (QR and SVD over normal equations); this unit takes the solution as given and studies its statistical sampling behaviour, so the two are the computational and inferential faces of one object.Ridge and lasso regularization
45.06.03deliberately relax the unbiasedness constraint that powers the Gauss-Markov proof, trading the BLUE property for a mean-squared-error gain in the high-dimensional regime where is ill-conditioned or singular.Discriminant analysis and generalized additive models
45.08.01reuse the projection and quadratic-form distribution theory: linear discriminant boundaries and additive-model backfitting both rest on the column-space projection and the chi-squared distribution of residual quadratic forms developed here.
Historical & philosophical context Master
The least-squares principle was published by Legendre in 1805 and developed probabilistically by Gauss, whose Theoria Motus Corporum Coelestium [Gauss 1809] tied it to the normal error law and to the determination of celestial orbits. Gauss returned to the problem in the Theoria Combinationis Observationum (1823), where he proved the optimality of least squares without assuming normality — the result now called the Gauss-Markov theorem. The attribution to Markov reflects A. A. Markov's early-twentieth-century textbook exposition, which brought Gauss's argument to a wider audience; the optimality claim is Gauss's.
The distributional theory came a century later. R. A. Fisher's work in the 1920s established the sampling distributions of regression statistics and named the analysis of variance, decomposing the total sum of squares into orthogonal components — the decomposition this unit casts as the projections and . W. G. Cochran [Cochran 1934] proved the theorem on the distribution of sums of quadratic forms in normal variables that underwrites the independence of and the residual sum of squares. A. C. Aitken [Aitken 1935] extended the Gauss-Markov optimality to correlated errors, giving the generalized-least-squares estimator. The modern matrix-projection formulation, the leverage diagnostics from the hat-matrix diagonal, and the unified treatment via the Moore-Penrose inverse for rank-deficient designs were consolidated by C. R. Rao and by Seber in the second half of the century.
Bibliography Master
@book{hastie2009elements,
author = {Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome},
title = {The Elements of Statistical Learning: Data Mining, Inference, and Prediction},
edition = {2},
publisher = {Springer},
year = {2009},
note = {Chapter 3, linear methods for regression}
}
@book{seber2003linear,
author = {Seber, George A. F. and Lee, Alan J.},
title = {Linear Regression Analysis},
edition = {2},
publisher = {Wiley},
year = {2003}
}
@book{rao1973linear,
author = {Rao, C. Radhakrishna},
title = {Linear Statistical Inference and Its Applications},
edition = {2},
publisher = {Wiley},
year = {1973}
}
@book{gauss1809theoria,
author = {Gauss, Carl Friedrich},
title = {Theoria Motus Corporum Coelestium in Sectionibus Conicis Solem Ambientium},
publisher = {Perthes and Besser},
year = {1809}
}
@article{cochran1934distribution,
author = {Cochran, William G.},
title = {The distribution of quadratic forms in a normal system, with applications to the analysis of covariance},
journal = {Mathematical Proceedings of the Cambridge Philosophical Society},
volume = {30},
number = {2},
pages = {178--191},
year = {1934}
}
@article{aitken1935least,
author = {Aitken, A. C.},
title = {On least squares and linear combination of observations},
journal = {Proceedings of the Royal Society of Edinburgh},
volume = {55},
pages = {42--48},
year = {1935}
}