From One Residual to a Whole Data Set
In “Residuals on a Scatterplot With the Line,” you identified a residual as the vertical gap between an observed point and the fitted line at the same \(x\)-value. Now the task is to calculate that gap for every observation in a small data set and organize the results so they can be checked.
The calculation follows the same rule for each row: use the observed \(x\)-value to find the predicted response \(\hat{y}\), then subtract that prediction from the observed response \(y\). Keep each \(x\) and \(y\) pair together. A residual is attached to its particular observation, so mixing up rows changes the answer.
A useful residual table includes the observed predictor \(x\), the observed response \(y\), the prediction \(\hat{y}\), and the residual \(y-\hat{y}\). The table makes it easier to check that every observation is included once, that each prediction uses the correct \(x\), and that the subtraction has the correct order.
For a least-squares regression line with an intercept, the signed residuals for the fitted data sum to zero, as noted in “Properties of the Least-Squares Line.” In a calculation, the sum may be approximately zero rather than exactly zero if the displayed line or table values have been rounded. The sum is a check on the work; it is not a replacement for calculating each residual.
A Row-by-Row Method
Use this sequence when a question asks for all residuals. If the equation is supplied, use it as written. If a calculator or computer supplies the line, retain as much precision as possible while calculating predictions and residuals.
Record each observed \(x\) and its matching observed \(y\) in the same row.
Substitute that row’s \(x\)-value into \(\hat{y}=a+bx\).
For every row, calculate \(y-\hat{y}\), keeping the sign.
Add the residuals with their signs. For a least-squares line with an intercept, the total should be zero or close to zero, allowing for rounding.
Do not add the absolute values when checking the sum. The positive and negative signs matter: adding \(|y-\hat{y}|\) answers a different question about total distance and will not generally give zero.
Worked Example: Residuals for a 3D Printer Data Set
Worked Example: Residuals for a 3D Printer Data Set
A fictional makerspace records \(x\), the hours a printer operates, and \(y\), the grams of filament used. The least-squares regression line is \(\hat{y}=10+2x\). Find and tabulate all residuals for these five observations: \((1,13)\), \((2,12)\), \((3,18)\), \((4,16)\), and \((5,21)\). Then check their sum.
State. The predictor is operating time in hours, and the response is filament used in grams. We need one prediction and one signed residual for each observed pair.
Plan. For each row, substitute its operating time into \(\hat{y}=10+2x\). Then subtract the prediction from that row’s observed filament use. Finally, add all five signed residuals.
Do. The first observation has \(x=1\), so its prediction is \(10+2(1)=12\) grams and its residual is \(13-12=1\) gram. For the remaining rows, the predictions and residuals are calculated in the same way:
| Operating time, \(x\) (hours) | Observed filament, \(y\) (grams) | Predicted filament, \(\hat{y}=10+2x\) (grams) | Residual, \(y-\hat{y}\) (grams) |
|---|---|---|---|
| 1 | 13 | 12 | +1 |
| 2 | 12 | 14 | −2 |
| 3 | 18 | 16 | +2 |
| 4 | 16 | 18 | −2 |
| 5 | 21 | 20 | +1 |
The signed total is:
Conclude. The five residuals are \(+1\), \(-2\), \(+2\), \(-2\), and \(+1\) grams, and their signed sum is zero. The positive residuals indicate observations above the fitted line; the negative residuals indicate observations below it.
The check concerns the signed residuals. Their absolute values add to \(1+2+2+2+1=8\) grams, not zero. That positive total describes the sum of the gaps’ magnitudes, not the sum required for checking a least-squares line.
Worked Example: A Table With Decimal Predictions
Worked Example: A Table With Decimal Predictions
A fictional student support program models a quiz score \(y\), in points, using \(x\), the number of hours spent studying. Its least-squares line is \(\hat{y}=12+1.25x\). For four students, the observed pairs are \((0,13)\), \((2,13.5)\), \((4,16)\), and \((6,20.5)\). Find all residuals and check their sum.
State. The response is quiz score in points, and the fitted line gives the predicted score for each number of study hours.
Plan. Calculate \(\hat{y}=12+1.25x\) at each observed \(x\). Use the observed score minus that predicted score to find each residual, then add the four results with their signs.
Do. At \(x=0\), the prediction is \(12+1.25(0)=12\), so the residual is \(13-12=1\) point. At \(x=2\), the prediction is \(12+1.25(2)=14.5\), so the residual is \(13.5-14.5=-1\) point. The remaining rows are calculated in the table.
| Study time, \(x\) (hours) | Observed score, \(y\) (points) | Predicted score, \(\hat{y}\) (points) | Residual, \(y-\hat{y}\) (points) |
|---|---|---|---|
| 0 | 13 | 12 | +1 |
| 2 | 13.5 | 14.5 | −1 |
| 4 | 16 | 17 | −1 |
| 6 | 20.5 | 19.5 | +1 |
For the last two rows, the calculations are \(16-17=-1\) point and \(20.5-19.5=1\) point, respectively. The signed sum is:
Conclude. The residuals are \(+1\), \(-1\), \(-1\), and \(+1\) points. Their signed sum is zero, as expected for the fitted least-squares line with an intercept.
Predictions do not have to be whole numbers just because the observed values happen to be whole numbers. Keep the decimal prediction when subtracting; rounding it first can change a residual and the sum.
Worked Example: Small Residuals and the Effect of Rounding
Worked Example: Small Residuals and the Effect of Rounding
A fictional bike-sharing program models trip time \(y\), in minutes, using trip distance \(x\), in kilometers. Its least-squares line is \(\hat{y}=4+1.5x\). Four observed pairs are \((1,5.51)\), \((2,6.97)\), \((3,8.53)\), and \((4,9.99)\). Find the residuals and explain why keeping precision matters.
State. Each residual is measured in minutes and is the observed trip time minus the line’s predicted time for the same distance.
Plan. Substitute each distance into \(\hat{y}=4+1.5x\), retain the predictions, and subtract them from the observed times. Then check the signed total.
Do. For example, at \(x=1\), the prediction is \(4+1.5(1)=5.5\) minutes, giving a residual of \(5.51-5.5=0.01\) minute. The full table is:
| Distance, \(x\) (kilometers) | Observed time, \(y\) (minutes) | Predicted time, \(\hat{y}=4+1.5x\) (minutes) | Residual, \(y-\hat{y}\) (minutes) |
|---|---|---|---|
| 1 | 5.51 | 5.5 | +0.01 |
| 2 | 6.97 | 7 | −0.03 |
| 3 | 8.53 | 8.5 | +0.03 |
| 4 | 9.99 | 10 | −0.01 |
Adding the residuals at the precision shown gives:
Suppose instead that each prediction were first rounded to a whole minute: \(5.5\) to \(6\), \(7\) to \(7\), \(8.5\) to \(9\), and \(10\) to \(10\). The resulting incorrectly rounded residuals would be \(-0.49\), \(-0.03\), \(-0.47\), and \(-0.01\) minutes, which sum to \(-1.00\) minute. The apparent failure of the check comes from rounding the predictions too early.
Conclude. Using the fitted line without prematurely rounding gives residuals that sum to zero. Keep enough precision during the calculations; round only when reporting a final result, and state that a nonzero total may reflect rounding if the line’s coefficients are themselves rounded.
Reading and Checking a Residual Table
A well-organized table lets you inspect more than the total. Check each row against the original paired data, confirm that every prediction uses the row’s \(x\), and verify the subtraction direction. As established in “Defining a Residual as Observed Minus Predicted,” a positive residual is \(y-\hat{y}>0\), and a negative residual is \(y-\hat{y}<0\). The residual’s units match the response’s units.
The zero-sum check applies when the line is the least-squares regression line for the observations and includes an intercept. It is not a general property of every line drawn through a scatterplot. If a proposed line is not a least-squares line, or if it is a regression through the origin without an intercept, do not use a zero sum as an expected result.
A small nonzero total can occur when the regression equation or predictions are rounded. If the total is noticeably different from zero, check for a sign error, an omitted observation, a mismatched \(x\)-\(y\) pair, or a line that is not the least-squares line for those data. Do not change a residual merely to force the sum to zero.
Common Mistakes and AP Exam Tips
- Reversing the subtraction. A residual is observed minus predicted, \(y-\hat{y}\), not \(\hat{y}-y\). A full-credit calculation shows the observed response first and preserves the resulting sign.
- Pairing the wrong observations. Each prediction uses the \(x\)-value from the same case as the observed \(y\). Keep the original row order or label cases clearly.
- Reporting only a total. The task asks for all residuals, so show a residual for every observation. A sum alone does not demonstrate that the individual calculations are correct.
- Adding absolute values for the check. The check uses signed residuals. Positive and negative values can cancel; absolute values cannot.
- Rounding too soon. Keep calculator or computer precision during substitution and subtraction. A rounded displayed line can produce a small nonzero sum even when the full-precision sum is zero.
- Claiming every line has a zero residual sum. State that the check is expected for the least-squares regression line with an intercept, not for an arbitrary candidate line.
- Leaving off response units. A residual is measured in the response variable’s units, such as minutes, grams, or score points—not in the predictor’s units.
For a clear written answer, include the fitted equation, a table with observed values, predictions, and signed residuals, and the calculation of the signed total. Then describe the total as zero or approximately zero, as appropriate to the precision provided.
Check Your Understanding
Use the fitted line and observations in each question. Show the residual calculations and keep the signs.
- A least-squares line is \(\hat{y}=6+2x\). For observations \((1,9)\), \((2,8)\), and \((3,13)\), calculate all three residuals and their signed sum.
- For one observation, \(y=17\) and \(\hat{y}=19.5\). What is its residual, and what units should it have?
- Why should predictions retain decimal places while you calculate a residual table?
- A table lists residuals \(+3\), \(-2\), and \(-1\). What is their signed sum? What is the sum of their absolute values, and which sum is used for the least-squares check?
- Does the residual-sum check apply to any line drawn on a scatterplot? Explain when it is expected to apply.