What a residual is and why you calculate it

A residual is the difference between what actually happened and what your model predicted would happen. If you fit a line through a scatter plot of data points, the residual for each point is how far that point sits above or below the line. Residuals tell you whether your model is doing its job — small residuals mean your predictions are close to reality; large ones mean something is off.

You calculate residuals to check how well your model fits the data. A pattern in the residuals (like them getting bigger as your data increases, or clustering on one side) signals that your model is missing something. Residuals also help you spot individual data points that don't fit the pattern, which might be errors or genuinely unusual cases worth investigating.

Key Takeaways

  • A residual is the actual value minus the predicted value for each data point.
  • You need a fitted model first — a line, curve, or equation that predicts values based on your data.
  • Calculate each residual separately, then plot them or look for patterns to assess model fit.
  • Residuals that are randomly scattered around zero suggest a good fit; residuals that trend upward or cluster suggest the model needs adjustment.

The basic formula and what each part means

The formula is straightforward: Residual = Actual Value − Predicted Value. For each data point, you subtract what your model predicted from what you actually observed. If the actual value is 10 and your model predicted 8, the residual is 2. If the actual value is 10 and your model predicted 12, the residual is −2.

The sign matters. A positive residual means the actual value was higher than predicted. A negative residual means it was lower. The size of the residual tells you how far off the prediction was. A residual of zero means your model predicted perfectly for that point.

Step-by-step calculation with a straightforward example

Suppose you have five data points and you've fit a line to them. Your line's equation is y = 2x + 1. Here are your actual observations and what the line predicts:

Data PointxActual yPredicted y (2x + 1)Residual
11330
22651
33770
4489−1
5512111

For point 2: actual is 6, predicted is 2(2) + 1 = 5, so residual is 6 − 5 = 1. For point 4: actual is 8, predicted is 2(4) + 1 = 9, so residual is 8 − 9 = −1. Once you have all five residuals, you can look at them together. Here they range from −1 to 1, which suggests the line fits reasonably well.

How to interpret residual patterns

Plot your residuals on a graph with the predicted values on the x-axis and residuals on the y-axis. A good fit shows residuals scattered randomly around zero with no clear pattern. If you see residuals that get larger as predicted values increase, your model is underfitting — it's missing a relationship that grows stronger in part of your data. If residuals cluster above or below zero, your model is systematically over- or under-predicting.

A curved pattern in the residuals (like a U-shape or inverted U) means your data follows a curve, not a straight line. Outliers appear as residuals far from the rest — points that don't fit the pattern at all. These might be data entry errors, or they might be real but unusual cases. Either way, they deserve a second look.

Calculating residuals in spreadsheets and software

In Excel or Google Sheets, create a column for predicted values using your model's equation, then subtract it from your actual values in a new column. If your model is a linear regression, use the FORECAST function or TREND function to generate predictions, then subtract those from your actual data column. Most spreadsheet software can fit a line to data and display the equation automatically — use that equation to calculate predictions, then residuals.

In statistical software like R, Python (with libraries like NumPy or scikit-learn), or SPSS, residuals are usually calculated automatically when you fit a model. In R, fit a linear model with lm() and extract residuals with the residuals() function. In Python with scikit-learn, fit your model and subtract predictions from actual values. Most software also produces residual plots automatically, saving you the graphing step.

Common mistakes when calculating residuals

The most frequent error is reversing the subtraction — calculating predicted minus actual instead of actual minus predicted. This flips the sign of every residual but doesn't change the magnitude, so it won't break your analysis if you're consistent, but it will confuse anyone reading your work. Always subtract predicted from actual.

Another mistake is forgetting to use the same model for all predictions. If you fit different lines to different parts of your data, or if you change your model partway through, your residuals won't be comparable. Fit one model to all your data, then calculate residuals for every point using that same model. A third common slip is calculating residuals before checking that your data is actually suited to the model you chose — if your data is clearly curved but you fit a straight line, large residuals are expected and don't mean you made a calculation error.

What to do once you have your residuals

Start by plotting them. A residual plot reveals patterns that a single number can't. Look for randomness — that's your goal. If you see a trend, your model needs adjustment. You might need to add variables, transform your data, or switch to a different model type entirely.

Calculate summary statistics on your residuals: the mean (which should be very close to zero if your model is unbiased), the standard deviation (which tells you the typical size of prediction error), and the range (which shows your worst-case errors). Some analysts calculate the sum of squared residuals, which penalizes large errors heavily and is useful for comparing two models fitted to the same data. The model with the smaller sum of squared residuals fits better.

Frequently Asked Questions

Should residuals always add up to zero?

In ordinary linear regression, the sum of residuals is always zero (or very close to it due to rounding). This is a mathematical property of how the line is fitted, not a sign of a good model. Other model types don't have this property, so don't rely on it as a check.

What size residuals are acceptable?

It depends on your data and what you're predicting. If you're predicting house prices in thousands of dollars, a residual of 5 might be excellent. If you're predicting test scores out of 100, a residual of 5 is larger. Compare residuals to the standard deviation of your actual data — if residuals are much smaller, your model is working well.

Can residuals be used to find outliers?

Yes. Points with unusually large residuals don't fit your model well. A common rule is to flag any point whose residual is more than three standard deviations away from zero. These points deserve investigation — they might be errors, or they might be real but unusual observations that your model doesn't capture.

Do I need to calculate residuals if my software does it automatically?

No, but understanding how they're calculated helps you interpret them correctly. If you're using software, verify that it's calculating residuals the way you expect (actual minus predicted, not the reverse), and always plot them to see patterns your eyes can catch that numbers alone might miss.