Orthogonality, QR and OLS as a projection
LA · Chapter 312 min readAsked at Two Sigma, Citadel, DE Shaw, Jane Street
Assumes The four fundamental subspaces, and when Ax = b has a solution.
After this lesson you should be able to
- Build a projection matrix and list its properties.
- Describe Gram–Schmidt and the QR decomposition it produces.
- Say why QR is used to solve least squares rather than the normal equations.
Projection is the geometric content of least squares, and orthogonalisation is how it is computed. Understanding both turns a list of regression facts — orthogonal residuals, monotone , the meaning of "controlling for" — into consequences of one picture.
Equation 3.1
The projection matrix
Projects any vector onto the column space of . Everything about least squares follows from its two defining properties.
- Idempotent — projecting twice is projecting once.
- Symmetric, which is what makes it an *orthogonal* projection.
Proposition 3.2
What the picture gives you
The residual is orthogonal to the column space, because the closest point is reached by dropping a perpendicular. That single fact yields: residuals sum to zero when there is an intercept, residuals are uncorrelated with fitted values, and adding a regressor enlarges the space so the residual can only shrink.
Holds when
- Eigenvalues of a projection are 0 and 1, so counts the dimensions projected onto.
- is also a projection — onto the orthogonal complement — which is where the residuals live.
- Pythagoras applies: , which *is* the analysis of variance.
Derivation 3.3
Gram–Schmidt and QR
Turn a set of vectors into an orthonormal basis by removing, from each, its component along the ones already processed.
Normalise the first.
Subtract the part already explained — which is residualising.
Why not just invert . Forming squares the condition number, so a design matrix that was merely awkward becomes numerically hopeless: you can lose twice as many digits of precision as the problem itself requires. QR works on directly and never forms the product, so it keeps the original conditioning. On well-conditioned data the two agree; on collinear data, which is the case where you most need the answer, the normal equations can return coefficients that are simply wrong. Every serious least-squares routine uses QR or SVD for this reason.
Example 3.4
Project onto the line spanned by , and give the residual.
Show the worked solutionHide the worked solution
Worked solution
- Formula
- Substitute
- Solve
- Answer
Sanity check. The residual is orthogonal to , as it must be: . And Pythagoras holds — — which is the analysis of variance in two dimensions.
The rest of this lesson is in Premium
You have read the opening. 9 more sections follow, including 3 worked examples and 3 quick checks.
Nothing is charged for 7 days, and you can cancel before then. Or read The law of large numbers and the central limit theorem in full, free.