When the Fitted Line Has No Residuals
Least squares chooses the line that minimizes the sum of squared residuals. Usually, the fitted values do not equal every observed response, so some residual variation remains. But sometimes all the data points lie exactly on one straight line. Then every residual is zero, and the residual sum of squares is zero as well. The calculation is straightforward; interpreting it requires more care.
In particular, zero residual variation in a dataset does not automatically mean that the underlying process has no random error. It may reflect a deterministic relationship, a small dataset, or values rounded before being recorded. And although the standard residual-based estimate of error variance is then zero, zero is not a usable estimate of a positive noise level for further uncertainty calculations.
The Model and the Exact-Fit Calculation
Write the simple linear regression model as \(Y_i=\beta_0+\beta_1x_i+\varepsilon_i\), where \(x_i\) is the predictor value for observation \(i\), and \(Y_i\) is its response. For the standard variance interpretation, assume the \(x_i\) values are fixed, the errors are independent with mean zero and common variance \(\sigma^2\), and the predictor values are not all equal. Normal errors, \(\varepsilon_i\sim N(0,\sigma^2)\), are an additional assumption when normal-based inference is required; they are not needed to calculate a least-squares line.
The least-squares estimates \(\hat{\beta}_0\) and \(\hat{\beta}_1\) give fitted values \(\hat{Y}_i=\hat{\beta}_0+\hat{\beta}_1x_i\). The residual for observation \(i\) is \(e_i=Y_i-\hat{Y}_i\). The residual sum of squares is \(SSE=\sum_{i=1}^n e_i^2\). With \(n\) observations and an estimated intercept and slope, the residual-based estimate of error variance is \(s^2=SSE/(n-2)\), provided \(n>2\).
The condition \(n>2\) matters. With two observations at distinct predictor values, a line can pass through both points, but there are no residual degrees of freedom left to estimate error variance. A zero residual sum of squares from two points is therefore automatic, not evidence of a noiseless relationship.
Why an Exact Line Gives Zero Residuals
Suppose the observed values satisfy \(Y_i=a+bx_i\) for constants \(a\) and \(b\), with at least two distinct predictor values. The least-squares slope can be written as \(S_{xy}/S_{xx}\), where \(S_{xy}=\sum (x_i-\bar{x})(Y_i-\bar{Y})\) and \(S_{xx}=\sum (x_i-\bar{x})^2\). Substituting the exact-line relationship shows why the calculated slope and intercept recover that line.
Thus \(\hat{Y}_i=a+bx_i=Y_i\) for every observation, so \(e_i=0\) and \(SSE=\sum 0^2=0\). If \(n>2\), dividing by the positive residual degrees of freedom \(n-2\) still gives \(s^2=0\). This establishes the calculation, not the truth of a zero-variance population model.
Worked Example: A Calibration Dataset Exactly on a Line
A hypothetical calibration exercise records four input settings \(x\) and corresponding sensor readings \(Y\): \((1,7),(2,9),(4,13),(5,15)\). Find the least-squares line, the residuals, \(SSE\), and \(s^2\). For the variance interpretation, suppose the usual independent, mean-zero, common-variance error model applies; normal errors may be assumed for inference, but no inference is requested here.
Method. Calculate the centered sums to identify the least-squares line, then calculate each residual. The common mistake to avoid is treating an exact fit as a positive residual variance estimate.
First, \(\bar{x}=(1+2+4+5)/4=3\), and \(\bar{Y}=(7+9+13+15)/4=44/4=11\). The centered predictor values are \(-2,-1,1,2\), and the centered responses are \(-4,-2,2,4\). Therefore,
The fitted slope is \(\hat{\beta}_1=20/10=2\), and the fitted intercept is \(\hat{\beta}_0=11-(2)(3)=5\). Thus the fitted line is \(\hat{Y}=5+2x\). At \(x=1,2,4,5\), the fitted values are \(7,9,13,15\), respectively. The residuals are \(7-7=0,\ 9-9=0,\ 13-13=0,\ 15-15=0\).
Consequently, \(SSE=0^2+0^2+0^2+0^2=0\). Here \(n=4\), so the residual degrees of freedom are \(4-2=2\), and \(s^2=0/2=0\). The result is internally consistent: substituting the fitted line reproduces every response exactly, and the residual sum of squares is zero.
What Zero Residual Variation Means
The residual variance estimate \(s^2\) summarizes the variation left after fitting the line. When all residuals vanish, the formula has no residual variation to summarize and returns zero. It does not distinguish why the residuals vanished. For example, a process may be deterministic, recorded values may have been rounded, or a small collection of observations may happen to display an exact pattern.
There is also a model-based caution. Under the normal regression model with \(\sigma^2>0\), errors have a continuous distribution. With more than two observations and a full-rank design, the probability that the entire random error vector lands exactly on the fitted line is zero. Thus an exact fit in such a dataset is not an ordinary positive-variance normal-regression outcome. It can indicate that the model or the data-recording description needs scrutiny. It does not justify quietly assuming that \(\sigma^2=0\) while continuing to use formulas that require positive error variance.
If a calculation requires a standard deviation based on \(s^2\), the result here is zero. That is a warning, not evidence that estimated uncertainty has disappeared. In particular, dividing by a standard error calculated as zero is not a valid way to claim overwhelming evidence. The variance estimate has collapsed because the observed residuals contain no variation.
Worked Example: A Horizontal Exact Fit and R-Squared
A hypothetical test records four output readings at input settings \(x=2,4,6,8\). Every reading is \(Y=3\). Find the fitted line, \(SSE\), \(s^2\), and whether the usual \(R^2=1-SSE/S_{YY}\) formula is defined, where \(S_{YY}=\sum (Y_i-\bar{Y})^2\). Assume the standard independent, mean-zero, common-variance error model for interpreting \(s^2\); the values themselves are treated as exact recorded values.
Method. Compute the means and centered sums, then check the denominator of \(R^2\). A common mistake is to state \(R^2=1\) for every exact fit without checking whether \(S_{YY}\) is positive.
The means are \(\bar{x}=(2+4+6+8)/4=5\) and \(\bar{Y}=(3+3+3+3)/4=3\). Each response deviation \(Y_i-\bar{Y}\) is zero, so \(S_{YY}=0\). The centered cross-products are also all zero, giving \(S_{xy}=0\). Meanwhile, \(S_{xx}=(-3)^2+(-1)^2+1^2+3^2=20\), so the fitted slope is \(0/20=0\), and the intercept is \(3-0(5)=3\). The fitted line is \(\hat{Y}=3\).
Each fitted value is 3, so every residual is \(3-3=0\), and \(SSE=0\). Since \(n=4\), \(s^2=0/(4-2)=0\). But \(R^2=1-0/0\) is undefined: its denominator is zero because there is no observed response variation to explain. The check is decisive; the exact horizontal fit does not give a defined usual \(R^2\).
Nearly Exact Fits and Recorded Precision
A dataset can look perfectly linear in a table that displays only a few decimal places, even when the underlying recorded values are not exactly on a line. To decide whether the fit is truly exact, use the values supplied in the problem and compute the residuals. Do not replace small residuals with zero merely because they seem negligible. Conversely, do not claim extra precision beyond the stated data.
For a nonhorizontal exact fit, \(S_{YY}>0\) and \(SSE=0\), so the usual \(R^2\) formula gives 1. For a horizontal exact fit, \(S_{YY}=0\), and the formula is undefined. A second trap is confusing these cases with the two-observation situation: with two distinct predictor values and only two observations, an exact line can always be drawn, but \(n-2=0\), so \(s^2\) cannot be calculated.
Worked Example: Small Residuals Are Not Zero Residuals
A hypothetical monitoring study records \((x,Y)=(0,1.02),(1,3.01),(2,4.99),(3,7.00)\). Treat the displayed decimal values as the exact data. Find the least-squares line, \(SSE\), and \(s^2\). For the usual variance interpretation, assume independent errors with mean zero and common variance; assume normal errors only if a later normal-based inference procedure is used.
Method. Calculate the least-squares coefficients and then retain the small residuals when forming \(SSE\). The mistake to avoid is rounding each fitted value too early and declaring the residuals zero.
The means are \(\bar{x}=(0+1+2+3)/4=1.5\) and \(\bar{Y}=(1.02+3.01+4.99+7.00)/4=16.02/4=4.005\). The centered \(x\) values are \(-1.5,-0.5,0.5,1.5\); the centered \(Y\) values are \(-2.985,-0.995,0.985,2.995\). Therefore,
The fitted line is \(\hat{Y}=1.017+1.992x\). Its fitted values at \(x=0,1,2,3\) are \(1.017,3.009,5.001,6.993\). Subtracting each fitted value from its observed response gives residuals \(0.003,0.001,-0.011,0.007\). Thus
With \(n=4\), \(s^2=0.000180/2=0.000090\). The arithmetic check is that the small residuals do not vanish, so the sum of their squares is positive. The exact-fit conclusion from the first example would be wrong for these data.
Exam Checks and Common Traps
They must not all be equal to identify an intercept-and-slope line from the data.
An exact fit requires every residual to be zero using the stated data values, not merely small.
The residual variance formula requires \(n-2>0\). With \(n=2\), a zero residual sum of squares leaves no residual degrees of freedom.
If \(n>2\) and \(SSE=0\), the formula gives \(s^2=0\); do not turn that result into an unsupported claim that the underlying random error variance is known to be zero.
The central distinction is between a property of the observed dataset and a claim about the stochastic process that generated it. An exact fit is a statement about observed residuals. The regression error variance is a model quantity. A zero residual-based estimate signals that this dataset supplies no positive residual variation from which to estimate a positive noise level.
Check Your Understanding
For each problem, use the stated observations as exact values and check both the residual calculation and the applicable degrees of freedom.
- A dataset has \(x=1,2,4\) and \(Y=1, -2, -8\). Find the fitted line, \(SSE\), and \(s^2\). (Answer: \(\hat{Y}=4-3x\), \(SSE=0\), \(s^2=0\) with 1 residual degree of freedom.)
- Four observations have predictor values \(0,1,2,3\) and response \(Y=5\) for all four. What is the fitted line, residual variance estimate, and status of the usual \(R^2=1-SSE/S_{YY}\)? (Answer: \(\hat{Y}=5\), \(s^2=0\), and \(R^2\) is undefined because \(S_{YY}=0\).)
- For \(x=0,1,2,3\), the responses are \(2,4,6,7\). Find the least-squares line, \(SSE\), and \(s^2\). (Answer: \(\hat{Y}=2.2+1.7x\), \(SSE=0.30\), \(s^2=0.15\) with 2 residual degrees of freedom.)
- Two observations have distinct predictor values and lie on a line with zero residuals. Can the residual error variance be estimated using \(SSE/(n-2)\), and does the zero \(SSE\) establish a zero-variance process? (Answer: No; \(n-2=0\), so the estimate is undefined, and the exact fit is automatic for two distinct predictor values.)
- Four observations have distinct predictor values, every response lies on a nonhorizontal line, and the supplied values are exact. State \(SSE\), \(s^2\), and the usual \(R^2\). (Answer: \(SSE=0\), \(s^2=0\) with 2 residual degrees of freedom, and \(R^2=1\).)