Language
• #### Related Blog

• Unable to find any related blog!

# Hat matrix

In statistics, the projection matrix ${\displaystyle \mathbf {P} }$,[1] sometimes also called the influence matrix[2] or hat matrix ${\displaystyle \mathbf {H} }$, maps the vector of response values (dependent variable values) to the vector of fitted values (or predicted values). It describes the influence each response value has on each fitted value.[3][4] The diagonal elements of the projection matrix are the leverages, which describe the influence each response value has on the fitted value for that same observation.

## Overview

If the vector of response values is denoted by ${\displaystyle \mathbf {y} }$ and the vector of fitted values by ${\displaystyle \mathbf {\hat {y}} }$,

${\displaystyle \mathbf {\hat {y}} =\mathbf {P} \mathbf {y} .}$

As ${\displaystyle \mathbf {\hat {y}} }$ is usually pronounced "y-hat", the projection matrix is also named hat matrix as it "puts a hat on ${\displaystyle \mathbf {y} }$". The formula for the vector of residuals ${\displaystyle \mathbf {u} }$ can also be expressed compactly using the projection matrix:

${\displaystyle \mathbf {u} =\mathbf {y} -\mathbf {\hat {y}} =\mathbf {y} -\mathbf {P} \mathbf {y} =\left(\mathbf {I} -\mathbf {P} \right)\mathbf {y} .}$

where ${\displaystyle \mathbf {I} }$ is the identity matrix. The matrix ${\displaystyle \mathbf {M} \equiv \left(\mathbf {I} -\mathbf {P} \right)}$ is sometimes referred to as the annihilator matrix. Moreover, the element in the ith row and jth column of ${\displaystyle \mathbf {P} }$ is equal to the covariance between the jth response value and the ith fitted value, divided by the variance of the former:

{\displaystyle {\begin{aligned}p_{ij}=\operatorname {Cov} \left[{\hat {y}}_{i},y_{j}\right]/\operatorname {Var} \left[y_{j}\right]\end{aligned}}}

Therefore, the covariance matrix of the residuals ${\displaystyle \mathbf {u} }$, by error propagation, equals

${\displaystyle \mathbf {\Sigma } _{\mathbf {u} }=\left(\mathbf {I} -\mathbf {P} \right)^{\mathsf {T}}\mathbf {\Sigma } \left(\mathbf {I} -\mathbf {P} \right)}$,

where ${\displaystyle \mathbf {\Sigma } }$ is the covariance matrix of the error vector (and by extension, the response vector as well). For the case of linear models with independent and identically distributed errors in which ${\displaystyle \mathbf {\Sigma } =\sigma ^{2}\mathbf {I} }$, this reduces to:[3]

${\displaystyle \mathbf {\Sigma } _{\mathbf {u} }=\left(\mathbf {I} -\mathbf {P} \right)\sigma ^{2}}$.

## Linear model

Suppose that we wish to estimate a linear model using linear least squares. The model can be written as

${\displaystyle \mathbf {y} =\mathbf {X} {\boldsymbol {\beta }}+{\boldsymbol {\varepsilon }},}$

where X is a matrix of explanatory variables (the design matrix), β is a vector of unknown parameters to be estimated, and ε is the error vector.

Many types of models and techniques are subject to this formulation. A few examples are linear least squares, smoothing splines, regression splines, local regression, kernel regression, and linear filtering.

### Ordinary least squares

When the weights for each observation are identical and the errors are uncorrelated, the estimated parameters are

