In statistics, the hat matrix, H, sometimes also called influence matrix and projection matrix, maps the vector of observed values to the vector of fitted values (or predicted values). It describes the influence each observed value has on each fitted value. The diagonal elements of the hat matrix are the leverages, which describe the influence each observed value has on the fitted value for that same observation.
If the vector of observed values is denoted by y and the vector of fitted values by ŷ,
As ŷ is usually pronounced "y-hat", the hat matrix is so named as it "puts a hat on y".
For uncorrelated errors, the estimated parameters are
so the fitted values are
Therefore the hat matrix is given by
The hat matrix corresponding to a linear model is symmetric and idempotent, that is, . 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.
The formula for the vector of residuals r can be expressed compactly using the hat matrix:
The covariance matrix of the residuals is therefore, by error propagation, equal to , where Σ is the covariance matrix of the errors (and by extension, the observations as well). For the case of linear models with independent and identically distributed errors in which Σ = σ2I, this reduces to (I − H)σ2.
For linear models, the trace of the hat matrix is equal to the rank of 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 y, the hat matrix can be used to define the effective degrees of freedom of the model.
The hat matrix has a number of useful algebraic properties. Practical applications of the hat matrix in regression analysis include leverage and Cook's distance, which are concerned with identifying observations which have a large effect on the results of a regression.
Some facts of the hat matrix are summarized as follows:
- H is symmetric, and so is I - H.
- H is idempotent: , and so is I - H.
- X is invariant under H : hence .
The above may be generalized to the case of correlated errors. Suppose that the covariance matrix of the errors is Σ. Then since
the hat matrix is thus
and again it may be seen that H2 = H
Suppose the design matrix can be decomposed by columns as . Define the Hat operator as . Similarly, define the residual operator as . Then the Hat matrix of can be decomposed as follows:
There are a number of applications of such a partitioning. The classical application has 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 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 without explicitly forming the matrix , which might be too large to fit into computer memory.
- Moore–Penrose pseudoinverse
- Studentized residuals
- Effective degrees of freedom
- Idempotent matrix
- Mean and predicted response
- Data Assimilation: Observation inﬂuence diagnostic of a data assimilation system
- 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
- David A. Freedman (2009). Statistical Models: Theory and Practice. Cambridge University Press.
- Gans, P. (1992) Data Fitting in the Chemical Sciences,, Wiley. ISBN 978-0-471-93412-7
- Draper, N.R., Smith, H. (1998) Applied Regression Analysis, Wiley. ISBN 0-471-17082-6
- Rao, C. Radhakrishna; Toutenburg, Shalabh, Heumann (2008). Linear Models and Generalizations (3rd ed.). Berlin: Springer. p. 323. ISBN 978-3-540-74226-5.