Residuals & Goodness of Fit (R-squared)
How far off is the line at each point — and how much of the story does it actually explain?
The leftover the line couldn't reach
You fit a straight line through a scatter of points. Almost none of the points land exactly on it — each one sits a little above or below. That vertical gap, from the point down (or up) to the line, is the residual.
Think of the line as the model's best guess and the residual as its miss. A point above the line has a positive residual (the line under-predicted); a point below has a negative one. Residuals are the raw material for answering two questions: was a straight line even the right shape, and how much of the pattern did it capture?
The residual plot: a report card for the line
Here is the trick that makes residuals so useful. Instead of eyeballing the scatterplot, plot the residuals themselves against x. If the line captured the real trend, the leftovers should be pure noise — scattered randomly above and below zero with no pattern.
A pattern in the residuals is the line confessing that it missed something:
- A curve (residuals swoop down then up, or up then down) means the true relationship bends — a straight line is the wrong shape.
- A funnel (residuals fan out, small on one side and large on the other) means the scatter around the line grows as x grows — the spread is not constant.
R-squared: how much of the variation the line explains
SSE tells you the leftover error, but leftover compared to what? Compare it to how much y varied in the first place. Before drawing any line, the total spread in y is the sum of squared distances from the mean \( \bar{y} \); call it SST (total variation). The line removes some of that; whatever is left is the SSE.
The fraction of the variation the line explains is what remains after you subtract the leftover share:
- Predict at each x with \( \hat{y} = 2 + 3x \): at x = 1, 2, 3, 4 the line gives \( \hat{y} = 5, 8, 11, 14 \).
- Residual = observed − predicted: \( 6-5=+1 \), \( 7-8=-1 \), \( 12-11=+1 \), \( 13-14=-1 \). The signs alternate and sum to zero, as residuals from a least-squares line always do.
- SSE = sum of squared residuals \( = 1^2 + (-1)^2 + 1^2 + (-1)^2 = 4 \).
- Total variation SST uses the mean \( \bar{y} = (6+7+12+13)/4 = 9.5 \): deviations are \( -3.5, -2.5, 2.5, 3.5 \), so \( \text{SST} = 12.25 + 6.25 + 6.25 + 12.25 = 37 \).
- \( r^2 = 1 - \text{SSE}/\text{SST} = 1 - 4/37 \approx 0.89 \).
Check your understanding
- A residual is observed minus predicted, e = y − ŷ: positive above the line, negative below.
- A residual plot is the fit's report card — a patternless band means a straight line fits; a curve means the wrong shape and a funnel means non-constant spread.
- SSE, the sum of squared residuals, is the total squared miss that the least-squares line makes as small as possible.
- r² = 1 − SSE/SST is the fraction of the variation in y explained by the line, running from 0 to 1.
- For a simple linear fit r² is just the correlation r squared, so it ignores sign — and it measures linear fit only, never causation.