← Chapter 14
Statistics · Chapter 14

Fit the Least-Squares Line

The points below are fixed. Your job is the line. For any line you draw, each point misses it by a vertical gap — a residual. Square every gap, add them up, and you get the sum of squared residuals (SSR). The least-squares line is the single line that makes that total as small as it can possibly be. Tilt the slope and shift the intercept below and watch SSR fall — every square, the running total, and the fit landscape recompute the instant the line moves.

The scatterplot & your line

The fit landscape: SSR at every slope

Sum of squared residualstilt and shift the line to shrink it
1.0
72
excess over the minimum—
Your SSR—
Minimum SSR—
R² of your line—
Times the min—
Why squared, and why vertical? The gaps are measured straight up and down, because the line predicts y from x and a residual is a prediction error in y. Each gap is squared before adding, so a miss of 6 counts 4× as much as a miss of 3 — the line is pulled hardest toward the points it is furthest from, and squaring keeps positive and negative misses from cancelling. On the plot, a residual literally becomes a square whose area is that penalty; least-squares shrinks the total shaded area to the smallest it can be.
The minimum is unique — and it sits on the mean point. There is exactly one least-squares line, given by b = Σ(x−x̄)(y−ȳ) ÷ Σ(x−x̄)² and a = ȳ − b·x̄. At that line, and only there, the residuals add up to zero and the line passes through the mean point (x̄, ȳ). Snapping does the algebra for you — but sliding there by hand shows you it really is the bottom of the bowl.