# Projection 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 ${\displaystyle \mathbf {P} }$ is also named hat matrix as it "puts a hat on ${\displaystyle \mathbf {y} }$". The formula for the vector of residuals ${\displaystyle \mathbf {r} }$ can also be expressed compactly using the projection matrix:

${\displaystyle \mathbf {r} =\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 \mathbf {I} -\mathbf {P} }$ is sometimes referred to as the residual maker 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 p_{ij}={\frac {\operatorname {Cov} \left[{\hat {y}}_{i},y_{j}\right]}{\operatorname {Var} \left[y_{j}\right]}}}$

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

${\displaystyle \mathbf {\Sigma } _{\mathbf {r} }=\left(\mathbf {I} -\mathbf {P} \right)^{\textsf {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 {r} }=\left(\mathbf {I} -\mathbf {P} \right)\sigma ^{2}}$.

## Intuition

A matrix, ${\displaystyle \mathbf {A} }$ has its column space depicted as the green line. The projection of some vector ${\displaystyle \mathbf {b} }$ onto the column space of ${\displaystyle \mathbf {A} }$ is the vector ${\displaystyle \mathbf {x} }$

From the figure, it is clear that the closest point from the vector ${\displaystyle \mathbf {b} }$ onto the column space of ${\displaystyle \mathbf {A} }$, is ${\displaystyle \mathbf {Ax} }$, and is one where we can draw a line orthogonal to the column space of ${\displaystyle \mathbf {A} }$. A vector that is orthogonal to the column space of a matrix is in the nullspace of the matrix transpose, so

${\displaystyle \mathbf {A} ^{\textsf {T}}(\mathbf {b} -\mathbf {Ax} )=0}$

From there, one rearranges, so

{\displaystyle {\begin{aligned}&&\mathbf {A} ^{\textsf {T}}\mathbf {b} &-\mathbf {A} ^{\textsf {T}}\mathbf {Ax} =0\\\Rightarrow &&\mathbf {A} ^{\textsf {T}}\mathbf {b} &=\mathbf {A} ^{\textsf {T}}\mathbf {Ax} \\\Rightarrow &&\mathbf {x} &=\left(\mathbf {A} ^{\textsf {T}}\mathbf {A} \right)^{-1}\mathbf {A} ^{\textsf {T}}\mathbf {b} \end{aligned}}}

Therefore, since ${\displaystyle \mathbf {x} }$ is on the column space of ${\displaystyle \mathbf {A} }$, the projection matrix, which maps ${\displaystyle \mathbf {b} }$ onto ${\displaystyle \mathbf {x} }$ is just ${\displaystyle \mathbf {Ax} }$, or ${\displaystyle \mathbf {A} \left(\mathbf {A} ^{\textsf {T}}\mathbf {A} \right)^{-1}\mathbf {A} ^{\textsf {T}}\mathbf {b} }$

## 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 ${\displaystyle \mathbf {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} ^{\textsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\textsf {T}}\mathbf {y} ,}$

so the fitted values are

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

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

${\displaystyle \mathbf {P} \equiv \mathbf {X} \left(\mathbf {X} ^{\textsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\textsf {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} ^{\textsf {T}}\mathbf {\Psi } ^{-1}\mathbf {X} \right)^{-1}\mathbf {X} ^{\textsf {T}}\mathbf {\Psi } ^{-1}\mathbf {y} }$.

the hat matrix is thus

${\displaystyle H=\mathbf {X} \left(\mathbf {X} ^{\textsf {T}}\mathbf {\Psi } ^{-1}\mathbf {X} \right)^{-1}\mathbf {X} ^{\textsf {T}}\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} ^{\textsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\textsf {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 \mathbf {I} -\mathbf {P} }$.
• ${\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 nr zeros, while the eigenvalues of ${\displaystyle \mathbf {M} }$ consist of nr 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 subspaces.

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.[8] 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={\begin{bmatrix}A&B\end{bmatrix}}}$. Define the hat or projection operator as ${\displaystyle P\{X\}=X\left(X^{\textsf {T}}X\right)^{-1}X^{\textsf {T}}}$. Similarly, define the residual operator as ${\displaystyle M\{X\}=I-P\{X\}}$. Then the projection matrix can be decomposed as follows:[9]

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

where, e.g., ${\displaystyle P\{A\}=A\left(A^{\textsf {T}}A\right)^{-1}A^{\textsf {T}}}$ 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. ^ "Data Assimilation: Observation influence diagnostic of a data assimilation system" (PDF). Archived from the original (PDF) on 2014-09-03.
3. ^ a b Hoaglin, David C.; Welsch, Roy E. (February 1978). "The Hat Matrix in Regression and ANOVA" (PDF). 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. ^ "Proof that trace of 'hat' matrix in linear regression is rank of X". Stack Exchange. April 13, 2017.
9. ^ Rao, C. Radhakrishna; Toutenburg, Helge; Shalabh; Heumann, Christian (2008). Linear Models and Generalizations (3rd ed.). Berlin: Springer. pp. 323. ISBN 978-3-540-74226-5.