# Leverage (statistics)

In statistics and in particular in regression analysis, leverage is a measure of how far away the independent variable values of an observation are from those of the other observations. High-leverage points, if any, are outliers with respect to the independent variables. That is, high-leverage points have no neighboring points in $\mathbb {R} ^{p}$ space, where ${p}$ is the number of independent variables in a regression model. This makes the fitted model likely to pass close to a high leverage observation. Hence high-leverage points have the potential to cause large changes in the parameter estimates when they are deleted i.e., to be influential points. Although an influential point will typically have high leverage, a high leverage point is not necessarily an influential point. The leverage is typically defined as the diagonal elements of the hat matrix.

## Definition and interpretations

Consider the linear regression model ${y}_{i}={\boldsymbol {x}}_{i}^{\top }{\boldsymbol {\beta }}+{\varepsilon }_{i}$, $i=1,\,2,\ldots ,\,n$. That is, ${\boldsymbol {y}}=\mathbf {X} {\boldsymbol {\beta }}+{\boldsymbol {\varepsilon }}$, where, $\mathbf {X}$ is the $n\times p$ design matrix whose rows correspond to the observations and whose columns correspond to the independent or explanatory variables. The leverage score for the ${i}^{th}$ independent observation ${\boldsymbol {x}}_{i}$ is given as:
    $h_{ii}=\left[\mathbf {H} \right]_{ii}={\boldsymbol {x}}_{i}^{\top }\left(\mathbf {X} ^{\top }\mathbf {X} \right)^{-1}{\boldsymbol {x}}_{i}$, the ${i}^{th}$ diagonal element of the ortho-projection matrix (a.k.a hat matrix) $\mathbf {H} =\mathbf {X} \left(\mathbf {X} ^{\top }\mathbf {X} \right)^{-1}\mathbf {X} ^{\top }$.
Thus the ${i}^{th}$ leverage score can be viewed as the 'weighted' distance between ${\boldsymbol {x}}_{i}$ to the mean of ${\boldsymbol {x}}_{i}$'s (see its relation with Mahalanobis distance). It can also be interpreted as the degree by which the ${i}^{th}$ measured (dependent) value (i.e., $y_{i}$) influences the ${i}^{th}$ fitted (predicted) value (i.e., ${\widehat {y\,}}_{i}$): mathematically,
    $h_{ii}={\frac {\partial {\widehat {y\,}}_{i}}{\partial y_{i}}}$.
Hence, the leverage score is also known as the observation self-sensitivity or self-influence. Using the fact that ${\boldsymbol {\widehat {y}}}={\mathbf {H} }{\boldsymbol {y}}$ (i.e., the prediction ${\boldsymbol {\widehat {y}}}$ is ortho-projection of ${\boldsymbol {y}}$ onto range space of $\mathbf {X}$) in the above expression, we get $h_{ii}=\left[\mathbf {H} \right]_{ii}$. Note that this leverage depends on the values of the explanatory variables $(\mathbf {X} )$ of all observations but not on any of the values of the dependent variables $(y_{i})$.

## Properties

* The leverage $h_{ii}$ is a number between 0 and 1, $0\leq h_{ii}\leq 1.$ Proof: Note that $\mathbf {H}$ is idempotent matrix ($\mathbf {H} ^{2}=\mathbf {H}$) and symmetric ($h_{ij}=h_{ji}$). Thus, by using the fact that $\left[\mathbf {H} ^{2}\right]_{ii}=\left[\mathbf {H} \right]_{ii}$, we have $h_{ii}=h_{ii}^{2}+\sum _{j\neq i}h_{ij}^{2}$. Since we know that $\sum _{j\neq i}h_{ij}^{2}\geq 0$, we have $h_{ii}\geq h_{ii}^{2}\implies 0\leq h_{ii}\leq 1$.
* Sum of leverages is equal to the number of parameters $(p)$ in ${\boldsymbol {\beta }}$ (including the intercept). Proof: $\sum _{i=1}^{n}h_{ii}=\operatorname {Tr} (\mathbf {H} )=\operatorname {Tr} \left(\mathbf {X} \left(\mathbf {X} ^{\top }\mathbf {X} \right)^{-1}\mathbf {X} ^{\top }\right)=\operatorname {Tr} \left(\mathbf {X} ^{\top }\mathbf {X} \left(\mathbf {X} ^{\top }\mathbf {X} \right)^{-1}\right)=\operatorname {Tr} (\mathbf {I} _{p})=p$.

## Determination of outliers in X using leverages

Large leverage ${h_{ii}}$ corresponds to an ${{\boldsymbol {x}}_{i}}$ that is extreme. A common rule is to identify ${{\boldsymbol {x}}_{i}}$ whose leverage value ${h}_{ii}$ is more than 2 times larger than the mean leverage ${\bar {h}}={\dfrac {1}{n}}\sum _{i=1}^{n}h_{ii}={\dfrac {p}{n}}$ (see property 2 above). That is, if $h_{ii}>2{\dfrac {p}{n}}$, ${{\boldsymbol {x}}_{i}}$ shall be considered an outlier. Some statisticians prefer the threshold of $3p/{n}$ instead of $2p/{n}$.

## Relation to Mahalanobis distance