${\displaystyle {\hat {\boldsymbol {\beta }}}=\left(\mathbf {X} ^{\mathsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\mathsf {T}}\mathbf {y} ,}$

so the fitted values are

${\displaystyle {\hat {\mathbf {y} }}=\mathbf {X} {\hat {\boldsymbol {\beta }}}=\mathbf {X} \left(\mathbf {X} ^{\mathsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\mathsf {T}}\mathbf {y} .}$

Therefore, the projection matrix (and hat matrix) is given by

${\displaystyle \mathbf {P} \equiv \mathbf {X} \left(\mathbf {X} ^{\mathsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\mathsf {T}}.}$

### Weighted and generalized least squares

The above may be generalized to the cases where the weights are not identical and/or the errors are correlated. Suppose that the covariance matrix of the errors is Ψ. Then since

${\displaystyle {\hat {\mathbf {\beta } }}_{\text{GLS}}=\left(\mathbf {X} ^{\top }\mathbf {\Psi } ^{-1}\mathbf {X} \right)^{-1}\mathbf {X} ^{\top }\mathbf {\Psi } ^{-1}\mathbf {y} }$.

the hat matrix is thus

${\displaystyle H=\mathbf {X} \left(\mathbf {X} ^{\top }\mathbf {\Psi } ^{-1}\mathbf {X} \right)^{-1}\mathbf {X} ^{\top }\mathbf {\Psi } ^{-1}}$

and again it may be seen that ${\displaystyle H^{2}=H\cdot H=H}$, though now it is no longer symmetric.

## Properties

The projection matrix has a number of useful algebraic properties.[5][6] In the language of linear algebra, the projection matrix is the orthogonal projection onto the column space of the design matrix ${\displaystyle \mathbf {X} }$.[4](Note that ${\displaystyle \left(\mathbf {X} ^{\mathsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\mathsf {T}}}$ is the pseudoinverse of X.) Some facts of the projection matrix in this setting are summarized as follows:[4]

• ${\displaystyle \mathbf {u} =(\mathbf {I} -\mathbf {P} )\mathbf {y} ,}$ and ${\displaystyle \mathbf {u} =\mathbf {y} -\mathbf {P} \mathbf {y} \perp \mathbf {X} .}$
• ${\displaystyle \mathbf {P} }$ is symmetric, and so is ${\displaystyle \mathbf {M} \equiv \left(\mathbf {I} -\mathbf {P} \right)}$.
• ${\displaystyle \mathbf {P} }$ is idempotent: ${\displaystyle \mathbf {P} ^{2}=\mathbf {P} }$, and so is ${\displaystyle \mathbf {M} }$.
• If ${\displaystyle \mathbf {X} }$ is an (n × r) matrix with ${\displaystyle \operatorname {rank} (\mathbf {X} )=r}$, then ${\displaystyle \operatorname {rank} (\mathbf {P} )=r}$
• The eigenvalues of ${\displaystyle \mathbf {P} }$ consist of r ones and n−r zeros, while the eigenvalues of ${\displaystyle \mathbf {M} }$ consist of n−r ones and r zeros.[7]
• ${\displaystyle \mathbf {X} }$ is invariant under ${\displaystyle \mathbf {P} }$ : ${\displaystyle \mathbf {PX} =\mathbf {X} ,}$ hence ${\displaystyle \left(\mathbf {I} -\mathbf {P} \right)\mathbf {X} =\mathbf {0} }$.
• ${\displaystyle \left(\mathbf {I} -\mathbf {P} \right)\mathbf {P} =\mathbf {P} \left(\mathbf {I} -\mathbf {P} \right)=\mathbf {0} .}$
• ${\displaystyle \mathbf {P} }$ is unique for certain subspace.

The projection matrix corresponding to a linear model is symmetric and idempotent, that is, ${\displaystyle \mathbf {P} ^{2}=\mathbf {P} }$. However, this is not always the case; in locally weighted scatterplot smoothing (LOESS), for example, the hat matrix is in general neither symmetric nor idempotent.

For linear models, the trace of the projection matrix is equal to the rank of ${\displaystyle \mathbf {X} }$, which is the number of independent parameters of the linear model. For other models such as LOESS that are still linear in the observations ${\displaystyle \mathbf {y} }$, the projection matrix can be used to define the effective degrees of freedom of the model.

Practical applications of the projection matrix in regression analysis include leverage and Cook's distance, which are concerned with identifying influential observations, i.e. observations which have a large effect on the results of a regression.

## Blockwise formula

Suppose the design matrix ${\displaystyle X}$ can be decomposed by columns as ${\displaystyle X=[A~~~B]}$. Define the hat or projection operator as ${\displaystyle P\{X\}=X\left(X^{\top }X\right)^{-1}X^{\top }}$. Similarly, define the residual operator as ${\displaystyle M\{X\}=I-P\{X\}}$. Then the projection matrix can be decomposed as follows:[8]

${\displaystyle P\{X\}=P\{A\}+P\{M\{A\}B\},}$

where, e.g., ${\displaystyle P\{A\}=A\left(A^{\top }A\right)^{-1}A^{\top }}$ and ${\displaystyle M\{A\}=I-P\{A\}}$. There are a number of applications of such a decomposition. In the classical application ${\displaystyle A}$ is a column of all ones, which allows one to analyze the effects of adding an intercept term to a regression. Another use is in the fixed effects model, where ${\displaystyle A}$ is a large sparse matrix of the dummy variables for the fixed effect terms. One can use this partition to compute the hat matrix of ${\displaystyle X}$ without explicitly forming the matrix ${\displaystyle X}$, which might be too large to fit into computer memory.

## References

1. ^ Basilevsky, Alexander (2005). Applied Matrix Algebra in the Statistical Sciences. Dover. pp. 160–176. ISBN 0-486-44538-0.
2. ^
3. ^ a b Hoaglin, David C.; Welsch, Roy E. (February 1978). "The Hat Matrix in Regression and ANOVA". The American Statistician. 32 (1): 17–22. doi:10.2307/2683469. JSTOR 2683469.
4. ^ a b c David A. Freedman (2009). Statistical Models: Theory and Practice. Cambridge University Press.
5. ^ Gans, P. (1992). Data Fitting in the Chemical Sciences. Wiley. ISBN 0-471-93412-7.
6. ^ Draper, N. R.; Smith, H. (1998). Applied Regression Analysis. Wiley. ISBN 0-471-17082-8.
7. ^ Amemiya, Takeshi (1985). Advanced Econometrics. Cambridge: Harvard University Press. pp. 460–461. ISBN 0-674-00560-0.
8. ^ Rao, C. Radhakrishna; Toutenburg, Helge; Shalabh; Heumann, Christian (2008). Linear Models and Generalizations (3rd ed.). Berlin: Springer. p. 323. ISBN 978-3-540-74226-5.

#### Related Blogs

• Did not find any related blogs!