# Projection matrix

In statistics, the projection matrix ($\mathbf {P}$ ), sometimes also called the influence matrix or hat matrix ($\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. 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 $\mathbf {y}$ and the vector of fitted values by $\mathbf {\hat {y}}$ ,

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

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

{\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 $\mathbf {u}$ , by error propagation, equals

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

where $\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 $\mathbf {\Sigma } =\sigma ^{2}\mathbf {I}$ , this reduces to:

$\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

$\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

${\hat {\boldsymbol {\beta }}}=\left(\mathbf {X} ^{\mathsf {T}}\mathbf {X} \right)^{-1}\mathbf {X} ^{\mathsf {T}}\mathbf {y} ,$ so the fitted values are

${\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

$\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

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

the hat matrix is thus

$H=\mathbf {X} \left(\mathbf {X} ^{\mathsf {T}}\mathbf {\Psi } ^{-1}\mathbf {X} \right)^{-1}\mathbf {X} ^{\mathsf {T}}\mathbf {\Psi } ^{-1}$ and again it may be seen that $H^{2}=H\cdot H=H$ , though now it is no longer symmetric.

## Properties

The projection matrix has a number of useful algebraic properties. In the language of linear algebra, the projection matrix is the orthogonal projection onto the column space of the design matrix $\mathbf {X}$ .(Note that $\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:

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

The projection matrix corresponding to a linear model is symmetric and idempotent, that is, $\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 $\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 $\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 $X$ can be decomposed by columns as $X=[A~~~B]$ . Define the hat or projection operator as $P\{X\}=X\left(X^{\mathsf {T}}X\right)^{-1}X^{\mathsf {T}}$ . Similarly, define the residual operator as $M\{X\}=I-P\{X\}$ . Then the projection matrix can be decomposed as follows:

$P\{X\}=P\{A\}+P\{M\{A\}B\},$ where, e.g., $P\{A\}=A\left(A^{\mathsf {T}}A\right)^{-1}A^{\mathsf {T}}$ and $M\{A\}=I-P\{A\}$ . There are a number of applications of such a decomposition. In the classical application $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 $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 $X$ without explicitly forming the matrix $X$ , which might be too large to fit into computer memory.