Sub topic 12
Outliers, Leverage and Cook's Distance
Prerequisites and the main idea
Assume you know simple and multiple linear regression, residuals, standard errors, and hypothesis tests. In a fitted regression, an observation can affect the estimated coefficients more than the other observations do. Such an observation is influential.
Three related ideas help diagnose this problem:
- An outlier has an unusually large residual. Its observed dependent-variable value is far from the model's prediction.
- A high-leverage observation has unusual predictor values. It lies far from the center of the \(X\)-data.
- An influential observation changes the fitted regression noticeably when it is removed.
An observation can be an outlier without having high leverage. It can also have high leverage without being an outlier. Cook's distance combines both ideas.
Residual outliers
A residual is
\[ ei = yi - \hat y_i. \]
A large residual means that the model predicts observation \(i\) poorly. Because residual size depends on the scale of the dependent variable, analysts often use standardized or studentized residuals.
A common screening rule is:
- absolute standardized residual above 2: investigate;
- absolute standardized residual above 3: strong warning.
These are screening rules, not automatic deletion rules. A large residual may represent a data-entry error, a rare but valid event, or evidence that the model omits an important variable.
Leverage
Leverage measures how unusual an observation's predictor values are. In matrix notation, the diagonal element \(h_{ii}\) of the hat matrix measures observation \(i\)'s leverage. The hat matrix maps observed dependent-variable values to fitted values.
With \(n\) observations and \(k\) independent variables plus an intercept, average leverage is
\[ \bar h = \frac{k+1}{n}. \]
Rules such as \(h{ii} > 2(k+1)/n\) or \(h{ii} > 3(k+1)/n\) identify observations for review. These cutoffs become easier to exceed in small samples, so context matters.
High leverage is not automatically harmful. An observation may be far out in predictor space and still follow the same relationship as the other observations. In that case it can improve estimation of the slope over a wider range.
Cook's distance
Cook's distance estimates how much the fitted regression would change if observation \(i\) were removed. One common expression is
\[ Di = \frac{ei^2}{(k+1)\hat\sigma^2} \frac{h{ii}}{(1-h{ii})^2}, \]
where \(ei\) is the residual, \(h{ii}\) is leverage, and \(\hat\sigma^2\) is the estimated error variance.
Cook's distance becomes large when an observation combines a large residual with high leverage. A rough rule is to investigate \(Di > 4/n\). Some analysts use \(Di > 1\) as a stronger warning. Neither value proves that the observation should be removed.
| Diagnostic | Main question | Typical warning |
|---|---|---|
| Studentized residual | Is the prediction unusually poor? | Absolute value above 2 or 3 |
| Leverage | Are the predictors unusual? | Above \(2(k+1)/n\) or \(3(k+1)/n\) |
| Cook's distance | Would removing the observation change the fit? | Above \(4/n\), then investigate |
A practical diagnostic workflow
Use the following process:
- Check the raw data for entry, unit, and coding errors.
- Inspect the observation's context. A valid extreme observation may be economically important.
- Examine residuals, leverage, and Cook's distance together.
- Refit the model with and without the observation.
- Compare coefficients, standard errors, predictions, and conclusions.
- Report the sensitivity analysis when the result changes materially.
Do not delete an observation only because it weakens statistical significance. Deletion should have a defensible data or modeling reason.
import numpy as np
import statsmodels.api as sm
rng = np.random.default_rng(7)
x = rng.normal(size=30)
y = 2 + 3 * x + rng.normal(size=30)
x[-1], y[-1] = 4.5, -8 # unusual predictor and outcome
X = sm.add_constant(x)
fit = sm.OLS(y, X).fit()
influence = fit.get_influence()
summary = influence.summary_frame()
print(summary[["standard_resid", "hat_diag", "cooks_d"]].tail())
threshold = 4 / len(y)
print("Cook's-distance threshold:", threshold)
print("Flagged rows:", np.flatnonzero(summary["cooks_d"] > threshold))This code does not decide whether the final model is correct. It identifies observations that deserve investigation.
Exercise
An observation has a studentized residual of 0.4, leverage of 0.25, and a large Cook's distance. What should you suspect?
Show answer
Suspect that its predictor values give it high leverage and allow it to affect the fitted regression, even though its residual is not large. Check the data and compare the model with and without the observation.