Drag, add or remove points and watch the least-squares line, SSE and R² update. Turn on the squared residuals to see what the line minimizes, try to beat it with your own line, then use the diagnostics to find the points that move the slope.
← All labsBased on Chapter 12, Linear Regression, of Polson and Sokolov, Bayes, Artificial Intelligence, and Deep Learning (vsokolov.org/html/_book).
Should look like random scatter around zero. A curve means the line is the wrong shape.
Red dashed contours mark Cook's D = 0.5 and 1. Points outside them are influential.
Combines residual size and leverage. Investigate D > 0.5; D > 1 is a strong warning.
The table lists the most influential points first. Click a row to highlight that point everywhere. "Drop" removes it and leaves the old line on the plot for comparison.
| Point | x | y | Fitted ŷ | Residual e | Leverage h | Std. resid r | Cook's D | β̂₁ without it |
|---|
Leavitt's 25 pulsating stars made the point first: least squares minimizes the average squared error, and any other rule on the same data fits visibly worse. The demos below load classic diagnostic cases.
Each residual eᵢ = yᵢ − ŷᵢ is the vertical miss at one point. Turn on the squares: each square's side is a residual, so its area is eᵢ². Least squares moves the line until the total area SSE is as small as possible. Any line you draw has a larger SSE.
Because β̂₀ = ȳ − β̂₁x̄, the line pivots around the point of means. The slope is the correlation rescaled into the right units, β̂₁ = rxy · sy / sx.
A point far from x̄ has high leverage hᵢ. It can pull the line toward itself, so its own residual can look small. Cook's distance multiplies the squared standardized residual by hᵢ/(1 − hᵢ). In the cigarettes data, country K plays the role of the United States in the classic data: removing it changes the slope a lot, but the slope stays positive.
On the raw scale a few giant mammals dominate and the residuals are huge and uneven. On the log–log scale the cloud is a straight band and the slope is an elasticity. The reference fit is log(Brain) = 2.18 + 0.74 log(Body): a 1% heavier body goes with a 0.74% heavier brain.
On the log scale the largest standardized residual belongs to the chinchilla, entered as 64 g instead of 6.4 g. Press "Fix the typo" and the only big outlier left is the human.
Takeaway for students. A regression without a look at its residuals is half a regression. Before you report a slope, check which points drive it, refit without them, and see whether the conclusion survives.
For each X, the Y values are normal, their means lie on the line, σ is the same at every X, and the observations are independent.
The Saratoga fit gives β̂₀ = 13.44 and β̂₁ = 0.11, in thousands of dollars per square foot. Each extra square foot adds about $110.