Definitioncore
Hat matrix
Also called influence matrix, projection matrix of least squares.
The matrix H = X (X^T X)^(-1) X^T that maps the responses to the fitted values. It is a projection; its diagonal holds the leverages.
The hat matrix of a linear regression is the matrix that turns the observed responses into the fitted values: . It "puts the hat on ". For a design matrix of full column rank it is , the orthogonal projection onto the column space of . It depends only on , not on . Its diagonal entries are the leverages, and most single-point regression diagnostics (studentized residuals, Cook's distance, leave-one-out residuals) are simple functions of and the residuals. The fit itself is on the ordinary least squares page.
Definition
Let be a real matrix of rank (so ). Its columns include the intercept column of ones when the model has one; some texts write for . The hat matrix is
where is row of . If is the least squares coefficient vector, then and the residual vector is . The matrix is sometimes called the residual maker.
Computation. With a thin QR decomposition , where is with orthonormal columns and is nonsingular, . With a thin singular value decomposition , . So is the squared length of row of , which costs for the factorization and for all diagonal entries, without forming or the matrix . If has rank , the projection onto its column space is still unique and equals , with the pseudoinverse, but the formula with does not apply.
Properties. Each follows from the definition in one or two lines.
- Symmetric: , since is symmetric.
- Idempotent: . So is the orthogonal projection onto , and is the orthogonal projection onto its orthogonal complement, the residual space. In particular , and .
- Trace and rank : . A symmetric idempotent matrix has eigenvalues with , so each is 0 or 1; has eigenvalues 1 and eigenvalues 0, and , the residual degrees of freedom.
- Only the column space matters: if is a nonsingular matrix, has the same hat matrix. Rescaling, centering or reordering the predictors does not change .
- Sensitivities: . Row gives the weights with which the fitted value averages the responses.
- Covariances: if , then and , so : residuals are correlated and have unequal variances even when the errors do not.
- Diagonal bounds: by properties 1 and 2, so . If the model has an intercept, (rows sum to 1) and is again a projection, so . The average of the is .
- Leave-one-out: the prediction error of from the fit without observation is when . This follows from the Sherman-Morrison formula applied to .
Examples and non-examples
Intercept only. gives : every fitted value is , and every .
Simple linear regression. For , with the mean and ,
A numerical case. Take , so , , and . Exact arithmetic gives the diagonal
whose sum is . The last row is ; it sums to 1, and the sum of its squares is , as property 7 says. So the fitted value at puts weight 0.836 on its own response, and the five other points share the rest, with negative weights on the far ones. With the responses the residual at is , but the line fitted without that point predicts 10.3 there, a prediction error of . A small residual at a high-leverage point says little about the fit there.
One-way layout. For group indicator columns, is block diagonal, and each block is : the fitted value is the group mean, and .
Non-example: the ridge smoother. Ridge regression gives with , . It is symmetric but not idempotent: its eigenvalues are , with the singular values of . Its trace, the effective degrees of freedom, is less than . Diagnostics that use do not carry over unchanged.
Non-example: weighted least squares. With weights , the fitted values are . This matrix is idempotent but not symmetric, an oblique projection. The symmetric version is , the hat matrix of the scaled problem; weighted least squares uses that one.
Non-example: without full column rank. If two columns are equal, is singular and the formula fails. The projection still exists and has trace equal to the rank.
Related definitions
- Leverage is the diagonal entry , the self-influence of observation .
- Studentized residuals divide by an estimate of , using property 6.
- Cook's distance measures the shift of all fitted values when observation is deleted, through and .
- Smoother matrix. For a linear smoother (kernel, spline, ridge), plays the role of , and is called the effective number of parameters. The leave-one-out shortcut of property 8 holds for ridge regression and gives the closed form of leave-one-out cross-validation.
- Projection matrices in general. Any symmetric idempotent matrix is the orthogonal projection onto its column space. The least squares problem page derives least squares as this projection.
References
- David C. Hoaglin and Roy E. Welsch, The hat matrix in regression and ANOVA, The American Statistician 32(1), 1978, pp. 17 to 22, The whole paper (the properties of H, the bounds on its diagonal, the average p/n and the rule 2p/n)
- George A. F. Seber and Alan J. Lee, Linear Regression Analysis, second edition, Wiley, 2003, Chapter 3 (least squares as an orthogonal projection, idempotent matrices and their trace) and Section 10.2 (residuals and hat matrix diagonals)
- David A. Belsley, Edwin Kuh and Roy E. Welsch, Regression Diagnostics, Wiley, 1980, Chapter 2 (the hat matrix and the diagnostics built on its diagonal)
- Gene H. Golub and Charles F. Van Loan, Matrix Computations, fourth edition, Johns Hopkins University Press, 2013, Section 5.2 (the thin QR factorization, whose Q_1 Q_1^T is the orthogonal projection on the range of X)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 7G73ZX Edit this page History Report an error Markdown