Once we have a least-squares regression line to make predictions, we need a way to measure how well that line actually fits the data.
1
Residuals: Actual Minus Predicted
For any single data point, we check how far off the line is by finding its residual: the vertical gap between the point's actual value and the value the regression line predicts at that same x.
Using the line Predicted Score=50+5×Hours Studied, we can find the residual for a student who studied 5 hours and earned an actual score of 82.
Residuals: Actual Minus Predicted
Text solution
Plug x=5 into the regression lineFind the score the line predicts for 5 hours of studying.
Predicted Score=50+5(5)=75
Subtract predicted from actualSubtract the line's prediction from the student's actual score of 82 to find how far off the prediction is.
Residual=Actual82−Predicted75=+7 points
So the student's residual is +7 points, meaning their actual score was 7 points above the line's prediction. For the student who studied 5 hours and scored 65, the residual is 65−75=−10 points because their dot sits 10 points below the line.
Watch the wording here: a negative residual means the actual point lies below the line, which means the line's prediction was too high, so it overestimated the actual value. A positive residual means the actual point lies above the line, so the line underestimated it.
2
Building and Reading a Residual Plot
Checking one residual tells us how the line did for a single point, but to tell whether a straight line is the right model for the whole dataset, we need to see all the residuals at once. A residual plot flattens the regression line into a horizontal line at 0, keeping the original x-variable on the horizontal axis and plotting each point's residual on the vertical axis.
Here is how we build the residual plot for five students at (1,50),(3,69),(5,82),(7,79), and (9,95), and use the overall pattern to judge the line.
Building and Reading a Residual Plot
Text solution
Find the predicted score and residual at each x-valuePlug each student's study hours into Predicted Score=50+5×Hours Studied, then subtract Actual−Predicted.
Plot (x,Residual) around the horizontal zero lineGraph the points (1,−5),(3,+4),(5,+7),(7,−6), and (9,0) with Hours Studied on the horizontal axis and Residual on the vertical axis.
However far a data point sits above, on, or below the slanted regression line on the scatter plot, its matching point on the residual plot sits that exact same vertical distance above, on, or below the horizontal line at 0.
Each point’s vertical gap from the regression line is its exact height above or below 0 on the residual plot.
Once the regression line is flattened to 0, any pattern left over in the residual plot is a pattern the straight line missed.
3
The Standard Deviation of the Residuals, s
When the residual plot shows random scatter, we know a straight line is the right shape for the data, and the next question is how far off the line's predictions typically are. The standard deviation of the residuals, s, measures the typical size of a prediction error in the same units as y.
The Standard Deviation of the Residuals, s
Text solution
Check that the residuals add up to zeroAdding the residuals directly always gives 0 because the positive residuals above the least-squares line cancel the negative residuals below it.
−5+4+7−6+0=0
Square each residual and add the squaresSquare every residual so the negative errors become positive before adding them together.
Divide by n−2 and take the square rootDivide the sum of squared residuals by the number of data points minus 2, then take the square root to bring the units back to test score points.
s=number of points minus 2n−2∑residual2=5−2126=42≈6.48 points
For a full class where s=5 points, when we use hours studied to predict a student's test score with this line, our predictions are typically off by about 5 points.
4
What r2 Measures
Knowing that our predictions are typically off by 5 points doesn't tell us how much better the line is than just guessing the average score for everyone. The number r2 measures the fraction of the original variation in y (around the flat average line) that the least-squares regression line eliminates.
Here we compare the 1,000 units of total squared error around the class average score of 70 with the 200 units of squared error left over in the residuals around the regression line.
What r-squared Measures
Text solution
Subtract the leftover residual error from the starting total errorFind how much of the squared error around the horizontal average line was removed by using the regression line.
Divide by the starting total errorDivide the eliminated squared error by the starting total squared error around the average line.
r2=1,000800=0.80=80%
So about 80% of the variation in test scores is accounted for by the linear model relating test score to hours studied, while the remaining 20% stays left over in the residuals.
As we switch from the horizontal class-average line at 70 to the slanted least-squares line, the squared vertical gaps shrink, and r2 is the percentage of the starting squared error around the average that the linear model removes.
Tilting the line from the flat class average to the best-fitting line removes the biggest possible share of the squared error, and that share is r-squared.
5
Connecting r and r2, and Why Residual Plots Still Matter
The fraction of variation explained by the line, r2, is literally the square of the correlation r (where −1≤r≤+1). We can convert directly between r and r2, and then see why even a huge r2 cannot replace checking the residual plot.
Connecting r and r-squared, and Why Residual Plots Still Matter
Text solution
Square the correlation r to find r2Whether the line slopes upward (r=+0.90) or downward (r=−0.90), squaring removes the sign and gives the same positive r2.
r2=(+0.90)2=(−0.90)2=0.81=81%
Take the square root of r2 and match the slope's sign to find rWhen r2=64%=0.64, take the square root of the decimal to get the size of r, then look at the slope of the line to pick + or −.
0.64=0.80⟹r=⎩⎨⎧+0.80−0.80if the lineslopes upward(positive slope)if the lineslopes downward(negative slope)
Even when data is clearly curved, the points can still lie much closer to a slanted line than to the flat average line. That gives a high r2 even though a straight line is the wrong shape, which is why we still need the residual plot:
A rising curve still sits much closer to the slanted line than to the flat average line, keeping r-squared high even when the residual plot shows a straight line is the wrong shape.
6
Reading Computer Regression Output
In practice, software computes the regression line, s, and r2 and prints them in a summary table. To read the table, we only use the `Predictor` and `Coef` columns and the bottom row (`S` and `R-Sq`).
Reading Computer Regression Output
Text solution
Read the y-intercept and slope from the `Coef` columnThe `Constant` coefficient is the y-intercept (92.40), and the `Absences` coefficient is the slope (−3.50) multiplying the x-variable.
Read s and r2 from the bottom rowTake `S` for the standard deviation of the residuals and regular `R-Sq` (ignoring `R-Sq(adj)`) for r2.
s=4.20 points,r2=81.0%=0.81
Calculate r from `R-Sq` and the slope's signTake the square root of regular `R-Sq` as a decimal, and make r negative because the slope for `Absences` (−3.50) is negative.
r=−0.81=−0.90
Using this line to predict a student's final grade from their absences will typically be off by about 4.20 points, and the linear model accounts for 81.0% of the variation in final grades.
Key concepts
Every tool here looks at the vertical gaps between the actual data points and the regression line's predictions, moving from a single point out to the whole dataset:
Error for one point (Residual)
Plug x into the regression line to get the predicted value, then subtract in the order
Residual=Actual−Predicted
For Predicted Score=50+5(5)=75 and an actual score of 82, the residual is 82−75=+7 points (dot is above the line, so the line underestimated). If the actual score is 65, the residual is 65−75=−10 points (dot is below the line, so the line overestimated).
Checking whether a straight line fits (Residual Plot)
Plot (x,Residual) around a horizontal line at 0. We want random scatter evenly above and below 0. Do not use r2 to check whether a line is the right shape: even if r2>90%, a curve in the residual plot means the data is curved and a straight line is the wrong model, while a fan shape means predictions are accurate where dots sit close to 0 and unreliable where they spread out.
Typical size of a prediction error (s)
Do not average the residuals directly, because the residuals from a least-squares line always add up to 0 (∑residual=0, which lets you find a missing residual if you know all the others). Instead, square them, divide by n−2, and take the square root:
s=n−2∑residual2
s is always measured in the units of y:s=5 points means predictions from the line are typically off by about 5 points.
Share of variation explained (r2 and r)
Compare the leftover squared error in the residuals to the starting total squared error around the horizontal average line yˉ:
r2=total error around averagetotal error around average−leftover error in residuals
Cutting the squared error from 1,000 down to 200 removes 1,0001,000−200=80% of the variation in y. Because r2 is the correlation r, squared, go backward by taking r=±r2 and matching the sign of the slope: on a computer table with `Constant Coef = 92.40`, `Absences Coef = -3.50`, and `R-Sq = 81.0%` (ignore `SE Coef`, `T`, `P`, and `R-Sq(adj)`), the slope is negative, so r=−0.81=−0.90.
7
Practice
1
A least-squares regression line predicting a student's quiz score (out of 50) from the number of practice problems completed is Predicted Score=20+2×Problems Completed. A student completes 12 practice problems and earns an actual score of 41. Find the student's residual and state whether the line overestimated or underestimated their score.
Reversing the order to 44−41 gives the common wrong answer +3 points.
Plug 12 into the line to find the predicted score first, then check the subtraction order in Residual=Actual−Predicted and compare the line's prediction to 41.
Plug 12 practice problems into the regression line to get the predicted score:
Predicted Score=20+2(12)=44
Subtract predicted from actual (watch out: reversing the order to 44−41 gives the common wrong answer +3 points):
Residual=Actual−Predicted=41−44=−3 points
Be careful not to read the negative sign in −3 as "underestimated": because the residual is negative (the student's actual dot is 3 points below the line's prediction of 44), the line overestimated the student's score by 3 points.
2
Using the same regression line, Predicted Score=20+2×Problems Completed, another student completed 8 practice problems and had a residual of +5 points. What was this student's actual quiz score?
Subtracting 36−5=31 treats the +5 residual as if the actual score were below the line.
Find the predicted score for 8 problems first, then substitute that prediction and the residual +5 into Residual=Actual−Predicted.
The predicted score for 8 problems is:
Predicted Score=20+2(8)=36
Substitute the residual +5 and the predicted score 36 into the residual formula (watch out: subtracting 36−5=31 treats the +5 residual as if the actual score were below the line):
Residual+5Actual=Actual−Predicted=Actual−36=41
3
A least-squares regression line is used to predict the monthly heating cost of houses (in dollars) from their floor area (in square feet). In the residual plot, the dots are scattered above and below 0 with no curve, but they are clustered tightly near 0 for small houses and fan out widely above and below 0 for large houses. What does this residual plot tell you about using the line to make predictions?
Separate what the lack of a curve tells you about the overall trend from what the widening vertical spread around 0 tells you about prediction accuracy for small versus large houses.
Do not confuse a fan shape with a curved pattern: because there is no curve and the residuals are scattered above and below 0, a straight line captures the overall trend, but the fanning pattern shows that the line's predictions are very accurate for small houses and unreliable (often off by large amounts in either direction) for large houses.
4
A least-squares regression line is fit to 6 data points predicting a plant's height (in centimeters) from the amount of fertilizer used (in grams). Five of the six residuals are +7,+4,+2,−1, and −5. Find the sixth residual, calculate s (the standard deviation of the residuals), and explain what s means in context.
Forgetting to flip the sign leaves +7, which makes the residuals add up to +14.
Use the fact that all 6 residuals around a least-squares line must add up to 0 to find the missing residual, then square all six, add them, and divide by n−2 inside the square root.
Because the residuals from a least-squares line always add up to 0, add the first five residuals:
7+4+2−1−5=+7
To make all six add up to 0, the sixth residual is −7 (watch out: forgetting to flip the sign leaves +7, which makes the residuals add up to +14).
Square all six residuals and add them up:
72+42+22+(−1)2+(−5)2+(−7)2=49+16+4+1+25+49=144
Divide by n−2=6−2=4 and take the square root (watch out: dividing by n=6 gives 24≈4.90 cm, and forgetting the square root leaves 36 cm):
s=6−2144=4144=36=6 centimeters
When using this line to predict a plant's height from the amount of fertilizer used, the predictions are typically off by about 6 centimeters.
5
When predicting the selling price of used bicycles from their age, using the overall average price for every bicycle gives a total squared error of 800. Using the least-squares regression line leaves 120 units of squared error in the residuals. Calculate r2 and explain what it means in this context.
Dividing the leftover error directly gives 120÷800=15%, which is the unexplained share left in the residuals.
First subtract to find how many of the 800 units of squared error the regression line eliminated, then divide that eliminated error by 800.
Find the squared error eliminated by the regression line:
800−120=680
Divide the eliminated error by the starting total error of 800 (watch out: dividing the leftover error directly gives 120÷800=15%, which is the unexplained share left in the residuals):
r2=800680=0.85=85%
About 85% of the variation in the selling prices of the used bicycles is accounted for by the linear model relating selling price to age, while the remaining 15% of the variation is left over in the residuals.
6
Computer regression output for predicting a car's Fuel Efficiency (in miles per gallon) from its Weight (in thousands of pounds) gives: Predictor Constant Coef=48.00 (SE Coef=2.10,T=22.86,P=0.000); Predictor Weight Coef=−5.00 (SE Coef=0.60,T=−8.33,P=0.000); and at the bottom, S=2.50,R-Sq=64.0%,R-Sq(adj)=62.5%. Write the equation of the least-squares regression line, interpret S in context, and find the correlation r.
Use 48.00 (Constant Coef) as the y-intercept and −5.00 (Weight Coef) as the slope: do not swap them into −5.00+48.00×Weight.
Read the y-intercept (`Constant`) and slope (`Weight`) from the `Coef` column. To find r, take the square root of regular `R-Sq` as a decimal and match the sign of the `Weight` slope.
Using `Constant Coef = 48.00` as the y-intercept and `Weight Coef = -5.00` as the slope (watch out: do not swap them into −5.00+48.00×Weight), the least-squares regression line is:
Predicted Fuel Efficiency=48.00−5.00×Weight
S=2.50 means that when using this line to predict a car's fuel efficiency from its weight, predictions will typically be off by about 2.50 miles per gallon.
To find r, use regular R-Sq=64.0%=0.64 rather than R-Sq(adj)=62.5%, take the square root 0.64=0.80, and attach a negative sign because the slope for Weight is −5.00 (leaving off the sign gives the common wrong answer +0.80):
r=−0.80
7
A student fits a straight line to predict braking distance from car speed and gets r2=94%. However, the residual plot shows residuals that are positive at low and high speeds and negative in the middle speeds. The student argues that because r2 is 94%, a straight line is the right model for the data. Explain why the student is mistaken and describe where the line consistently misses the data.
Recall what r2 compares the line against versus what a curved pattern in the residual plot tells you, and use Residual=Actual−Predicted to link the sign of the residuals to whether the line underestimated or overestimated.
A high r2 only means that the straight line accounts for 94% of the variation in braking distances compared to guessing the overall average; it does not prove that a straight line is the right shape. The clear curve in the residual plot shows that the original relationship between speed and braking distance is curved, so a straight line is the wrong model (watch out for the sign direction: a positive residual means Actual>Predicted, so the line's prediction is too low, not too high): it consistently underestimates braking distance at low and high speeds (positive residuals) and overestimates braking distance at middle speeds (negative residuals).