Week 02 · Linear regression and influential observations
Measure how one high-leverage point changes the fitted slope.
← Week 1 · Subject contents · Week 3 →
Measure how one high-leverage point changes the fitted slope.
Work through the problem
For a line with intercept, least squares gives slope Σ(xᵢ−x̄)(yᵢ−ȳ)/Σ(xᵢ−x̄)². An input far from x̄ contributes a large squared term to the denominator. Its potential to change the fit is called leverage.
The three points (0,0), (1,1), and (2,2) give slope 1. Add (8,0): x̄ = 2.75, ȳ = 0.75, and the numerator becomes 5−11×0.75 = −3.25. The denominator is 69−4×2.75² = 38.75. The slope changes sign. Check whether that observation is a data error, a different regime, or a valid observation before deciding what to do.
One distant point reverses the slope.
Run the Python lab
import numpy as np
x, y = np.array([0,1,2,8]), np.array([0,1,2,0])
lines = {}
for label, take in [("All points",slice(None)), ("Without x=8",slice(3))]:
w = np.polyfit(x[take],y[take],1)
lines[label] = np.polyval(w,x)
print(label, w.round(3))
assert abs(np.polyfit(x,y,1)[0] - (-3.25/38.75)) < 1e-9
Output from the lab
All points [-0.084 0.981]
Without x=8 [1. 0.]
Practice
- Is high leverage the same as a large residual?
Check your reasoning
- No. Leverage depends on the inputs. A distant point can lie on the fitted line and have a small residual.