Tutorials › Regression Analysis (Undergraduate) › Hat Values and Leverage

Leverage and Influential Observations · Tutorial 544 of 991

Hat Values and Leverage

See how the diagonal of the OLS hat matrix measures predictor leverage, why its values lie between zero and one, and how to calculate and check them.

Intermediate 9 min read

What You'll Learn

  • Define the hat matrix and interpret its diagonal entries as leverage values.
  • Explain why each leverage value lies between zero and one.
  • Derive why the leverage values sum to the number of independent design columns.
  • Calculate the average leverage in a full-rank OLS model.
  • Compute leverage values by hand for simple and multiple regression designs.
  • Distinguish predictor-based leverage from residual size and influence.

What Hat Values Measure

In ordinary least-squares (OLS) regression, each fitted value is a weighted combination of the observed responses. The weights are determined by the predictor values, not by the observed response values. The diagonal weight for observation \(i\) is its hat value, also called its leverage. Hat values help describe how unusual an observation's predictor information is relative to the rest of the design.

This is a property of the predictor data and the chosen model, such as whether an intercept or additional predictors are included. It does not depend on whether the observed response is close to its fitted value. Consequently, a high hat value is not, by itself, evidence that an observation has a large residual or an influential effect on the fitted regression.

Definition: Write the OLS model in matrix form as \(y=X\beta+\varepsilon\), where \(y\) is the vector of \(n\) observed responses and \(X\) is the \(n\)-by-\(m\) design matrix. Its columns contain the predictors used in the model; if the model has an intercept, one column consists of ones. Assume \(X\) has full column rank \(m\), so \(X'X\) is invertible. The hat matrix is \(H=X(X'X)^{-1}X'\). It maps the observed response vector to fitted values: \(\hat{y}=Hy\). The hat value for observation \(i\) is the diagonal entry \(h_{ii}\) of \(H\).

The name comes from the mapping \(y\mapsto\hat{y}\): the matrix puts a “hat” on the observed response vector. The off-diagonal entries also contribute to fitted values, but this tutorial focuses on the diagonal entries. The algebraic results below require a full-rank design for the displayed inverse. They do not require normally distributed errors or equal error variances: they follow from the OLS design matrix itself.

Range and Average of the Hat Values

For a full-rank design with \(m\) columns, every hat value is between zero and one, inclusive. Also, all \(n\) hat values sum to \(m\), so their average is \(m/n\). These facts give useful checks on hand calculations and a basic reference for understanding how the leverage is distributed across observations.

