Tutorials › Introduction to Statistics › Computing and Interpreting Regression Residuals

Residuals and Transformations · Tutorial 275 of 996

Computing and Interpreting Regression Residuals

Calculate observed-minus-predicted residuals, interpret their signs and units, and connect each one to its paired data point on a scatterplot.

Intermediate 9 min read

What You'll Learn

  • Calculate a fitted response and its residual for a paired observation.
  • Interpret positive, negative, and zero residuals in context.
  • Explain why a residual is a signed vertical distance on a scatterplot.
  • Distinguish an observed residual from an unobserved model error.
  • Check the residuals from a least-squares line with an intercept.

Why Residuals Matter

A fitted regression line gives a predicted response for each predictor value. But a prediction is not usually the same as the observed response for an individual case. The difference between those two values tells us how far that case’s observed response is from the line, and in which direction.

That difference is called a residual. Residuals put individual prediction errors on the same scale as the response, such as points, minutes, or dollars. They also give each observed point a direct connection to its fitted line: the residual is the point’s signed vertical gap from the line.

Definition: For observation \(i\), let \(x_i\) be its predictor value and \(y_i\) its observed response. If the fitted regression line predicts \(\hat{y}_i\) at \(x_i\), the residual is $$ e_i = y_i - \hat{y}_i. $$ It is the observed response minus the predicted response for the same observation.

Calculating a Residual

Suppose a fitted line predicts the response \(y\) from the predictor \(x\) using \(\hat{y}=a+bx\), where \(a\) is the fitted intercept and \(b\) is the fitted slope. For observation \(i\), first substitute its predictor value \(x_i\) to calculate \(\hat{y}_i=a+bx_i\). Then subtract that prediction from its observed response \(y_i\).

$$ e_i = y_i - \hat{y}_i = y_i - (a+bx_i) $$

The order of subtraction matters. A positive residual means the observed response is greater than the predicted response. A negative residual means the observed response is less than predicted. A residual of zero means the observation falls exactly on the fitted line. In all three cases, the residual has the same units as the response because it is a difference between two response values.

Worked Example: Quiz Scores and Study Hours

Suppose, hypothetically, a fitted line predicts quiz score \(y\), in points, from study time \(x\), in hours: \(\hat{y}=42+5x\). Calculate residuals for three students with the following paired observations: \((2,55)\), \((4,59)\), and \((6,76)\). The first value in each pair is hours studied; the second is the observed quiz score.

For the student who studied 2 hours, the predicted score is \(42+5(2)=52\) points. The residual is \(e=55-52=3\) points. The observed score is 3 points above the prediction.

For the student who studied 4 hours, the prediction is \(42+5(4)=62\) points. The residual is \(e=59-62=-3\) points. The observed score is 3 points below the prediction.

For the student who studied 6 hours, the prediction is \(42+5(6)=72\) points. The residual is \(e=76-72=4\) points. The observed score is 4 points above the prediction.

The residuals, in order, are \(3\), \(-3\), and \(4\) points. Their signs describe which side of the line each observation lies on; their magnitudes describe how many score points separate the observed and predicted responses.

Residuals as Vertical Gaps on a Scatterplot

A scatterplot displays predictor values along the horizontal axis and response values along the vertical axis. An observation \((x_i,y_i)\) is plotted at its predictor and its observed response. The fitted line gives the predicted response \(\hat{y}_i\) at that same horizontal position \(x_i\). The residual compares \(y_i\) with \(\hat{y}_i\), so it is a vertical difference between the point and the line.

If \(e_i>0\), then \(y_i>\hat{y}_i\), and the point lies above the line. If \(e_i<0\), then \(y_i<\hat{y}_i\), and the point lies below the line. If \(e_i=0\), the observed point is on the line. The size of the vertical gap is \(|e_i|\), while the sign records its direction.

A residual is not a horizontal distance to the line, and it is not the shortest geometric distance to the line. It compares two response values at the same \(x_i\). This is why a residual’s units come from the vertical axis, not the horizontal one.

Worked Example: Interpreting a Residual in Context

Imagine a hypothetical analysis of daily exercise time and resting pulse rate. Let \(x\) be exercise time in minutes and \(y\) be resting pulse rate in beats per minute. A fitted line is \(\hat{y}=72-0.8x\). For a person who exercised for 30 minutes, the observed resting pulse rate is 52 beats per minute. Calculate and interpret the residual.

At \(x=30\) minutes, the predicted rate is \(\hat{y}=72-0.8(30)=72-24=48\) beats per minute. Subtract the prediction from the observed response: \(e=52-48=4\) beats per minute.

The residual is positive, so the observed point lies above the fitted line at 30 minutes. In context, this person’s observed resting pulse rate is 4 beats per minute higher than the line predicts for that exercise time. This description is about the fitted relationship; it does not establish that exercise caused the pulse rate.

