Sub topic 12
Outliers, leverage and Cook's distance
This chapter assumes you can read a multiple regression output and know what the residual, the standard error and the t-statistic mean. It also assumes you know the earlier chapters' vocabulary: partial slope, R-squared and misspecification. Here you learn how to find the few observations that can change a fitted model on their own, and how to decide what to do about them.
Why a handful of points can matter
Ordinary least squares (OLS) chooses coefficients that minimize the sum of squared residuals. Squaring makes a large residual very costly, so the fitted plane is pulled toward points that sit far from the pattern. A single odd observation can then change a slope, flip its sign, or turn a significant coefficient into an insignificant one.
Analysts care for three reasons:
- The coefficients you report may describe one data point rather than the relationship in the other observations.
- The t-tests and F-test rest on those coefficients and on the residual variance, so the inference is distorted too.
- An unusual point is sometimes a data error (a misplaced decimal, a wrong ticker). Sometimes it is the most informative event in the sample, such as a crisis month. The two cases call for different responses.
Three different ideas
People often use "outlier" for everything. The three terms below describe different things and should be kept apart.
| Term | What is unusual | Where it shows up | Typical diagnostic |
|---|---|---|---|
| Outlier | The dependent variable, given the X values: a large residual | Vertical distance from the fitted plane | Studentized residual |
| High-leverage point | The independent variables: far from the center of the X data | Horizontal distance in X space | Leverage `h_ii` |
| Influential observation | Removing it changes the fitted model materially | Change in coefficients or fitted values | Cook's distance |
A point can be an outlier without high leverage. It then has a large residual but sits near the middle of the X data, so it moves the intercept a little and the slopes hardly at all. A point can also have high leverage without being an outlier. If it lies close to the fitted plane, it extends the range of X and can even improve precision. The dangerous case is a point that has both a large residual and high leverage. Influence is roughly the product of the two.
Leverage
Leverage measures how much an observation's own Y value determines its own fitted value. For observation i it is the diagonal element h_ii of the hat matrix, which is the matrix that turns observed Y values into fitted Y values. You do not need to compute that matrix by hand to use the result.
Key properties:
h_iilies between 0 and 1.- The leverages sum to
k + 1, wherekis the number of independent variables and the extra one is the intercept. The average leverage is therefore(k + 1) / n. - A common rule of thumb flags an observation when
h_ii > 3 * (k + 1) / n, which is three times the average.
With n = 50 and k = 2, the average leverage is 3 / 50 = 0.06, and the flag threshold is 0.18. An observation with leverage 0.30 has a lot of say in where the plane goes.
Studentized residuals
A raw residual e_i is hard to judge because its scale depends on the units of Y. It is also misleading because high-leverage points pull the plane toward themselves and so tend to have small residuals. The studentized residual fixes both problems. In the common deleted version, you refit the model without observation i, predict i, and divide the prediction error by its estimated standard deviation.
Under the model assumptions, this statistic follows a t-distribution with n - k - 2 degrees of freedom. The usual rule of thumb treats an absolute value above about 3 as a likely outlier. You can also compare it with the critical t-value at your chosen significance level. With many observations, a few values above 2 are expected by chance, so a value of 2.3 in a sample of 500 is not alarming.
Cook's distance
Cook's distance, D_i, combines residual size and leverage into one number. It measures how much all the fitted values shift when observation i is left out:
D_i = (e_i^2 / ((k + 1) * MSE)) * (h_ii / (1 - h_ii)^2)
Here MSE is the mean squared error of the full model. The first factor grows with the residual. The second factor grows quickly as leverage approaches 1.
A worked example: suppose k = 2, e_i = -2.0, MSE = 1.0 and h_ii = 0.20.
- The residual factor is
4.0 / (3 * 1.0) = 1.3333. - The leverage factor is
0.20 / (0.80^2) = 0.20 / 0.64 = 0.3125. - So
D_i = 1.3333 * 0.3125 = 0.4167.
Rules of thumb for judging D_i differ by source:
- A value above about 0.5 deserves a look, and a value above 1 is very likely influential.
- The CFA curriculum also cites
sqrt(k / n)as a cutoff. Withn = 50andk = 2that issqrt(0.04) = 0.20, so the example above (0.4167) would be flagged. - Many practitioners use
4 / ninstead, which is0.08here.
These are screening devices, not tests. A flagged point tells you where to look, and it does not tell you the point is wrong.
A diagnostic workflow
Running the diagnostics in Python
The code below simulates a clean relationship, then plants one observation that is extreme in X and far off the pattern in Y. It computes the three diagnostics, flags observations with the cutoffs above, and refits without the flagged point to show the effect.
import numpy as np
import statsmodels.api as sm
rng = np.random.default_rng(7)
n, k = 50, 2
x1 = rng.normal(size=n)
x2 = rng.normal(size=n)
y = 1.0 + 2.0 * x1 - 1.0 * x2 + rng.normal(scale=0.5, size=n)
# Plant one point: extreme in X space and far from the fitted pattern in Y
x1[0], x2[0], y[0] = 4.0, -3.0, -10.0
X = sm.add_constant(np.column_stack([x1, x2]))
fit = sm.OLS(y, X).fit()
infl = fit.get_influence()
leverage = infl.hat_matrix_diag
stud = infl.resid_studentized_external
cooks = infl.cooks_distance[0]
lev_cut = 3 * (k + 1) / n
cook_cut = np.sqrt(k / n)
flagged = np.where(
(leverage > lev_cut) | (np.abs(stud) > 3) | (cooks > cook_cut)
)[0]
print("Leverage cutoff:", round(lev_cut, 3), " Cook cutoff:", round(cook_cut, 3))
for i in flagged:
print(i, "leverage", round(leverage[i], 3),
"studentized", round(stud[i], 2),
"Cook", round(cooks[i], 3))
keep = np.ones(n, dtype=bool)
keep[0] = False
fit_without = sm.OLS(y[keep], X[keep]).fit()
print("With all points: ", fit.params.round(3))
print("Without point 0: ", fit_without.params.round(3))
print("t-values with: ", fit.tvalues.round(2))
print("t-values without: ", fit_without.tvalues.round(2))Read the output in three steps:
- Point 0 should be flagged by all three diagnostics. It has high leverage because it sits far from the center of X. It has a large studentized residual because its Y value contradicts the pattern. Its Cook's distance combines the two.
- Compare the two coefficient rows. The slopes with the point included should be visibly pulled away from the true values of 2 and -1. Without it, they should sit close to those values.
- Compare the t-values. A single point can change the standard errors and the residual variance as well as the slopes, so the significance conclusions can move.
The other flagged points, if any, will have small values. A few extra flags are normal, because the leverage cutoff applies to every observation and some will exceed it by chance.
What to do with a flagged observation
The decision should come from the data's meaning, not from the desire to get a nicer fit.
- Check for an error. Look at the raw record. A return of 250% for a large-cap stock in one month is probably a data problem. Correct it, or remove it if you cannot correct it, and document that.
- Check whether it is a legitimate extreme. A market crash or a merger is a real event. Deleting it makes the model look better and understates risk. If it is real and influential, keep it and say so.
- Compare results with and without it. Report both when they differ. This is the most defensible practice.
- Look for a modelling cause. A cluster of large residuals can point to an omitted variable, a nonlinear relationship, or two regimes pooled into one sample. These are the misspecification problems covered earlier in this tutorial. In that case the fix is a better model, not removing points.
- Consider alternatives. A dummy variable for one event period lets that event have its own intercept without distorting the other slopes. Robust regression methods reduce the weight of extreme residuals automatically. Winsorizing, which caps values at a chosen percentile, is another option, but it changes the data, so state it clearly.
Common errors
- Treating "outlier" and "influential" as the same. A large residual alone does not make a point influential. Check leverage and Cook's distance.
- Using raw residuals to find outliers. High-leverage points often have small raw residuals because they drag the fit toward themselves. Use studentized residuals.
- Applying cutoffs mechanically. In a large sample, many points exceed
3 * (k + 1) / nby chance. Look at how far above the cutoff a point is and whether it stands apart from the rest. - Ignoring leverage when it is high but the residual is small. Such a point is not harmful now, but the estimates rest heavily on one observation. If it has an error, the whole fit is affected.
- Confusing this with heteroskedasticity. Heteroskedasticity is a pattern in the residual variance across many observations. Influence is about individual observations. The two can occur together, and a few extreme points can create a false signal in a Breusch-Pagan test.
Exercise
A regression has n = 80 and k = 3. One observation has leverage 0.15, a studentized residual of 1.1 and a Cook's distance of 0.04. Using the rule of thumb 3(k + 1)/n for leverage and sqrt(k/n) for Cook's distance, is the observation flagged by either diagnostic? What does the pattern tell you about it?
Show answer
The leverage cutoff is 3 * 4 / 80 = 0.15. The observation's leverage of 0.15 sits right at the cutoff and is not above it, so it is borderline and not clearly flagged. The Cook's distance cutoff is sqrt(3 / 80) = sqrt(0.0375) = 0.194, and 0.04 is well below it. The studentized residual of 1.1 is not an outlier. So the point is unusual in X space but fits the pattern, and it is not influential. It does not need to be removed, though it is worth confirming its X values are correct.
Exercise
You compute Cook's distance for an observation with k = 2, residual e = 1.5, MSE = 0.75 and leverage 0.40. Calculate D, and say whether it exceeds the cutoff 0.5 and the cutoff 1.
Show answer
The residual factor is e^2 / ((k + 1) MSE) = 2.25 / (3 0.75) = 1.0. The leverage factor is 0.40 / (0.60^2) = 0.40 / 0.36 = 1.1111. So D = 1.0 * 1.1111 = 1.1111. This exceeds 0.5 and also exceeds 1, so the observation is very likely influential. Next steps: check the data, then refit without the point and compare coefficients.
Exercise
An analyst finds that three months of extreme returns in 2008 are influential, and deletes them because the model's R-squared rises from 0.41 to 0.58. What is wrong with this approach, and what should the analyst do instead?
Show answer
The 2008 months are genuine observations, not data errors, and they are deleted only because they make the fit worse. The higher R-squared is a result of removing the hard cases, so it overstates how well the model would work in a similar period. The analyst should keep the observations, report results with and without them, and consider whether the relationship changes in crisis periods. A dummy variable for the crisis months or a regime-specific model is a better response than deletion.