Theorem: For the full-rank OLS hat matrix \(H=X(X'X)^{-1}X'\), \(0\le h_{ii}\le 1\) for every observation \(i\), and \(\sum_{i=1}^{n}h_{ii}=m\). Thus the average hat value is \(m/n\). If a model has \(k\) predictors and an intercept, then \(m=k+1\) and the average is \((k+1)/n\).

Here is a short derivation. The matrix \(H\) is symmetric because \((X'X)^{-1}\) is symmetric. It is also idempotent, meaning \(H^2=H\): multiplying out gives \(X(X'X)^{-1}(X'X)(X'X)^{-1}X'=H\). Let \(e_i\) be the vector with a one in position \(i\) and zeros elsewhere. Symmetry and idempotence give \(h_{ii}=e_i'He_i=(He_i)'(He_i)\), which is a squared length and hence nonnegative. The matrix \(I-H\) is also symmetric and idempotent, so \(1-h_{ii}=e_i'(I-H)e_i=((I-H)e_i)'((I-H)e_i)\ge0\). Therefore \(h_{ii}\le1\).

For the sum, the sum of diagonal entries is the trace. Using the identity that the trace of a product can be cyclically rearranged,

$$ \sum_{i=1}^{n} h_{ii} =\operatorname{tr}(H) =\operatorname{tr}\!\left(X(X'X)^{-1}X'\right) =\operatorname{tr}\!\left((X'X)^{-1}X'X\right) =\operatorname{tr}(I_m) =m. $$

Dividing this total by the \(n\) observations gives the average \(m/n\). In a model with an intercept and \(k\) predictors, the design matrix has \(k+1\) columns when they are linearly independent, so its average leverage is \((k+1)/n\). The average is a property of the model's design, not an individual-observation cutoff for declaring a case unusual.

Simple Linear Regression: A Direct Formula

In simple linear regression with an intercept and one quantitative predictor \(x\), the leverage can be calculated without constructing the full hat matrix. Define \(\bar{x}\) as the sample mean of the predictor values and \(S_{xx}=\sum_{j=1}^{n}(x_j-\bar{x})^2\). Provided the predictor is not constant, the formula is

$$ h_{ii}=\frac{1}{n}+\frac{(x_i-\bar{x})^2}{S_{xx}}. $$

To see why, the OLS fitted value at \(x_i\) is \(\hat{y}_i=\bar{y}+(x_i-\bar{x})\sum_{j=1}^{n}(x_j-\bar{x})(y_j-\bar{y})/S_{xx}\). Since \(\bar{y}=(1/n)\sum_j y_j\), the coefficient of \(y_i\) in the first term is \(1/n\). In the second term, the coefficient of \(y_i\) is \((x_i-\bar{x})^2/S_{xx}\); subtracting \(\bar{y}\) does not change that coefficient because \(\sum_j(x_j-\bar{x})=0\). But \(\hat{y}_i=\sum_j h_{ij}y_j\), so the coefficient of \(y_i\) is precisely \(h_{ii}\). Adding the two contributions yields the formula.

The formula shows that observations at the predictor mean have leverage \(1/n\), while observations farther from the mean have larger leverage. It also makes clear that the response values \(y_j\) do not enter the calculation.

Worked Example: Leverage in a Small Simple Regression

Suppose a hypothetical dataset has predictor values \(x=1,2,3,4,5\), measured in hours of practice. The model includes an intercept and a linear predictor. Find each hat value and check their sum and average.

There are \(n=5\) observations and \(m=2\) design columns: the intercept and practice hours. The predictor mean is \(\bar{x}=(1+2+3+4+5)/5=3\), and

$$ S_{xx}=(1-3)^2+(2-3)^2+(3-3)^2+(4-3)^2+(5-3)^2=10. $$

Using \(h_{ii}=1/n+(x_i-\bar{x})^2/S_{xx}\), the leverage values are

$$ \begin{aligned} x_1=1:\quad h_{11}&=\frac{1}{5}+\frac{(1-3)^2}{10}=0.2+0.4=0.6,\\ x_2=2:\quad h_{22}&=\frac{1}{5}+\frac{(2-3)^2}{10}=0.2+0.1=0.3,\\ x_3=3:\quad h_{33}&=\frac{1}{5}+\frac{(3-3)^2}{10}=0.2,\\ x_4=4:\quad h_{44}&=\frac{1}{5}+\frac{(4-3)^2}{10}=0.2+0.1=0.3,\\ x_5=5:\quad h_{55}&=\frac{1}{5}+\frac{(5-3)^2}{10}=0.2+0.4=0.6. \end{aligned} $$

The sum is \(0.6+0.3+0.2+0.3+0.6=2\), equal to \(m=2\). The average is \(2/5=0.4\), which also equals \(m/n\). The two observations at the extremes of the practice-hour range have the greatest leverage in this design; the observation at the predictor mean has the least.

Calculating Leverage in Other Designs

With more than one predictor, the simple-regression shortcut does not apply in general. For a row vector \(x_i'\) containing the predictor values for observation \(i\), including a one if there is an intercept, the diagonal entry can be written

$$ h_{ii}=x_i'(X'X)^{-1}x_i. $$

This expression follows by taking the \(i\)th diagonal entry of \(X(X'X)^{-1}X'\). It provides a direct route to calculation when the design columns are manageable.

Worked Example: An Intercept-Only Model

A hypothetical model uses the mean response for four observations and has no predictors other than its intercept. Find the hat values. The design matrix is a column of four ones, so \(n=4\), \(m=1\), and \(X'X=4\).

$$ H=X(X'X)^{-1}X' =\begin{pmatrix}1\\1\\1\\1\end{pmatrix} \frac{1}{4} \begin{pmatrix}1&1&1&1\end{pmatrix} =\frac{1}{4} \begin{pmatrix} 1&1&1&1\\ 1&1&1&1\\ 1&1&1&1\\ 1&1&1&1 \end{pmatrix}. $$

Every diagonal entry is \(h_{ii}=0.25\). The sum is \(4(0.25)=1=m\), and the average is \(1/4=m/n\). Since the model has no varying predictor, all observations have the same leverage.

Worked Example: Two Predictors in a Small Design

Consider a hypothetical dataset of four observations with two predictors, \(x\) and \(z\), and an intercept. The predictor pairs are \((-1,-1),(-1,1),(1,-1),(1,1)\). Compute the hat values.

The design matrix has columns for the intercept, \(x\), and \(z\):

$$ X= \begin{pmatrix} 1&-1&-1\\ 1&-1&1\\ 1&1&-1\\ 1&1&1 \end{pmatrix}, \qquad X'X= \begin{pmatrix} 4&0&0\\ 0&4&0\\ 0&0&4 \end{pmatrix}. $$

Thus \((X'X)^{-1}\) is a diagonal matrix with \(1/4\) in each diagonal position. For every row \(x_i'=(1,x_i,z_i)\), both predictor entries have square one, so

$$ h_{ii}=x_i'(X'X)^{-1}x_i =\frac{1^2+x_i^2+z_i^2}{4} =\frac{1+1+1}{4} =0.75. $$

All four hat values equal \(0.75\). They sum to \(4(0.75)=3\), the number \(m=3\) of design columns, and their average is \(3/4\). This example also illustrates that adding predictors increases the average leverage when \(n\) is held fixed, because the model has more design columns to estimate.

How to Use Hat Values Carefully

Leverage describes the predictor position of an observation relative to the design used to fit the model. Because \(H\) is determined by \(X\), changing a response while holding all predictors fixed leaves every hat value unchanged. Conversely, changing the predictor data or the model's set of predictors can change the hat values, even if the responses remain the same.

A frequent mistake is to reason, “This observation has a high hat value, so it must be an outlier or must strongly influence the fitted regression.” That conclusion does not follow. A hat value is not a measure of residual size: it contains no response information. Nor does leverage alone establish how much a fitted model would change if an observation were removed. Those questions require other diagnostics. The safe conclusion is narrower: the observation has relatively high leverage within this particular predictor design.

Hat values are useful as a screening description, not as a stand-alone verdict. The range and average offer checks: a computed value outside \([0,1]\), or a sum that differs from the number of independent design columns beyond rounding, signals a calculation or setup problem. But the average \(m/n\) is not a universal threshold for identifying cases that deserve concern. Interpret any particular value in light of the model and the predictor data.

Key takeaway: In full-rank OLS, \(h_{ii}\) is the \(i\)th diagonal entry of \(H\), depends only on the design matrix, lies between zero and one, and contributes to a total leverage of \(m\). With an intercept and one predictor, \(h_{ii}=1/n+(x_i-\bar{x})^2/S_{xx}\).

Check Your Understanding

Use the definitions and results above to answer the following questions.

  1. A full-rank model has an intercept and three predictors, with \(n=20\). How many design columns does it have, and what is the average hat value?
  2. In simple linear regression with an intercept, why does an observation at \(x_i=\bar{x}\) have leverage \(1/n\)?
  3. For a full-rank design with \(m=4\), what must the sum of the diagonal hat values equal?
  4. Two observations have the same predictor data across the design columns but different observed responses. Must their hat values differ? Explain.
  5. Why is it incorrect to conclude from a high hat value alone that an observation is an outlier in its response?