When Every Point Falls on One Line
A scatterplot sometimes shows a striking pattern: every observed point lies exactly on the same straight line. In that case, a least-squares regression line can reproduce every response in the dataset with no error. Working through this special case makes the relationship between fitted values, residuals, and squared error especially clear.
The key word is observed. A dataset can lie exactly on a line without showing that the same relationship holds for every individual in a larger population, or that changing the predictor causes a change in the response. Here we study the arithmetic of fitting a line to the data at hand.
For a simple linear regression fit, the fitted response at predictor value \(x_i\) is \(\hat{y}_i=\hat{\beta}_0+\hat{\beta}_1x_i\), where \(\hat{\beta}_0\) and \(\hat{\beta}_1\) are the estimated intercept and slope. The residual for observation \(i\) is \(e_i=y_i-\hat{y}_i\). The residual sum of squares, also called the sum of squared errors, is \(\mathrm{SSE}=\sum_{i=1}^{n}e_i^2\).
To calculate a simple regression line from observed data, the predictor values must vary: at least two \(x_i\) values must be distinct. The calculations below use that condition. They do not require a probability model for the observations; the focus is on the fitted line and its errors within the dataset.
Why an Exact Line Gives Zero Squared Error
If \(y_i=a+bx_i\) for each observation, the line with intercept \(a\) and slope \(b\) predicts \(a+bx_i\) at \(x_i\). Therefore it predicts \(y_i\) exactly. Least squares chooses the intercept and slope to minimize the sum of squared residuals. Since squared residuals cannot be negative, no candidate line can have an SSE below zero. The exact line attains that lower bound.
For calculation, the simple least-squares slope and intercept are
When a dataset is exactly on a line and its \(x\) values vary, these formulas recover that line's slope and intercept. The examples show the calculation rather than relying only on the visual pattern.
Worked Example: A Line With a Positive Slope
Suppose a hypothetical dataset records study time \(x\), in hours, and a practice score \(y\), in points, for four learners. The observed pairs are \((1,5)\), \((2,8)\), \((3,11)\), and \((4,14)\). Fit the least-squares line and calculate every fitted value, residual, and the SSE.
First calculate the means: \(\bar{x}=(1+2+3+4)/4=2.5\) hours and \(\bar{y}=(5+8+11+14)/4=9.5\) points. The centered products are \((-1.5)(-4.5)=6.75\), \((-0.5)(-1.5)=0.75\), \((0.5)(1.5)=0.75\), and \((1.5)(4.5)=6.75\). Their sum is \(15\). The squared centered predictor values sum to \(2.25+0.25+0.25+2.25=5\).
Thus the slope is \(\hat{\beta}_1=15/5=3\) points per hour, and the intercept is \(\hat{\beta}_0=9.5-(3)(2.5)=2\) points. The fitted line is \(\hat{y}=2+3x\).
At \(x=1,2,3,4\), the fitted values are \(5,8,11,14\) points. Subtracting each fitted value from its observed response gives residuals \(5-5=0\), \(8-8=0\), \(11-11=0\), and \(14-14=0\) points. Therefore \(\mathrm{SSE}=0^2+0^2+0^2+0^2=0\) point-squared.
The observations match the fitted line exactly, so every observation equals its fitted value. This conclusion describes these four hypothetical data points, not all learners or all possible study times.
Checking the Calculation Observation by Observation
A useful verification is to substitute every observed predictor into the fitted equation and compare the result with the recorded response. If the observations really do follow one line, each comparison matches. Checking individual values guards against a mistaken coefficient or arithmetic error that could be hidden by reporting only a slope and intercept.
Worked Example: A Line With a Negative Slope
Consider a hypothetical set of measurements relating an input setting \(x\), in units, to an output \(y\), in millimeters: \((0,12)\), \((2,9)\), \((4,6)\), and \((6,3)\). Fit a line and verify its predictions.
The predictor mean is \(\bar{x}=(0+2+4+6)/4=3\) units, and the response mean is \(\bar{y}=(12+9+6+3)/4=7.5\) millimeters. The centered predictor deviations are \(-3,-1,1,3\); the centered response deviations are \(4.5,1.5,-1.5,-4.5\). The sum of centered products is \((-3)(4.5)+(-1)(1.5)+(1)(-1.5)+(3)(-4.5)=-13.5-1.5-1.5-13.5=-30\). The sum of squared predictor deviations is \(9+1+1+9=20\).
The fitted slope is \(\hat{\beta}_1=-30/20=-1.5\) millimeters per input unit. The intercept is \(\hat{\beta}_0=7.5-(-1.5)(3)=12\) millimeters, so the fitted line is \(\hat{y}=12-1.5x\).
Substitution gives \(\hat{y}=12\) at \(x=0\), \(9\) at \(x=2\), \(6\) at \(x=4\), and \(3\) at \(x=6\), all in millimeters. These are exactly the observed responses. The residuals are \(0,0,0,0\) millimeters, and their squared sum is \(0^2+0^2+0^2+0^2=0\) square millimeters.
The negative slope means that the fitted output decreases by \(1.5\) millimeters for each one-unit increase in the input, across this observed set of values. The zero residuals say something different: at each recorded input, the fitted response equals the recorded response.
A Short Justification of the Least-Squares Result
The conclusion that the exact line is a least-squares fit follows directly from the definition of the objective. For any candidate intercept \(c\) and slope \(d\), its residual at observation \(i\) is \(y_i-(c+dx_i)\). Its SSE is the sum of the squares of those residuals, so it must be at least zero. If \(y_i=a+bx_i\) for every \(i\), choosing \(c=a\) and \(d=b\) makes every residual zero and gives SSE zero. Thus that line reaches the smallest possible SSE.
If at least two observed predictor values are distinct, this exact-fitting line is also the only line that can give SSE zero. To see why, an SSE of zero is a sum of nonnegative squared residuals. It can equal zero only if every residual equals zero. Any zero-SSE line must therefore pass through every observed point. Two points with distinct \(x\) values determine one straight line, so any such line must have the same slope and intercept as the exact line.
Worked Example: Exact Fit With Decimal Values
Suppose a hypothetical calibration dataset records an instrument setting \(x\), in units, and a displayed reading \(y\), in centimeters: \((2,2.70)\), \((5,4.95)\), and \((8,7.20)\). Calculate the regression line and check the squared errors.
The means are \(\bar{x}=(2+5+8)/3=5\) units and \(\bar{y}=(2.70+4.95+7.20)/3=4.95\) centimeters. The centered predictor values are \(-3,0,3\), and the centered response values are \(-2.25,0,2.25\). The centered-product sum is \((-3)(-2.25)+(0)(0)+(3)(2.25)=6.75+0+6.75=13.5\). The squared-predictor-deviation sum is \(9+0+9=18\).
The slope is \(\hat{\beta}_1=13.5/18=0.75\) centimeters per setting unit. The intercept is \(\hat{\beta}_0=4.95-(0.75)(5)=1.20\) centimeters. The fitted equation is \(\hat{y}=1.20+0.75x\).
At the three observed settings, the fitted readings are \(1.20+(0.75)(2)=2.70\), \(1.20+(0.75)(5)=4.95\), and \(1.20+(0.75)(8)=7.20\) centimeters. The residuals are \(2.70-2.70=0\), \(4.95-4.95=0\), and \(7.20-7.20=0\) centimeters. Hence \(\mathrm{SSE}=0^2+0^2+0^2=0\) square centimeters.
The exact match is not a consequence of rounding the displayed slope or intercept: both coefficients here yield the stated fitted values exactly. With measured or rounded data, however, a relationship may look linear while leaving small nonzero residuals.
What a Zero SSE Does and Does Not Say
A zero residual sum of squares means there is no discrepancy between observed and fitted responses at the predictor values in this dataset. Because every squared residual is nonnegative, a sum of zero also confirms that each residual is zero individually; positive and negative errors cannot cancel inside a sum of squares.
The squared errors use squared response units. For example, if responses are measured in millimeters, residuals are in millimeters and SSE is in square millimeters. In an exactly linear dataset the numerical total is zero regardless of the response units, but stating the units helps clarify what quantity is being calculated.
A perfect fit to a finite set of observations is not by itself proof of a deterministic law. The pattern might hold only over the observed range, and measurements rounded before recording can affect whether the displayed values lie exactly on a line. Nor does an exact line establish that changing \(x\) causes \(y\) to change. Regression here summarizes the observed association and fits a line; causal claims require appropriate evidence and design.
Common Mistakes
- Claiming the SSE is merely small. If every observed response equals its fitted value, each residual is exactly zero, so the SSE is exactly zero.
- Adding residuals before squaring and calling that the SSE. The SSE is the sum of squared residuals, \(\sum e_i^2\), not the square of their sum. Here both happen to be zero, but they are different calculations in general.
- Thinking positive and negative residuals cancel in the SSE. Squaring makes each contribution nonnegative. Cancellation cannot produce an SSE of zero unless every residual is zero.
- Generalizing the perfect fit beyond the data. An exact fit at the observed predictor values does not guarantee exact predictions for unobserved cases or establish a causal relationship.
Check Your Understanding
Use the definitions and calculations above to answer these questions.
- A dataset has three observed pairs, and each response equals \(4+2x_i\). What are the residuals and SSE for the line with intercept 4 and slope 2?
- Why can no candidate line have an SSE below zero?
- For the observations \((1,7)\), \((2,10)\), and \((3,13)\), what exact line fits the data? Verify the fitted responses.
- If the observed responses equal their fitted values, what does that tell you about the individual residuals?
- Does a zero SSE for one dataset prove that the predictor causes the response to change? Explain briefly.