What a residual is and why you calculate it
A residual is the difference between what a model predicted and what actually happened. If you predicted a house would sell for $300,000 but it sold for $310,000, your residual is $10,000. Residuals tell you where your predictions went wrong—and by how much.
You calculate residuals because they show you whether your model is systematically over-predicting, under-predicting, or hitting the mark. A pattern in your residuals (like always being too high for expensive houses) means your model has a blind spot. Residuals also help you spot outliers—cases so unusual that your model couldn't have predicted them accurately.
In practice, residuals are the foundation of model checking. Before you trust a prediction, you need to know how far off it typically is. That distance is what residuals measure.
Key Takeaways
- A residual is calculated by subtracting the predicted value from the actual value: Residual = Actual − Predicted.
- Positive residuals mean your prediction was too low; negative residuals mean it was too high.
- You calculate residuals for every data point in your dataset, then look for patterns across all of them.
- The average of all residuals should be close to zero if your model is unbiased, though this is not always true in practice.
- Residual plots—graphs showing residuals on one axis and predicted values on the other—reveal whether your model has systematic errors.
The basic formula and how the process works it
The formula is straightforward: Residual = Actual Value − Predicted Value. You need two numbers for each case: the real outcome and what your model said would happen.
Suppose you built a model to predict test scores based on hours studied. For one student, your model predicted a score of 78, but they actually scored 82. The residual is 82 − 78 = 4. For another student, the model predicted 85 but they scored 79. That residual is 79 − 85 = −6. The negative sign tells you the prediction was too high.
You repeat this for every observation in your dataset. If you have 100 students, you calculate 100 residuals. Each one is a single number—positive, negative, or zero.
Working through a concrete example
Imagine you have a straightforward linear regression model that predicts apartment rent based on square footage. The model's equation is: Predicted Rent = 500 + (1.5 × Square Feet).
You have three apartments in your dataset:
| Apartment | Square Feet | Actual Rent | Predicted Rent | Residual |
|---|---|---|---|---|
| A | 800 | $1,700 | 500 + (1.5 × 800) = $1,700 | $1,700 − $1,700 = $0 |
| B | 1,000 | $2,200 | 500 + (1.5 × 1,000) = $2,000 | $2,200 − $2,000 = $200 |
| C | 1,200 | $1,950 | 500 + (1.5 × 1,200) = $2,300 | $1,950 − $2,300 = −$350 |
Apartment A's residual is zero—the model nailed it. Apartment B's residual is positive, meaning the actual rent was higher than predicted (maybe it's in a desirable neighborhood). Apartment C's residual is negative, meaning the actual rent was lower than predicted (perhaps it needs renovation). These three residuals together tell you where the model succeeded and where it missed.
What residuals reveal about your model
A single residual tells you one prediction's error. But the pattern across all residuals tells you whether your model is fundamentally sound. If residuals are scattered randomly around zero with no pattern, your model is probably doing its job. If they cluster in a way—always positive for large values, always negative for small values—your model has a systematic bias.
The sum of all residuals should be close to zero (or exactly zero in ordinary least squares regression). If it is not, something went wrong in your calculation or your model is biased. The average residual should also be near zero. A large average residual means your model consistently over-predicts or under-predicts.
You also look at the standard deviation of residuals—how spread out they are. A small standard deviation means your predictions are consistently close to reality. A large one means your model is unreliable, even if the average is zero.
Reading and using a residual plot
A residual plot is a scatter graph with predicted values on the horizontal axis and residuals on the vertical axis. Each dot represents one observation. A good residual plot looks like a random cloud centered on zero, with no obvious pattern.
If the plot shows a funnel shape—residuals spread wider as predicted values increase—your model is less accurate for larger values. If it shows a curve, your model may be missing a non-linear relationship. If all points sit above or below the zero line, your model is systematically biased.
To create a residual plot in most software: calculate residuals for all observations, then plot them against the predicted values. Many statistical packages (R, Python with scikit-learn, Excel with add-ins) can generate this automatically once you have fit a model.
Common mistakes when calculating residuals
The most common error is reversing the subtraction: calculating Predicted − Actual instead of Actual − Predicted. This flips the sign of every residual, which changes your interpretation. Always subtract the predicted from the actual.
Another mistake is using the wrong predicted value. If you are working with a regression model, make sure you are using the model's prediction for that specific observation, not an average or a different observation's prediction.
A third pitfall is ignoring residuals that look like outliers. A residual of 500 when most others are between −10 and 10 is worth investigating. It might mean that observation is genuinely unusual, or it might mean your model needs adjustment. Do not delete it without understanding why it happened.
When to call in help
If you are working with a small dataset or a straightforward linear model, calculating residuals by hand or in a spreadsheet is manageable. For larger datasets or complex models (multiple regression, logistic regression, machine learning), use statistical software. R, Python (with libraries like NumPy and Pandas), and even Excel can handle this.
If your residual plot shows a clear pattern that you cannot explain, or if your residuals are not normally distributed when your model assumes they should be, you may need to rethink your model. That is a sign to consult someone with statistical training, not a sign you did the calculation wrong.
Frequently Asked Questions
Should residuals always add up to exactly zero?
In ordinary least squares regression, the sum of residuals is mathematically zero (or very close due to rounding). In other types of models, residuals may not sum to zero. What matters is that the average residual is close to zero, which means your model is not systematically biased high or low.
What does a large residual mean?
A large residual means your model made a big prediction error for that observation. It could mean the observation is unusual, your model is missing an important variable, or there is a data entry error. Always investigate large residuals rather than ignoring them.
Can residuals be used to improve a model?
Yes. If residuals show a pattern—for example, always positive for one group and negative for another—that tells you your model is missing a variable or relationship. You can add that variable to the model and recalculate residuals to see if the pattern disappears.
Do I need residuals to be normally distributed?
It depends on your model and what you are using residuals for. Linear regression assumes residuals are normally distributed if you want to calculate confidence intervals or p-values. If you are only using the model for prediction, normality is less critical. Check your model's assumptions before deciding.
What is the difference between a residual and an error?
In statistics, "error" usually refers to the theoretical difference between a true value and a prediction. A "residual" is the observed difference you can actually measure in your data. They are closely related but not identical—residuals are what you calculate; errors are what you theorize about.