Leverage is closely related to the Mahalanobis distance (proof). Specifically, for some $n\times p$ matrix $\mathbf {X}$, the squared Mahalanobis distance of ${{\boldsymbol {x}}_{i}}$ (where ${\boldsymbol {x}}_{i}^{\top }$ is ${i}^{th}$ row of $\mathbf {X}$) from the vector of mean ${\widehat {\boldsymbol {\mu }}}=\sum _{i=1}^{n}{\boldsymbol {x}}_{i}$ of length $p$, is $D^{2}({\boldsymbol {x}}_{i})=({\boldsymbol {x}}_{i}-{\widehat {\boldsymbol {\mu }}})^{\top }\mathbf {S} ^{-1}({\boldsymbol {x}}_{i}-{\widehat {\boldsymbol {\mu }}})$, where $\mathbf {S} =\mathbf {X} ^{\top }\mathbf {X}$ is the estimated covariance matrix of ${{\boldsymbol {x}}_{i}}$'s. This is related to the leverage $h_{ii}$ of the hat matrix of $\mathbf {X}$ after appending a column vector of 1's to it. The relationship between the two is:
    $D^{2}({\boldsymbol {x}}_{i})=(n-1)(h_{ii}-{\tfrac {1}{n}})$
This relationship enables us to decompose leverage into meaningful components so that some sources of high leverage can be investigated analytically.

## Relation to influence functions

In a regression context, we combine leverage and influence functions to compute the degree to which estimated coefficients would change if we removed a single data point. Denoting the regression residuals as ${\widehat {e}}_{i}=y_{i}-{\boldsymbol {x}}_{i}^{\top }{\widehat {\boldsymbol {\beta }}}$ , one can compare the estimated coefficient ${\widehat {\boldsymbol {\beta }}}$ to the leave-one-out estimated coefficient ${\widehat {\boldsymbol {\beta }}}^{(-i)}$ using the formula
    ${\widehat {\boldsymbol {\beta }}}-{\widehat {\boldsymbol {\beta }}}^{(-i)}={\frac {(\mathbf {X} ^{\top }\mathbf {X} )^{-1}{\boldsymbol {x}}_{i}{\widehat {e}}_{i}}{1-h_{ii}}}$
Young (2019) uses a version of this formula after residualizing controls. To gain intuition for this formula, note that ${\frac {\partial {\hat {\beta }}}{\partial y_{i}}}=(\mathbf {X} ^{\top }\mathbf {X} )^{-1}{\boldsymbol {x}}_{i}$ captures the potential for an observation to affect the regression parameters, and therefore $(\mathbf {X} ^{\top }\mathbf {X} )^{-1}{\boldsymbol {x}}_{i}{\widehat {e}}_{i}$ captures the actual influence of that observations' deviations from its fitted value on the regression parameters. The formula then divides by $(1-h_{ii})$ to account for the fact that we remove the observation rather than adjusting its value, reflecting the fact that removal changes the distribution of covariates more when applied to high-leverage observations (i.e. with outlier covariate values). Similar formulas arise when applying general formulas for statistical influences functions in the regression context.

## Effect on residual variance

If we are in an ordinary least squares setting with fixed $\mathbf {X}$ and homoscedastic regression errors $\varepsilon _{i},$ ${\boldsymbol {y}}=\mathbf {X} {\boldsymbol {\beta }}+{\boldsymbol {\varepsilon }};\ \ \operatorname {Var} ({\boldsymbol {\varepsilon }})=\sigma ^{2}\mathbf {I}$, then the ${i}^{th}$ regression residual, $e_{i}=y_{i}-{\widehat {y}}_{i}$ has variance
    $\operatorname {Var} (e_{i})=(1-h_{ii})\sigma ^{2}$.
In other words, an observation's leverage score determines the degree of noise in the model's misprediction of that observation, with higher leverage leading to less noise. This follows from the fact that $\mathbf {I} -\mathbf {H}$ is idempotent and symmetric and ${\widehat {\boldsymbol {y}}}=\mathbf {H} {\boldsymbol {y}}$, hence, $\operatorname {Var} ({\boldsymbol {e}})=\operatorname {Var} ((\mathbf {I} -\mathbf {H} ){\boldsymbol {y}})=(\mathbf {I} -\mathbf {H} )\operatorname {Var} ({\boldsymbol {y}})(\mathbf {I} -\mathbf {H} )^{\top }=\sigma ^{2}(\mathbf {I} -\mathbf {H} )^{2}=\sigma ^{2}(\mathbf {I} -\mathbf {H} )$.
The corresponding studentized residual—the residual adjusted for its observation-specific estimated residual variance—is then
    $t_{i}={e_{i} \over {\widehat {\sigma }}{\sqrt {1-h_{ii}\ }}}$
where ${\widehat {\sigma }}$ is an appropriate estimate of $\sigma$.

## Partial leverage

Partial leverage (PL) is a measure of the contribution of the individual independent variables to the total leverage of each observation. That is, PL is a measure of how $h_{ii}$ changes as a variable is added to the regression model. It is computed as:
    $\left(\mathrm {PL} _{j}\right)_{i}={\frac {\left(\mathbf {X} _{j\bullet [j]}\right)_{i}^{2}}{\sum _{k=1}^{n}\left(\mathbf {X} _{j\bullet [j]}\right)_{k}^{2}}}$
where $j$ is the index of independent variable, $i$ is the index of observation and $\mathbf {X} _{j\bullet [j]}$ are the residuals from regressing $\mathbf {X} _{j}$ against the remaining independent variables. Note that the partial leverage is the leverage of the ${i}^{th}$ point in the partial regression plot for the ${j}^{th}$ variable. Data points with large partial leverage for an independent variable can exert undue influence on the selection of that variable in automatic regression model building procedures.

## Software implementations

Many programs and statistics packages, such as R, Python, etc., include implementations of Leverage.
| Language/Program | Function | Notes |
| R | hat(x, intercept = TRUE) or hatvalues(model, ...) | See |
| Python | (x * np.linalg.pinv(x).T).sum(-1) | See |