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, yy^y - \hat{y}. 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 (xˉ,yˉ)(\bar{x}, \bar{y}), the residuals add to exactly zero, because the positives and the negatives cancel. A line that misses one point by +50+50 and another by 50-50 scores the same zero as a line that hits both points exactly.

Squaring fixes that in one move:

sum of squared residuals=(yiy^i)2\text{sum of squared residuals} = \sum (y_i - \hat{y}_i)^2

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 y^=a+bx\hat{y} = a + bx fitted to nn points:

(yiy^i)=(yiabxi)=n(yˉabxˉ)\sum (y_i - \hat{y}_i) = \sum (y_i - a - bx_i) = n(\bar{y} - a - b\bar{x})

Two separate things go wrong with that quantity.

There is no smallest sum. Slide the whole line upward by raising aa. 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 yˉ=a+bxˉ\bar{y} = a + b\bar{x}, which says the line runs through (xˉ,yˉ)(\bar{x}, \bar{y}). Infinitely many lines do that: one for every slope you can name. A flat line at yˉ\bar{y} 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 yiy^i\sum |y_i - \hat{y}_i|, 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: b=rsysxb = r \cdot \frac{s_y}{s_x} and a=yˉbxˉa = \bar{y} - b\bar{x}. 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, rr, and r2r^2 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.

PatternSizes of the missesSum of absolute valuesSum of squares
A3, 3, 3, 31236
B0, 0, 0, 1212144

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 (xˉ,yˉ)(\bar{x}, \bar{y}). 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 di=yiyˉd_i = y_i - \bar{y} and ei=xixˉe_i = x_i - \bar{x}. A line with slope bb has residual dibeid_i - be_i at each point, so the total is

(dibei)2=di22bdiei+b2ei2\sum (d_i - be_i)^2 = \sum d_i^2 - 2b\sum d_ie_i + b^2\sum e_i^2

Read the shape rather than the symbols. As a function of the slope bb, that is a quadratic whose b2b^2 coefficient, ei2\sum e_i^2, 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

b=dieiei2b = \frac{\sum d_ie_i}{\sum e_i^2}

which is the same slope as rsysxr \cdot \frac{s_y}{s_x}. 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 n1n-1 for a sample, and the standard deviation is its square root. Same idea, applied to one variable instead of to a line.
  • The mean yˉ\bar{y} is the single number cc that minimizes (yic)2\sum (y_i - c)^2. A median minimizes yic\sum |y_i - c|, and when nn 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: r2=1sum of squared residualssum of squared deviations of y from yˉr^2 = 1 - \frac{\text{sum of squared residuals}}{\text{sum of squared deviations of } y \text{ from } \bar{y}}. Both pieces are squared quantities, so r2r^2 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 r2r^2 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:

  1. 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."
  2. 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).
  3. Knowing the line is not resistant, so an influential point can move the slope a long way.
  4. 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: (1,2)(1, 2), (2,5)(2, 5), (3,5)(3, 5), (4,8)(4, 8), (5,10)(5, 10). Compare three candidate lines. Line A is the least-squares line y^=0.3+1.9x\hat{y} = 0.3 + 1.9x, line B is the flat line y^=6\hat{y} = 6, and line C is y^=10+1.9x\hat{y} = 10 + 1.9x, which sits well above the data. For each, add the residuals and add the squared residuals, then say which criterion is doing useful work.

  1. Find the mean point. xˉ=1+2+3+4+55=155=3\bar{x} = \frac{1+2+3+4+5}{5} = \frac{15}{5} = 3 and yˉ=2+5+5+8+105=305=6\bar{y} = \frac{2+5+5+8+10}{5} = \frac{30}{5} = 6. Line A gives 0.3+1.9(3)=60.3 + 1.9(3) = 6 at x=3x = 3, and line B gives 6 everywhere, so both pass through (3,6)(3, 6).

  2. Line A residuals. Predicted values are 2.2,4.1,6.0,7.9,9.82.2, 4.1, 6.0, 7.9, 9.8, so the residuals are 22.2=0.22 - 2.2 = -0.2, 54.1=0.95 - 4.1 = 0.9, 56.0=1.05 - 6.0 = -1.0, 87.9=0.18 - 7.9 = 0.1, 109.8=0.210 - 9.8 = 0.2.

  3. Line A totals. Sum: 0.2+0.91.0+0.1+0.2=0-0.2 + 0.9 - 1.0 + 0.1 + 0.2 = 0. Sum of squares: 0.04+0.81+1.00+0.01+0.04=1.900.04 + 0.81 + 1.00 + 0.01 + 0.04 = 1.90.

  4. Line B residuals. The predicted value is 6 for every point, so the residuals are 4,1,1,2,4-4, -1, -1, 2, 4.

  5. Line B totals. Sum: 411+2+4=0-4 - 1 - 1 + 2 + 4 = 0. Sum of squares: 16+1+1+4+16=3816 + 1 + 1 + 4 + 16 = 38.

  6. Line C residuals. Line C is line A raised by 9.7, so every residual drops by 9.7: 9.9,8.8,10.7,9.6,9.5-9.9, -8.8, -10.7, -9.6, -9.5.

  7. Line C totals. Sum: 9.98.810.79.69.5=48.5-9.9 - 8.8 - 10.7 - 9.6 - 9.5 = -48.5. Sum of squares: 98.01+77.44+114.49+92.16+90.25=472.3598.01 + 77.44 + 114.49 + 92.16 + 90.25 = 472.35.

  8. Read the plain sums. Lines A and B tie at 0 even though B ignores the trend completely, and line C beats both with 48.5-48.5. Raise line C further and the sum drops further, with no bottom.

  9. Read the squared sums. 1.901.90 for A, 3838 for B, 472.35472.35 for C. The ranking now matches what your eye sees, and no line beats A's 1.901.90.

  10. Bonus check. Line B's total, 38, is the total squared distance of the y-values from yˉ\bar{y}, so r2=11.9038=10.05=0.95r^2 = 1 - \frac{1.90}{38} = 1 - 0.05 = 0.95, matching r0.9747r \approx 0.9747 squared.

