Tutorials › Regression Analysis (Undergraduate) › The Zero-Sum Residual Property

Fitting a Simple Linear Regression · Tutorial 87 of 991

The Zero-Sum Residual Property

See why fitting an intercept forces the residuals to balance to zero, and practice checking the result in small datasets.

Beginner 9 min read

What You'll Learn

  • Define residuals and state the zero-sum residual property for an ordinary least-squares fit with an intercept.
  • Prove the property by minimizing the sum of squared residuals with respect to the intercept.
  • Calculate fitted values and residuals, then check their sum in a small dataset.
  • Explain why residuals average to zero when an intercept is included.
  • Identify why the zero-sum result is not guaranteed for a fit without an intercept.
  • Distinguish a small nonzero sum caused by rounding from a failure of the property.

Why Residuals Balance Around Zero

A regression line leaves a residual for each observation: the observed response minus the response predicted by the line. Some residuals are positive and some are negative. When ordinary least squares fits a line with an intercept, these signed differences balance exactly: their sum is zero. The balance is a consequence of the fitting rule, not an extra assumption about the data.

This property is useful as a quick check on a calculation. It also has a simple interpretation: the average residual is zero, so the fitted responses and observed responses have the same average. The result applies to the residuals used to fit the line; it does not say that predictions for new observations will have errors that sum to zero.

Definition: For observation \(i\), let \(y_i\) be its observed response and let \(\hat{y}_i\) be the fitted response from the regression line. Its residual is \(e_i=y_i-\hat{y}_i\). An ordinary least-squares line with an intercept is a line of the form \(\hat{y}_i=b_0+b_1x_i\) whose coefficients minimize the sum of squared residuals, \(\sum_{i=1}^{n}(y_i-b_0-b_1x_i)^2\). For this fitted line, \(\sum_{i=1}^{n}e_i=0\).

Here \(b_0\) is the fitted intercept and \(b_1\) is the fitted slope. The residual has the same units as the response \(y\), not the predictor \(x\). A positive residual means the observation is above the fitted line; a negative residual means it is below. The zero-sum result concerns the signed residuals. It does not say that the sum of their absolute values or their squares is zero.

Why the Intercept Forces the Sum to Zero

The key is that least squares is free to adjust the intercept. Hold the slope \(b_1\) fixed temporarily and consider the sum of squared residuals as a function of a candidate intercept \(b_0\):

$$ Q(b_0)=\sum_{i=1}^{n}(y_i-b_0-b_1x_i)^2. $$

At the least-squares minimum, changing \(b_0\) slightly in either direction cannot reduce \(Q\). Because \(Q\) is a differentiable quadratic function, its derivative with respect to \(b_0\) must be zero at its minimum. Differentiating each squared term gives:

$$ \frac{dQ}{db_0} =-2\sum_{i=1}^{n}(y_i-b_0-b_1x_i)=0. $$

At the fitted coefficients, \(y_i-b_0-b_1x_i\) is exactly \(e_i\). Dividing the equation by \(-2\) therefore gives the result:

$$ \sum_{i=1}^{n}e_i=0. $$

This argument does not require the responses to follow a particular probability distribution. It follows from minimizing squared residuals over an intercept that can vary freely. In particular, it still applies if the predictor values have no variation: a slope may then be undetermined, but minimizing over the intercept still makes the residuals sum to zero.

Theorem: If an ordinary least-squares regression includes a freely estimated intercept, the residuals for the observations used to fit the model sum to zero. Consequently, their arithmetic mean is zero: \(\bar{e}=\frac{1}{n}\sum_{i=1}^{n}e_i=0\).

Another way to see the role of the intercept is to write the fitted response as \(\hat{y}_i=b_0+b_1x_i\). The derivative condition says the intercept adjusts until the total observed response matches the total fitted response. Thus the fitted responses and observations have equal means. This is a statement about the sample used for fitting, not a claim that each fitted response equals its observed response.

Checking the Property in a Dataset

Consider the following small hypothetical dataset. The response is measured in units, and the predictor is measured in hours. We first calculate the ordinary least-squares line, then check its residuals directly.

Worked Example: Residuals From a Fitted Line

Suppose three hypothetical observations are \((x_i,y_i)=(1,2),(2,3),(3,7)\). Find the least-squares line with an intercept and show that its residuals sum to zero.

The sample means are \(\bar{x}=(1+2+3)/3=2\) hours and \(\bar{y}=(2+3+7)/3=4\) response units. The slope is the centered-data slope:

$$ b_1= \frac{\sum (x_i-\bar{x})(y_i-\bar{y})} {\sum (x_i-\bar{x})^2} = \frac{(-1)(-2)+(0)(-1)+(1)(3)} {(-1)^2+0^2+1^2} =\frac{5}{2}=2.5. $$

