Residual analysis
Check whether a straight line really suits your data with residual analysis in Year 12 VCE General Mathematics. A podcast whose audience grows faster every week can still show a high correlation, yet a straight line will miss badly at the start and the end. Residuals, the gaps between the actual and predicted values, reveal this.
You will calculate residuals as actual minus predicted, decide whether each point sits above or below the line, and use the fact that least squares residuals add to zero. Then you will build residual plots and read them: random scatter supports a linear model, while a curve signals that the data may need a transformation.
Theory
A residual measures how far each point lies from the least squares line, and a residual plot shows whether a straight line really fits. This Year 12 General Mathematics guide for students in Victoria shows how to calculate residuals, construct the plot and read it to judge a linear model.
When a least squares line \(y = a + bx\) is fitted to data, each data point has a predicted value (from the line) and an actual value (from the data). The residual is the difference: actual value minus predicted value.
A positive residual means the point lies above the line, so the line under-predicted. A negative residual means the point lies below the line, so the line over-predicted. A residual of zero means the point is on the line. For a least squares line, the residuals always add to zero.
A residual plot graphs each residual (vertical axis) against the explanatory variable (horizontal axis), with a horizontal line at zero. It is used to check the quality of fit: whether a straight line is a good model for the data.
The residual for each data point:
The predicted value comes from substituting \(x\) into the least squares line:
For a least squares line, the residuals always balance out:
Constructing and reading a residual plot
- Predict. Substitute each value of the explanatory variable into \(y = a + bx\) to get the predicted value.
- Subtract. Residual \(=\) actual \(-\) predicted. Keep the sign. As a check, the residuals should add to zero (or very close, after rounding).
- Plot. Put the explanatory variable on the horizontal axis and the residual on the vertical axis. Draw the zero line.
- Judge. Random scatter with no pattern supports a linear model. A curve or other clear pattern means the relationship is non-linear.
Find the predicted value from the line, then subtract it from the actual value.
| \(\text{predicted}\) | \(=\) | \(15 + 0.7 \times 30\) |
| \(\text{predicted}\) | \(=\) | \(15 + 21\) |
| \(\text{predicted}\) | \(=\) | \(36 \text{ L}\) |
| \(\text{residual}\) | \(=\) | \(\text{actual} - \text{predicted}\) |
| \(\text{residual}\) | \(=\) | \(35.4 - 36\) |
| \(\text{residual}\) | \(=\) | \(-0.6 \text{ L}\) |
The residual is \(-0.6\) L. It is negative, so this point lies below the line: the line over-predicted the fuel used by \(0.6\) L.
| Lessons, \(x\) | 2 | 4 | 6 | 8 | 10 | 12 |
|---|---|---|---|---|---|---|
| Time, \(y\) (s) | 37.5 | 37 | 34.5 | 29 | 28 | 23 |
For each number of lessons, the predicted time is \(42 - 1.5 \times \text{lessons}\). Then residual \(=\) actual \(-\) predicted:
| \(x\) | actual | predicted | residual |
|---|---|---|---|
| \(2\) | \(37.5\) | \(39\) | \(-1.5\) |
| \(4\) | \(37\) | \(36\) | \(1\) |
| \(6\) | \(34.5\) | \(33\) | \(1.5\) |
| \(8\) | \(29\) | \(30\) | \(-1\) |
| \(10\) | \(28\) | \(27\) | \(1\) |
| \(12\) | \(23\) | \(24\) | \(-1\) |
| \(\text{sum of residuals}\) | \(=\) | \((-1.5) + 1 + 1.5 + (-1) + 1 + (-1)\) |
| \(\text{sum of residuals}\) | \(=\) | \(0\) |
The residuals are scattered randomly above and below zero with no pattern, so the residual plot supports a linear model.
| Week, \(x\) | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Subscribers, \(y\) (hundreds) | 3 | 4 | 6 | 9 | 13 | 19 |
Predicted \(= -2 + 3.14 \times \text{week}\). Then residual \(=\) actual \(-\) predicted:
| \(x\) | actual | predicted | residual |
|---|---|---|---|
| \(1\) | \(3\) | \(1.14\) | \(1.86\) |
| \(2\) | \(4\) | \(4.28\) | \(-0.28\) |
| \(3\) | \(6\) | \(7.42\) | \(-1.42\) |
| \(4\) | \(9\) | \(10.56\) | \(-1.56\) |
| \(5\) | \(13\) | \(13.7\) | \(-0.7\) |
| \(6\) | \(19\) | \(16.84\) | \(2.16\) |
The residuals are positive, then negative, then positive again: a clear U-shaped pattern. A linear model is not appropriate, even though \(r = 0.96\) is strong. Subscribers are growing faster each week, so the relationship is non-linear.
(a) Find the fifth residual.
(b) The fifth point has \(x = 15\). Find its actual \(y\)-value.
(a) Least squares residuals add to zero. (b) Rearrange: actual \(=\) predicted \(+\) residual.
| \(1.6 + (-0.9) + 2.3 + (-2.2) + \text{residual}\) | \(=\) | \(0\) |
| \(0.8 + \text{residual}\) | \(=\) | \(0\) |
| \(\text{residual}\) | \(=\) | \(-0.8\) |
| \(\text{predicted}\) | \(=\) | \(6 + 1.4 \times 15\) |
| \(\text{predicted}\) | \(=\) | \(6 + 21\) |
| \(\text{predicted}\) | \(=\) | \(27\) |
| \(\text{actual}\) | \(=\) | \(27 + (-0.8)\) |
| \(\text{actual}\) | \(=\) | \(26.2\) |
(a) The fifth residual is \(-0.8\). (b) The actual value is \(y = 26.2\), just below the line.
Common pitfalls
Frequently asked questions
What is a residual in statistics?
A residual is the actual value of the response variable minus the value predicted by the least squares line. Positive means the point is above the line; negative means it is below.
How do you construct a residual plot?
Work out the predicted value for each x using y = a + bx, subtract it from the actual y-value to get the residual, then plot each residual against its x-value with a horizontal line at zero.
What does a good residual plot look like?
The residuals are scattered randomly above and below the zero line, with no curve, trend or other pattern. That supports a linear model for the data.
What does a curved pattern in a residual plot mean?
It means the relationship between the variables is not linear, so a straight line is not an appropriate model, even if the correlation coefficient is strong. A transformation may help.
Why do the residuals add up to zero?
The least squares line passes through the point of means and balances the points above it against the points below it, so the positive and negative residuals always cancel out.
Can r be close to 1 when a linear model is not appropriate?
Yes. Curved data that rise steadily can give r above 0.9. The residual plot, not r, tells you whether the form of the data is linear.