All three sums of residuals are useless: A and B tie at 0, and the absurd line C 'wins' with 48.5-48.5 and can be pushed lower forever. The sums of squared residuals rank the lines honestly at 1.901.90, 3838, and 472.35472.35, and 1.901.90 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 (3,6)(3, 6): y^=1.5+1.5x\hat{y} = 1.5 + 1.5x, y^=0.3+1.9x\hat{y} = 0.3 + 1.9x, and y^=0.9+2.3x\hat{y} = -0.9 + 2.3x. Show that the plain sum of residuals cannot separate them, then find the slope that minimizes the sum of squared residuals.

  1. Check the mean point. At x=3x = 3: 1.5+4.5=61.5 + 4.5 = 6, 0.3+5.7=60.3 + 5.7 = 6, and 0.9+6.9=6-0.9 + 6.9 = 6. All three pass through (3,6)(3, 6), so all three have residuals summing to zero and the plain-sum rule cannot choose between them.

  2. Slope 1.5. Predicted: 3.0,4.5,6.0,7.5,9.03.0, 4.5, 6.0, 7.5, 9.0. Residuals: 1.0,0.5,1.0,0.5,1.0-1.0, 0.5, -1.0, 0.5, 1.0, which sum to 0. Squares: 1.00+0.25+1.00+0.25+1.00=3.501.00 + 0.25 + 1.00 + 0.25 + 1.00 = 3.50.

  3. Slope 1.9. Predicted: 2.2,4.1,6.0,7.9,9.82.2, 4.1, 6.0, 7.9, 9.8. Residuals: 0.2,0.9,1.0,0.1,0.2-0.2, 0.9, -1.0, 0.1, 0.2, which sum to 0. Squares: 0.04+0.81+1.00+0.01+0.04=1.900.04 + 0.81 + 1.00 + 0.01 + 0.04 = 1.90.

  4. Slope 2.3. Predicted: 1.4,3.7,6.0,8.3,10.61.4, 3.7, 6.0, 8.3, 10.6. Residuals: 0.6,1.3,1.0,0.3,0.60.6, 1.3, -1.0, -0.3, -0.6, which sum to 0. Squares: 0.36+1.69+1.00+0.09+0.36=3.500.36 + 1.69 + 1.00 + 0.09 + 0.36 = 3.50.

  5. Build the general formula. The x-deviations are 2,1,0,1,2-2, -1, 0, 1, 2 and the y-deviations are 4,1,1,2,4-4, -1, -1, 2, 4, so ei2=4+1+0+1+4=10\sum e_i^2 = 4+1+0+1+4 = 10, diei=8+1+0+2+8=19\sum d_ie_i = 8+1+0+2+8 = 19, and di2=16+1+1+4+16=38\sum d_i^2 = 16+1+1+4+16 = 38.

  6. Substitute into di22bdiei+b2ei2\sum d_i^2 - 2b\sum d_ie_i + b^2\sum e_i^2 to get the total as a function of the slope: 10b238b+3810b^2 - 38b + 38.

  7. Verify against the three lines. At b=1.5b = 1.5: 22.557+38=3.5022.5 - 57 + 38 = 3.50. At b=1.9b = 1.9: 36.172.2+38=1.9036.1 - 72.2 + 38 = 1.90. At b=2.3b = 2.3: 52.987.4+38=3.5052.9 - 87.4 + 38 = 3.50. All three match the hand computations.

  8. Find the vertex of the parabola: b=382(10)=1.9b = \frac{38}{2(10)} = 1.9, which also equals dieiei2=1910\frac{\sum d_ie_i}{\sum e_i^2} = \frac{19}{10}.

Every line through (3,6)(3, 6) has residuals summing to zero, so adding cannot rank them. The squared totals are 3.503.50 at slope 1.5, 1.901.90 at slope 1.9, and 3.503.50 at slope 2.3. Written out, the total is 10b238b+3810b^2 - 38b + 38, an upward parabola whose single lowest point is at b=1.9b = 1.9, 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 (xˉ,yˉ)(\bar{x}, \bar{y}). 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, sys_y, or r2r^2. 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 r2r^2. 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 yy, 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 r2r^2.