The intercept is \(b_0=\bar{y}-b_1\bar{x}=4-(2.5)(2)=-1\). Thus the fitted line is \(\hat{y}=-1+2.5x\), with fitted responses \(1.5,\ 4,\ 6.5\) response units for the three observed predictor values.

Subtract each fitted response from its observed response. The residuals are \(2-1.5=0.5\), \(3-4=-1\), and \(7-6.5=0.5\) response units. Their sum is \(0.5+(-1)+0.5=0\) response units, as the theorem requires. The positive and negative residuals balance, although none of the observations needs to lie exactly on the line.

The calculation also illustrates why signs matter. A residual sum uses the original positive and negative values. If we squared the residuals instead, we would get \(0.5^2+(-1)^2+0.5^2=1.5\) squared response units, not zero. Least squares minimizes this sum of squares; it does not make the sum of squared residuals vanish.

More Worked Checks

Worked Example: Computing the Mean Residual

Suppose a hypothetical least-squares fit with an intercept gives four residuals, in millimetres: \(0.3,\ 0.1,\ -1.1,\ 0.7\). Verify the sum and find the mean residual.

Add the signed residuals: \(0.3+0.1-1.1+0.7=0.0\) millimetres. There are \(n=4\) observations, so the mean residual is:

$$ \bar{e}=\frac{\sum e_i}{n} =\frac{0.0\text{ mm}}{4} =0.0\text{ mm}. $$

This is consistent with the theorem: a least-squares fit that includes an intercept has residuals averaging zero in the data used to fit it. Notice that the residuals are not all zero; the property is about their average, not about perfect predictions.

The intercept condition is essential. If the line is forced through the origin, there is no adjustable intercept to balance the total signed residuals. The following small calculation shows that the sum can then be nonzero.

Worked Example: A Fit Without an Intercept

For two hypothetical observations \((x_i,y_i)=(1,2)\) and \((2,2)\), fit the least-squares line through the origin, \(\hat{y}_i=b_1x_i\), and calculate the residual sum.

For a line through the origin, the least-squares slope is \(\sum x_i y_i/\sum x_i^2\). Substituting the data gives:

$$ b_1=\frac{(1)(2)+(2)(2)}{1^2+2^2} =\frac{6}{5}=1.2. $$

The fitted responses are \(1.2\) and \(2.4\) response units. The residuals are \(2-1.2=0.8\) and \(2-2.4=-0.4\) response units, so their sum is \(0.8+(-0.4)=0.4\) response units, not zero. There is no contradiction: this model has no intercept, so the zero-sum residual theorem does not apply.

Using the Property Carefully

For an intercept model, the zero-sum result is a useful calculation check, but it is not a general measure of whether the line fits well. A poor-fitting line can still have residuals that sum to zero. For example, a few large positive residuals can balance several negative ones even when the individual prediction errors are substantial.

The property also has a practical limitation: displayed values are often rounded. A computer may use more decimal places internally than it shows in a table. If residuals are rounded before being added, their displayed sum might be a small amount away from zero. That tiny discrepancy does not necessarily indicate an incorrect fit; check using unrounded values when available.

The zero-sum property applies to the observed data used to estimate the line. It does not guarantee that residuals from a separate set of observations, or prediction errors for future cases, will sum to zero. Those values were not used to select the intercept.

Key takeaway: In ordinary least squares with a freely estimated intercept, minimizing squared residuals makes their signed sum—and therefore their mean—zero for the fitting data. Do not extend this guarantee to a no-intercept fit, rounded calculations, or observations that were not used to fit the line.

Common Mistakes

  • Adding absolute residuals instead of signed residuals. The theorem is about \(\sum e_i\), where negative residuals remain negative. Absolute values remove the cancellation that makes the sum zero.
  • Expecting every residual to be zero. A zero sum means the residuals balance overall; it does not mean every point lies on the fitted line.
  • Applying the result to a line forced through the origin. Without an intercept, the derivative condition with respect to an intercept is unavailable, and the residual sum need not be zero.
  • Treating a small rounded sum as a failure. Rounding individual fitted values or residuals can introduce a small displayed discrepancy. The exact result concerns unrounded least-squares residuals.

Check Your Understanding

Answer each question using the distinction between signed residuals, squared residuals, and the model's intercept.

  1. State the definition of a residual and the zero-sum result for an ordinary least-squares fit with an intercept.
  2. In one sentence, explain why minimizing squared residuals with respect to the intercept implies that the residuals sum to zero.
  3. A fitted model has residuals \(-0.4,\ 0.6,\ -0.2\) centimetres. What is their sum and their mean?
  4. Does the zero-sum property imply that every observation lies on the fitted line? Explain.
  5. Why is a nonzero residual sum possible when the model is fitted through the origin?