R-squared, Residual Error and Residual Plots
Split variation into explained and unexplained parts, compute R-squared and the residual standard error, and use residual plots to judge whether a line fits.
Welcome back!
Step 1 of 12Learn
Same slope, very different usefulness
Two analysts each fit a regression with a slope of 1.2. In the first dataset, points hug the line tightly: predictions are rarely off by more than half a unit. In the second, points scatter widely: predictions are often off by 5 units. Same slope, but only the first model is useful for prediction.
So beyond the line itself, you need measures of fit: how much of the variation in y the line accounts for, and how far off its predictions typically are. You also need a way to check whether a straight line is even the right shape.
This lesson covers three tools:
- R², the share of variation in y explained by the model.
- The residual standard error, the typical size of a prediction error, in the units of y.
- Residual plots, which reveal curves, changing spread and unusual points that summary numbers hide.
These tools answer different questions. R² says how much better the line does than simply predicting the average for everyone. The residual standard error says how precise individual predictions are. Residual plots say whether the model's assumptions look reasonable. A complete regression report includes all three, because a model can score well on one and badly on another.
Step 2 of 12Learn
Splitting variation: SST, SSR and SSE
Start with the simplest possible prediction: ignore x and predict ȳ for everyone. The total squared error of that baseline is the total sum of squares:
SST = Σ(y − ȳ)²
The regression line does better. Its leftover error is the sum of squared errors, SSE = Σ(y − ŷ)². The improvement, the part of the variation the line accounts for, is the regression sum of squares, SSR = Σ(ŷ − ȳ)². For least squares these always add up:
SST = SSR + SSE
R², the coefficient of determination, is the share of total variation explained:
R² = SSR / SST = 1 − SSE / SST
For the five students: SST = Σ(y − 5.4)² = 17.2 and SSE = 2.8, so R² = 1 − 2.8 / 17.2 ≈ 0.84. Practice hours explain about 84% of the variation in quiz scores in this tiny sample; 16% is left unexplained.
In simple linear regression, R² is exactly the square of the correlation: 0.915² ≈ 0.84. R² ranges from 0 (the line is no better than predicting the mean) to 1 (every point is on the line). It has no units, so it can be compared across models for the same response, but not across different responses.
Step 3 of 12Chart
Splitting SST = 17.2 for the five students
| Item | Sum of squares |
|---|---|
| Explained by the line (SSR) | 14.4 |
| Left over (SSE) | 2.8 |
Step 4 of 12Try the calculator
R² and residual standard error
Enter the sums of squares and the number of observations. The defaults are the five-student example.
- R²
- 0.837
- SSR (explained)
- 14.4
- Residual standard error
- 0.966
Step 5 of 12Practice · Work it out
A regression has SSE = 300 and SST = 1,200. What is R²? Give your answer as a decimal.
Step 6 of 12Learn
The residual standard error: typical prediction error
R² is a proportion. Decision-makers often care more about a number in real units: how far off will a prediction typically be? That is the residual standard error (also called the standard error of the regression, or s_e):
s_e = √( SSE / (n − 2) )
It is essentially the standard deviation of the residuals. The divisor is n − 2 rather than n − 1 because two quantities, the slope and the intercept, were estimated from the data.
For the five students, s_e = √(2.8 / 3) ≈ 0.97 points: predictions are typically off by about one point. If residuals are roughly normal, about 95% of points lie within 2 × s_e of the line, so most actual scores should be within about ±2 points of the prediction.
The two measures complement each other. A model predicting house prices might have R² = 0.85, which sounds excellent, and s_e = $45,000, which might be too imprecise for an appraisal. A model of daily temperature might have R² = 0.3 but s_e = 1.5 °C, perfectly usable. Whether a model is good enough depends on how precise predictions need to be for the decision at hand, and s_e answers that more directly than R².
Step 7 of 12Learn
Residual plots: let the leftovers talk
A residual plot shows the residuals on the y-axis against the predicted values (or against x) on the x-axis, with a horizontal line at zero. If the linear model is appropriate, the plot should look like a shapeless horizontal band of points scattered evenly above and below zero.
Patterns mean trouble:
- A curve (residuals positive at both ends and negative in the middle, or the reverse): the relationship isn't linear. A straight line systematically misses. Consider a transformation or a curved term.
- A funnel (spread growing with the predicted value): the variability of y changes with x, called heteroscedasticity. It is very common with money: errors in predicting the price of a $2 million house are larger than for a $200,000 house. Standard errors and prediction intervals become unreliable; a log transformation often helps.
- Isolated points far from zero: outliers the model fits poorly. Investigate them.
- Patterns over time (when data is ordered in time): residuals that stay positive for a while and then negative suggest the observations aren't independent.
The residual plot often reveals problems invisible in the original scatterplot, because removing the main trend magnifies what's left. Make one for every regression you fit; it takes seconds.
Step 8 of 12Practice · Chart
A residual plot with a warning sign
Tap the point where the line overpredicts the most.
Tap the point that answers the question, then press Check.
| Point | Predicted value | Residual |
|---|---|---|
| A | 2 | 2.1 |
| B | 3 | 0.8 |
| C | 4 | -0.4 |
| D | 5 | -1.2 |
| E | 6 | -1.6 |
| F | 7 | -1.1 |
| G | 8 | -0.3 |
| H | 9 | 0.9 |
| I | 10 | 2.2 |
Step 9 of 12Practice · Match the pairs
Match each residual plot pattern to the problem it signals.
Tap an answer, then tap the place where it belongs (or drag it there).
- A U-shaped curve of residuals
- Residuals fan out as predicted values grow
- A random horizontal band around zero
- Long runs of positive then negative residuals in time order
Step 10 of 12Note
Step 11 of 12Practice · True or false
In a simple linear regression, a correlation of r = −0.6 means the line explains 36% of the variation in y.
Step 12 of 12Practice · Choose one
A model predicting delivery times has R² = 0.62 and a residual standard error of 4 minutes. Which statement is correct?
Lesson complete!