Matrix Decompositions — QR
00 · Symbol Glossary
The decomposition of a matrix with linearly independent columns into an orthogonal factor (orthonormal columns) and an upper triangular factor . Extends the Gram-Schmidt construction from Chapter 11 into a matrix factorisation usable for least squares and eigenvalue algorithms.
The defining property of the factor when has linearly independent columns: the columns of are orthonormal. Read aloud as "Q transpose Q equals the identity." Inversion of is free: .
The residual in a least squares problem — the part of that the column space of cannot explain. Minimising is the objective of ordinary least squares regression.
The Gram matrix formed from the columns of . The classical least squares normal equations are . This system is theoretically correct but numerically dangerous when — QR avoids forming entirely.
01 · From Gram-Schmidt to QR
Chapter 11 constructed orthonormal vectors from a linearly independent set via the Gram-Schmidt process. QR packages that construction into a single matrix factorisation: the columns of are the orthonormalised vectors, and records the projection coefficients that reconstruct the original columns of .
If has linearly independent columns (), then there exists a factorisation:
has orthonormal columns: .
is upper triangular with positive diagonal entries .
The columns of are produced by Gram-Schmidt on the columns of . The entry for , and for .
A fund manager runs a 3-factor model on 252 trading days. The design matrix has columns: market, size, and value factor returns. The response holds the fund's daily excess returns.
Factor exposures (betas) solve the overdetermined system in the least squares sense. QR factorisation of gives numerically stable betas without forming , which squares the condition number of a potentially ill-conditioned factor correlation structure.
Let — column 2 equals column 1.
Gram-Schmidt on gives . Normalising requires division by .
Why it breaks: would have , violating the positive-diagonal requirement. The columns of do not span a full -dimensional subspace.
Consequence: QR requires linearly independent columns. Rank-deficient needs a pivoted variant () or SVD-based least squares.
02 · Constructing and via Gram-Schmidt
The algorithm from Chapter 11, now read as a factorisation.
Given linearly independent columns of :
Step 1: , , .
Step (for ):
Assemble and the upper triangular .
Column 1: . .
. .
Project onto : .
The comes from the dot product formula with already normalised.
Orthogonalise : .
.
Normalise: .
Assemble factors:
Verify : ✓.
✓.
✓. All six entries of the product match .
The upper triangular is the coefficient matrix in the expansion . Entry is the component of in direction . Zeros below the diagonal reflect the fact that has no component in directions for .
03 · Properties of the QR Factorisation
The columns of satisfy:
— Kronecker delta: when , when .
When is square (), is an orthogonal matrix and also holds.
satisfies for all . The diagonal entries are the norms of the orthogonalised vectors before normalisation — strictly positive when columns of are independent.
For with , has but .
Setup: from the example above.
Computation: is , not — the three rows of span only a 2-dimensional subspace of .
Why it breaks: requires orthonormal columns in . A tall thin has only columns.
Consequence: for tall , use for inversion in the -dimensional column space. Do not treat as a square orthogonal matrix.
04 · Least Squares via QR
The normal equations solve least squares algebraically. QR solves the same problem without squaring the condition number.
Given with and full column rank, find that minimises:
— the residual vector. The minimiser satisfies the normal equations .
With :
projects onto the coordinate system of the orthonormal columns of . Back-substitution on the small upper triangular system gives directly.
Note: is here — one regressor. , .
Compute : .
Solve : , so .
Residual: . .
. The part of orthogonal to the column of has length .
05 · QR vs Normal Equations — Numerical Stability
The normal equations form , whose condition number satisfies:
Squaring the condition number amplifies relative errors in floating-point arithmetic. QR works directly with : solving has conditioning — no squaring.
For a regression with , normal equations have — potentially losing 8 digits of precision in double arithmetic. QR retains 4 digits of reliability relative to .
Design matrix with nearly collinear factor columns (value and growth proxies with correlation ). .
Normal equations: . Beta estimates on the 4th and 5th factors may have relative errors in double precision — unreliable for risk attribution.
QR: solves with . Same theoretical answer, but stable betas. Production quant libraries (LAPACK dgels) use QR or SVD, not .
For , columns are nearly orthogonal but .
in limited precision — the small terms vanish, making singular or nearly so.
Consequence: normal equations destroy information present in . QR on directly preserves the nearly-orthogonal structure. This is why Chapter 20 treats condition numbers as first-class objects.
06 · Practice Exercises
Apply Gram-Schmidt to the two columns. , , .
. . .
.
. . .
Verify: ✓.
Find the QR decomposition of . Show and verify .
After building and from Gram-Schmidt, verify by computing the four entries of the product.
From the chapter example: .
✓.
✓.
✓.
. Columns are orthonormal.
For , verify using the from the chapter's step-by-step. Show all three diagonal/off-diagonal entries.
Compute first — a vector in . Then back-substitute on .
Use QR from the chapter: , .
: row 1 = . Row 2 = .
Solve: , so .
, so , .
.
Using the QR factors for , solve the least squares problem for via .
Compare the two solution paths: (1) solve ; (2) solve . Both give the same in exact arithmetic.
, — exact fit.
, . Normal equations: .
QR: , . . , ✓.
Both methods agree. For this well-conditioned case they are identical. The advantage of QR appears when and loses precision.
For and , solve via normal equations and via QR. Confirm both give the same and explain when they would diverge in floating point.
. If , how many digits of relative accuracy might normal equations lose in double precision ( digits)?
, so .
In double precision, relative error in solving a system is roughly .
Normal equations may lose digits of accuracy relative to the ideal answer — leaving reliable digits.
QR on directly: error — about 1000 times more accurate.
Therefore production least squares uses QR or SVD, not .
A regression design matrix has . Estimate . Explain in one paragraph why a quant library would prefer QR over normal equations for computing factor betas.
Build with columns = factor returns. QR gives betas via where is the fund's excess returns. Interpret as market beta.
(3 days, 3 factors), .
Gram-Schmidt: , .
, , .
, eventually , .
: .
Back-substitute on for (factor exposures).
The market beta captures average sensitivity to the first factor column — the parallel shift in all factors. QR isolates each factor's incremental contribution via orthogonality.
Three days of factor returns form (market, size, value). Fund excess returns are . Outline the QR steps to estimate factor betas and interpret as market exposure.
07 · Summary
| Term | Definition |
|---|---|
| QR decomposition | ; has orthonormal columns, upper triangular |
| Columns of are orthonormal; when square | |
| — projection coefficient | |
| Least squares via QR | Solve by back substitution |
| Normal equations | — correct but |
| Numerical stability | QR avoids forming ; preferred for regression |
| Residual | ; minimised in norm |
Next: Matrix Decompositions — SVD — the universal factorisation that exists for every matrix, connects to PCA and low-rank approximation, and underpins modern quant analytics.