Forty simulated observations from a straight-line model, one of them (observation 20) pushed far above the line, plus an optional 41st point far to the right. Grab any point on the left and drag it. The red line is the least-squares fit to all the points, the dashed blue line the fit without the point you hold, so the gap between them is that point's influence. On the right every point is placed by its leverage (how unusual its x is) and its studentized residual (how unusual its y is, given the others). A point needs both to move the line much: an outlier at an ordinary x mostly inflates the RSE, while a point at an extreme x can drag the slope.
Leverage: hi = 1/n + (xi − x̄)²/Σ(xi′ − x̄)² (3.37), between 1/n and 1 with average (p+1)/n = 2/n. Studentized residual: ei/(s(i)√(1 − hi)), where s(i) is the RSE of the fit without point i (the externally studentized residual, as R's rstudent). Cook's distance: Di = ei²/(2·RSE²) · hi/(1 − hi)². Click a point to select it; drag it with the mouse or a finger, or use the sliders.
code/ch03_linear_regression.py (outlier_data makes these data, ols returns leverages, studentized residuals and Cook's distances; see the code index).