Why do we square the residuals in regression?
By Jude Wallis · Published
Because residuals add up to zero for any line through the mean point, so the plain sum cannot tell a good line from a terrible one. Squaring removes the sign so nothing cancels, makes big misses count far more than small ones, and leaves exactly one best line.
AP Statistics: Unit 5 (topics 5.4 Residuals, 5.5 Least-Squares Regression). This sits behind Unit 5 topics 5.4 and 5.5 of the Fall 2026 course: residuals are observed minus predicted, and the least-squares line is defined as the one minimizing the sum of their squares.
Why we square the residuals
A residual is the observed value minus the predicted value, . Points above the line have positive residuals, points below it have negative residuals.
Now try the obvious idea: add the residuals up and keep the line with the smallest total. It breaks immediately. For any line that passes through the mean point , the residuals add to exactly zero, because the positives and the negatives cancel. A line that misses one point by and another by scores the same zero as a line that hits both points exactly.
Squaring fixes that in one move:
Every squared residual is positive or zero, so nothing cancels. Large misses count far more than small ones. And this total has exactly one smallest value, so there is one winner. That winning line is the least-squares regression line your calculator reports, and it is where the name comes from.
Adding the residuals fails twice
Write out the total for a line fitted to points:
Two separate things go wrong with that quantity.
There is no smallest sum. Slide the whole line upward by raising . Every point now sits below the line, every residual turns negative, and the total marches off toward negative infinity. The rule "make the sum of residuals as small as possible" would pick a line floating far above your data, then a line above that one, forever. Nothing stops it.
Forcing the sum to zero still does not pick one line. The expression above equals zero exactly when , which says the line runs through . Infinitely many lines do that: one for every slope you can name. A flat line at qualifies. So does a nearly vertical one. They all tie at zero.
The lesson is that the sum of residuals measures balance, not accuracy. It tells you the line has as much data above it as below it, weighted by distance, and nothing more. There is one useful side effect: because the least-squares line passes through the mean point, its residuals sum to zero and their mean is zero, which is why the reference line on a residual plot is drawn at zero.
Why not just take absolute values?
Absolute values kill the sign too. You could pick the line that minimizes , and unlike the plain sum, that criterion really does rank lines. It is a genuine method, called least absolute deviations, and statisticians use it. Three reasons squares won the argument for AP Statistics and for almost every piece of software.
- Squares produce a formula. The absolute value function has a sharp corner at zero, and that corner blocks the calculus that solves for the best line. Squares are smooth, so the answer comes out in closed form: and . Least absolute deviations has to be searched for numerically.
- Squares give one answer. The squared total is a parabola in the slope, and a parabola has a single lowest point. The absolute-value total is made of straight pieces joined at corners, and its bottom can be flat, leaving several lines tied for best.
- Squares match the rest of the course. Variance, standard deviation, , and are all built from squared deviations. Fitting with squares keeps the line, the spread, and the correlation on the same footing.
The honest cost: absolute values resist outliers better. Squaring is exactly what lets one far-out point swing the whole line, which is the tradeoff the next section describes.
Squaring makes big misses hurt more
Squaring does more than delete minus signs. It changes how the misses are ranked against each other. Double a residual and its contribution quadruples. A miss of 4 costs 16 while a miss of 1 costs 1, so four times the error costs sixteen times as much.
Compare two error patterns of the same total size across four points. Pattern A misses every point by 3. Pattern B is exact at three points and off by 12 at the fourth. These are miss sizes chosen to isolate the ranking question, so the sign bookkeeping of the previous section is set aside here.
| Pattern | Sizes of the misses | Sum of absolute values | Sum of squares |
|---|---|---|---|
| A | 3, 3, 3, 3 | 12 | 36 |
| B | 0, 0, 0, 12 | 12 | 144 |
Absolute values call it a tie. Squares prefer pattern A by a factor of four. Least squares would rather be a little wrong everywhere than badly wrong once.
That preference has a price. Because one large residual dominates the total, a single unusual point can drag the line toward itself. The least-squares line is not resistant, in the same way the mean is not resistant and the median is. Drag a point around in the influential point interactive and watch the line chase it.
Squares leave exactly one best line
Here is the uniqueness argument in one line of algebra. Restrict attention to lines through . Any line that misses the mean point can be slid vertically onto it, and that shift strictly lowers the sum of squared residuals, so the winner has to be one of them. Write and . A line with slope has residual at each point, so the total is
Read the shape rather than the symbols. As a function of the slope , that is a quadratic whose coefficient, , is positive as long as the x-values are not all identical. A parabola opening upward has exactly one lowest point. That is the entire argument, and its vertex sits at
which is the same slope as . So squaring does not just rank lines, it names one, and it is the only criterion in this discussion guaranteed to. Absolute deviations usually name a single line as well, but nothing rules out a tie. The second worked example below runs this parabola on real numbers.
The same squaring runs through the whole course
Squared deviations are not a regression trick. They are how AP Statistics measures spread everywhere.
- Variance is a total of squared deviations from the mean, divided by for a sample, and the standard deviation is its square root. Same idea, applied to one variable instead of to a line.
- The mean is the single number that minimizes . A median minimizes , and when is even every value between the two middle observations ties for that minimum, the same non-uniqueness that argues against absolute values for the line. Same contest, different penalty, different winner, which is one more angle on mean versus median.
- The coefficient of determination compares two of these totals: . Both pieces are squared quantities, so only exists because the fit was defined with squares in the first place. See r versus r-squared.
That is the real reason the convention stuck. Squares make the line, the spread, the correlation, and parts of one system instead of four unrelated recipes.
What the AP exam actually asks
You will not be asked to derive the least-squares line. Coefficients come from technology, and Unit 5 makes up 10 to 20 percent of the multiple-choice section. What does get tested:
- Saying what the line minimizes. The least-squares regression line minimizes the sum of the squares of the residuals (Topic 5.5). Write that sentence, not "it is the line closest to the points."
- Knowing that least-squares residuals sum to zero, so their mean is zero and a residual plot is read against a horizontal line at zero (Topic 5.4).
- Knowing the line is not resistant, so an influential point can move the slope a long way.
- Computing residuals as observed minus predicted, and squaring and adding them if a question asks for the total.
For the mechanics of finding the line, see the least-squares regression line, or run a data set through the regression calculator.
Three candidate lines, and why adding the residuals cannot rank them
Five points: , , , , . Compare three candidate lines. Line A is the least-squares line , line B is the flat line , and line C is , which sits well above the data. For each, add the residuals and add the squared residuals, then say which criterion is doing useful work.
Find the mean point. and . Line A gives at , and line B gives 6 everywhere, so both pass through .
Line A residuals. Predicted values are , so the residuals are , , , , .
Line A totals. Sum: . Sum of squares: .
Line B residuals. The predicted value is 6 for every point, so the residuals are .
Line B totals. Sum: . Sum of squares: .
Line C residuals. Line C is line A raised by 9.7, so every residual drops by 9.7: .
Line C totals. Sum: . Sum of squares: .
Read the plain sums. Lines A and B tie at 0 even though B ignores the trend completely, and line C beats both with . Raise line C further and the sum drops further, with no bottom.
Read the squared sums. for A, for B, for C. The ranking now matches what your eye sees, and no line beats A's .
Bonus check. Line B's total, 38, is the total squared distance of the y-values from , so , matching squared.
All three sums of residuals are useless: A and B tie at 0, and the absurd line C 'wins' with and can be pushed lower forever. The sums of squared residuals rank the lines honestly at , , and , and is the smallest any line can achieve for this data.
The squared total is a parabola with one lowest point
Use the same five points. Consider three lines through the mean point : , , and . Show that the plain sum of residuals cannot separate them, then find the slope that minimizes the sum of squared residuals.
Check the mean point. At : , , and . All three pass through , so all three have residuals summing to zero and the plain-sum rule cannot choose between them.
Slope 1.5. Predicted: . Residuals: , which sum to 0. Squares: .
Slope 1.9. Predicted: . Residuals: , which sum to 0. Squares: .
Slope 2.3. Predicted: . Residuals: , which sum to 0. Squares: .
Build the general formula. The x-deviations are and the y-deviations are , so , , and .
Substitute into to get the total as a function of the slope: .
Verify against the three lines. At : . At : . At : . All three match the hand computations.
Find the vertex of the parabola: , which also equals .
Every line through has residuals summing to zero, so adding cannot rank them. The squared totals are at slope 1.5, at slope 1.9, and at slope 2.3. Written out, the total is , an upward parabola whose single lowest point is at , the least-squares slope.
Frequently asked questions
Do the residuals always add up to zero?
For the least-squares line, yes, and more generally for any line through the mean point . That is exactly why the plain sum cannot judge a fit, and why the reference line on a residual plot sits at zero.
Why not use absolute values instead of squares?
You can, and the method exists: least absolute deviations. It has no closed-form solution because the absolute value function has a corner at zero, it can leave several lines tied for best, and it does not connect to variance, , or . Its one advantage is resistance to outliers.
Why not cube the residuals or raise them to the fourth power?
Cubing keeps the sign, since a negative number cubed is still negative, so the cancellation problem comes straight back. Even powers do work, but higher ones punish outliers far more and break the link to the mean, the variance, and . Two is the smallest even power, and it is the one that gives the mean.
Does squaring change the units of the answer?
Yes. The sum of squared residuals is in squared units of , which is why nobody reports it raw. It gets turned into something readable first, either by taking a square root to return to y's units or by converting it into the unitless proportion .