What a Residual Does—and Does Not—Measure

A residual belongs to one particular paired observation and one particular fitted line. If either the observed response or the fitted line changes, the residual may change. It is therefore not a permanent attribute of a person or object. To interpret one correctly, identify the observation, the response, the fitted prediction at that observation’s predictor value, and the response units.

A residual is also distinct from an unobserved model error. The model error is the deviation of an observed response from the underlying population relationship, which is not directly known. A residual instead uses the fitted line estimated from the available data, so it can be calculated from the observed response and the fitted prediction. It is an observable difference, not a direct measurement of an unknown population error.

Residuals are useful because they show how individual observations differ from predictions. A large absolute residual means the observed response is far from the fitted prediction in response units. That fact alone does not determine whether the whole regression is appropriate, nor does it explain why the observation differs. Assessing overall patterns in residuals is a separate task.

Worked Example: A Residual in Monthly Rent

Suppose a hypothetical fitted line predicts monthly rent \(y\), in dollars, from apartment area \(x\), in square metres: \(\hat{y}=500+12x\). One apartment has an area of 80 square metres and an observed monthly rent of $1,390. Calculate the prediction and residual, then connect the result to the scatterplot.

The predicted rent is \(\hat{y}=500+12(80)=500+960=\$1{,}460\) per month. The residual is \(e=1{,}390-1{,}460=-\$70\) per month.

The negative sign means the observed rent is below the predicted rent. On a scatterplot of area against rent, this apartment’s point is at \(x=80\) square metres and \(y=\$1{,}390\) per month, 70 dollars vertically below the line’s prediction at \(x=80\). The residual is measured in dollars per month, not square metres.

A Useful Check for Least-Squares Lines

When a straight line is fitted by ordinary least squares with an intercept, its residuals sum to zero, apart from possible rounding in reported values. This is a property of the fitting procedure, not a rule that every residual must be zero or that every point lies close to the line.

To see why, write the sum of squared residuals for a line with intercept \(a\) and slope \(b\) as \(Q(a,b)=\sum_i (y_i-a-bx_i)^2\). At the least-squares fit, changing the intercept slightly cannot reduce \(Q\). Therefore the derivative of \(Q\) with respect to \(a\) is zero:

$$ \frac{\partial Q}{\partial a} = -2\sum_i (y_i-a-bx_i) = -2\sum_i e_i = 0. $$

It follows that \(\sum_i e_i=0\). In the quiz-score example, the three residuals sum to \(3+(-3)+4=4\), not zero. That line was supplied as a hypothetical fitted equation and was not specified as the ordinary least-squares line for those three observations. The check applies only when the line was fitted by ordinary least squares with an intercept, and exact residuals are used.

1
Find the matched observation.
Use the observed response and predictor value from the same case.
2
Calculate the fitted response.
Substitute that case’s predictor value into the fitted regression equation.
3
Subtract predicted from observed.
Compute \(e_i=y_i-\hat{y}_i\), preserving the response units.
4
Interpret the result.
Positive means above the line, negative means below, and zero means on the line.

Common Mistakes

  • Reversing the subtraction. A learner might calculate \(\hat{y}_i-y_i\), then say a positive result means the observation was above the line. The correction is to use \(e_i=y_i-\hat{y}_i\): positive residuals are above the line, and negative residuals are below it.
  • Using the wrong case’s values. A prediction at one predictor value must be compared with the observed response for that same observation. Pair each \(x_i\) with its own \(y_i\) before calculating.
  • Giving the predictor’s units. A rent residual is measured in dollars per month, not square metres. Since \(y_i\) and \(\hat{y}_i\) are both response values, their difference has response units.
  • Calling the residual a horizontal or shortest distance. The residual compares observed and predicted responses at the same predictor value. On the usual scatterplot, it is a signed vertical gap.
  • Assuming zero-sum residuals mean a perfect fit. Residuals can add to zero while individual residuals are large, because positive and negative values can cancel. The zero-sum property is not evidence that every observation is predicted exactly.
Key takeaway: For each observation, calculate the fitted response at its predictor value and subtract that prediction from the observed response. The result is a signed vertical discrepancy in response units: positive above the line, negative below it, and zero on it.

Check Your Understanding

For each question, focus on the observed response, the fitted prediction for that same case, and the residual’s meaning.

  1. A fitted line predicts a response of 18 units for one case whose observed response is 15 units. Calculate the residual and state whether the point is above or below the line.
  2. A residual is \(-6\) minutes for a prediction of a person’s waiting time. Explain what the sign and units mean in context.
  3. Why is a residual a vertical gap on a scatterplot rather than a horizontal gap?
  4. A student calculates \(\hat{y}_i-y_i=7\) and reports a positive residual. What is the correct residual, and how should the point’s position relative to the line be described?
  5. Why can the residuals sum to zero for a least-squares line with an intercept even though individual observations do not all lie on the line?