StatisticsExploring Two-Variable Data4 of 8
Exploring Two-Variable Data · 4

The Least-Squares Regression Line

When two variables show a straight-line trend on a scatterplot, we need a way to find the exact equation of the single line through the points that gives the best predictions of y\data{y} from x\data{x}.

1

Why Least Squares Minimizes Squared Gaps

We want to measure how well any line we try fits a scatterplot of points so we can find the single best prediction line. Suppose five students record the hours they spent practicing for a 10-point quiz (x\data{x}) and their quiz scores (y\data{y}) at (1,2)\data{(1, 2)}, (2,5)\data{(2, 5)}, (3,4)\data{(3, 4)}, (4,7)\data{(4, 7)}, and (5,7)\data{(5, 7)}, and we want to draw a line through the points to predict the score for a sixth student who practiced for 3.5\data{3.5} hours.

Residuals and Why Least Squares Minimizes Squared Gaps
11
22
33
44
55
22
44
66
88
1010
00
y: quiz score (out of 10)\htmlClass{lc-blue}{y}\htmlClass{lc-ink}{\text{: quiz score (out of 10)}}
x: hours practicing\htmlClass{lc-blue}{x}\htmlClass{lc-ink}{\text{: hours practicing}}
x\htmlClass{lc-blue}{x}
y\htmlClass{lc-blue}{y}
12345\htmlClass{lc-blue}{\begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ 5 \end{array}}
25477\htmlClass{lc-blue}{\begin{array}{c} 2 \\ 5 \\ 4 \\ 7 \\ 7 \end{array}}

For any input x\data{x}, the height of the line gives the predicted value y^\fit{\hat{y}} (read "y\fit{y}-hat"; the hat tells us it is a prediction on the line, not an actual data value y\data{y}). Each point's vertical distance from the line is its residual:

Residual\displaystyle \resid{\text{Residual}} =y⏟actual−y^⏟predicted\displaystyle = \underbrace{\data{y}}_{\data{\text{actual}}} - \underbrace{\fit{\hat{y}}}_{\fit{\text{predicted}}}

We always subtract in the order actual−predicted\data{\text{actual}} - \fit{\text{predicted}} so the sign matches the picture: a point above the line is higher than the prediction and has a positive residual, while a point below the line has a negative residual.

11
22
33
44
55
22
44
66
88
00
Hours practicing\htmlClass{lc-ink}{\text{Hours practicing}}
Quiz score\htmlClass{lc-ink}{\text{Quiz score}}
1.22\htmlClass{lc-orange}{1.2^2}
Residual=y−y^=5−3.8=+1.2\begin{aligned} \htmlClass{lc-orange}{\text{Residual}} &= \htmlClass{lc-blue}{y} - \htmlClass{lc-violet}{\hat{y}} \\ &= \htmlClass{lc-blue}{5} - \htmlClass{lc-violet}{3.8} \\ &= \htmlClass{lc-orange}{+1.2} \end{aligned}

Adding the plain residuals fails because positive errors above the line and negative errors below the line cancel out, and adding the unsigned vertical distances can give the same total error to many different lines. The least-squares regression line is the one line that minimizes the total area of the squares built on the vertical gaps:

Sum of squared residuals\displaystyle \resid{\text{Sum of squared residuals}} =∑(y−y^)2\displaystyle = \sum (\data{y} - \fit{\hat{y}})^2

See how the signed residuals and the squared areas change as we tilt a trial line through the five quiz points.

See how positive and negative residuals cancel out even on a bad line, while squaring them gives a total area that is smallest on only one best-fitting line.
2

Finding the Least-Squares Line from Data

Now that we know which line we are looking for, we want to find its equation y^=a+bx\fit{\hat{y}} = \fit{a} + \step{b}\data{x} directly from the five quiz points (1,2)\data{(1, 2)}, (2,5)\data{(2, 5)}, (3,4)\data{(3, 4)}, (4,7)\data{(4, 7)}, and (5,7)\data{(5, 7)}, and use it to predict the quiz score for 3.5\data{3.5} hours of practice.

Finding the Least-Squares Line from Data and Making Predictions
11
22
33
44
55
22
44
66
88
1010
00
y: quiz score (out of 10)\htmlClass{lc-blue}{y}\htmlClass{lc-ink}{\text{: quiz score (out of 10)}}
x: hours practicing\htmlClass{lc-blue}{x}\htmlClass{lc-ink}{\text{: hours practicing}}
x\htmlClass{lc-blue}{x}
y\htmlClass{lc-blue}{y}
12345\htmlClass{lc-blue}{\begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ 5 \end{array}}
25477\htmlClass{lc-blue}{\begin{array}{c} 2 \\ 5 \\ 4 \\ 7 \\ 7 \end{array}}
point\htmlClass{lc-violet}{\text{point}}
slope\htmlClass{lc-pink}{\text{slope}}
11
22
33
44
55
66
00
Hours practicing\htmlClass{lc-ink}{\text{Hours practicing}}
Quiz score\htmlClass{lc-ink}{\text{Quiz score}}
(xˉ,yˉ)=(3,5)\htmlClass{lc-violet}{(\bar{x}, \bar{y})} = \htmlClass{lc-violet}{(3, 5)}
step x=2\htmlClass{lc-pink}{\text{step } x} = \htmlClass{lc-pink}{2}
step y=2\htmlClass{lc-pink}{\text{step } y} = \htmlClass{lc-pink}{2}
step x=x−xˉstep y=y−yˉ\htmlClass{lc-pink}{\text{step } x} = \htmlClass{lc-blue}{x} - \htmlClass{lc-violet}{\bar{x}} \qquad \htmlClass{lc-pink}{\text{step } y} = \htmlClass{lc-blue}{y} - \htmlClass{lc-violet}{\bar{y}}
1.2\htmlClass{lc-pink}{1.2}
1.2\htmlClass{lc-pink}{1.2}
yˉ=5\htmlClass{lc-violet}{\bar{y}} = \htmlClass{lc-violet}{5}
a=1.4\htmlClass{lc-violet}{a} = \htmlClass{lc-violet}{1.4}
xˉ=3\htmlClass{lc-violet}{\bar{x}} = \htmlClass{lc-violet}{3}

Once the line is pinned at the point of means (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, each point pulls on the slope according to its horizontal and vertical steps from (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, and walking backward xˉ\means{\bar{x}} steps from yˉ\means{\bar{y}} lands on the yy-intercept at x=0\data{x} = \data{0}:

b=∑(x−xˉ)⏞step x(y−yˉ)⏞step y∑(x−xˉ)2,a=yˉ−bxˉ\displaystyle \begin{aligned} \step{b} &= \frac{\sum \overbrace{(\data{x} - \means{\bar{x}})}^{\step{\text{step } x}}\overbrace{(\data{y} - \means{\bar{y}})}^{\step{\text{step } y}}}{\sum (\data{x} - \means{\bar{x}})^2}, \\[6pt] \fit{a} &= \means{\bar{y}} - \step{b}\means{\bar{x}} \end{aligned}
Text solution
Pin the line at the point of meansAverage the hours x\data{x} and the scores y\data{y} to find the balance point (xˉ,yˉ)\means{(\bar{x}, \bar{y})} that the least-squares line must pass through.
xˉ=1+2+3+4+55=155=3yˉ=2+5+4+7+75=255=5\displaystyle \begin{aligned} \means{\bar{x}} &= \frac{\data{1} + \data{2} + \data{3} + \data{4} + \data{5}}{5} = \frac{15}{5} = \means{3} \\ \means{\bar{y}} &= \frac{\data{2} + \data{5} + \data{4} + \data{7} + \data{7}}{5} = \frac{25}{5} = \means{5} \end{aligned}
Multiply the steps from (3,5)\means{(3, 5)} and divide by the squared xx-steps to find the slopeFind (step x,step y)=(x−3,y−5)(\step{\text{step } x}, \step{\text{step } y}) = (\data{x} - \means{3}, \data{y} - \means{5}) for all five points, add their products, and divide by the sum of the squared horizontal steps.
∑(x−3)(y−5)=(−2)(−3)+(−1)(0)+(0)(−1)+(1)(2)+(2)(2)=6+0+0+2+4=12∑(x−3)2=(−2)2+(−1)2+02+12+22=4+1+0+1+4=10b=1210=1.2\displaystyle \begin{aligned} \sum (\data{x} - \means{3})(\data{y} - \means{5}) &= (\step{-2})(\step{-3}) + (\step{-1})(\step{0}) + (\step{0})(\step{-1}) + (\step{1})(\step{2}) + (\step{2})(\step{2}) \\ &= \positive{6} + 0 + 0 + \positive{2} + \positive{4} = \positive{12} \\[4pt] \sum (\data{x} - \means{3})^2 &= (\step{-2})^2 + (\step{-1})^2 + \step{0}^2 + \step{1}^2 + \step{2}^2 \\ &= 4 + 1 + 0 + 1 + 4 = \step{10} \\[4pt] \step{b} &= \frac{\positive{12}}{\step{10}} = \step{1.2} \end{aligned}
Walk backward from (3,5)\means{(3, 5)} to x=0\data{x} = \data{0} to find the yy-interceptStart at height yˉ=5\means{\bar{y}} = \means{5} at xˉ=3\means{\bar{x}} = \means{3} and subtract 3\means{3} backward steps of the slope b=1.2\step{b} = \step{1.2}.
a\displaystyle \fit{a} =5−3(1.2)\displaystyle = \means{5} - \means{3}(\step{1.2}) =5−3.6\displaystyle = \means{5} - 3.6 =1.4\displaystyle = \fit{1.4}
Write the line, plug in x=3.5\data{x} = \data{3.5} to predict, and subtract to find the residual at (2,5)\data{(2, 5)}Substitute a=1.4\fit{a} = \fit{1.4} and b=1.2\step{b} = \step{1.2} into y^=a+bx\fit{\hat{y}} = \fit{a} + \step{b}\data{x}, then find y^\fit{\hat{y}} at x=3.5\data{x} = \data{3.5} and at x=2\data{x} = \data{2}.
y^=1.4+1.2xy^x=3.5=1.4+1.2(3.5)=1.4+4.2=5.6y^x=2=1.4+1.2(2)=1.4+2.4=3.8Residualx=2=5−3.8=+1.2\displaystyle \begin{aligned} \fit{\hat{y}} &= \fit{1.4} + \step{1.2}\data{x} \\ \fit{\hat{y}}_{\data{x=3.5}} &= \fit{1.4} + \step{1.2}(\data{3.5}) = \fit{1.4} + 4.2 = \fit{5.6} \\ \fit{\hat{y}}_{\data{x=2}} &= \fit{1.4} + \step{1.2}(\data{2}) = \fit{1.4} + 2.4 = \fit{3.8} \\ \resid{\text{Residual}}_{\data{x=2}} &= \data{5} - \fit{3.8} = \resid{+1.2} \end{aligned}

So a student who practices for 3.5\data{3.5} hours has a predicted quiz score of 5.6\fit{5.6} points (starting from a predicted 1.4\fit{1.4} points at 0\data{0} hours and rising by a predicted 1.2\step{1.2} points per additional hour), and the student at (2,5)\data{(2, 5)} scored 1.2\resid{1.2} points higher than the line predicted for 2\data{2} hours. Always include the word predicted (or on average) when interpreting the slope or intercept: the line tells us what score to expect on average, not a guaranteed change for every person.

With the line pinned at (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, points to the upper right or lower left of (xˉ,yˉ)\means{(\bar{x}, \bar{y})} have a positive step product and pull the slope upward, while points to the upper left or lower right pull it downward, and points further out horizontally from xˉ\means{\bar{x}} pull much harder on the slope.

The line stays pinned to the center point, tilting with each point's horizontal and vertical steps from that center and walking backward from it to hit the vertical axis.
3

Finding the Line from Summary Statistics

When we aren't given the individual data points to measure steps from (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, we can find the slope b\step{b} and intercept a\fit{a} from the group's summary statistics: the means xˉ,yˉ\means{\bar{x}}, \means{\bar{y}}, the standard deviations sx,sy\step{s_x}, \step{s_y}, and the correlation rr. Using these five summary numbers for a group of adults (height x\data{x} with xˉ=68 in\means{\bar{x}} = \means{68}\text{ in} and sx=4 in\step{s_x} = \step{4}\text{ in}, weight y\data{y} with yˉ=160 lb\means{\bar{y}} = \means{160}\text{ lb} and sy=20 lb\step{s_y} = \step{20}\text{ lb}, and correlation r=0.80r = 0.80), we can build the least-squares line for predicting weight from height.

Finding the Line from Summary Statistics
yy
xx
xˉ\htmlClass{lc-violet}{\bar{x}}
sx\htmlClass{lc-pink}{s_x}
yˉ\htmlClass{lc-violet}{\bar{y}}
sy\htmlClass{lc-pink}{s_y}
rr
sx\htmlClass{lc-pink}{s_x}
sy\htmlClass{lc-pink}{s_y}
b=  ?\htmlClass{lc-pink}{b} = \;?

If all the points lined up perfectly with r=1r = 1, stepping right by 1\step{1} standard deviation sx\step{s_x} from xˉ\means{\bar{x}} would step up by 1\step{1} full standard deviation sy\step{s_y} from yˉ\means{\bar{y}}, giving a slope of sysx\frac{\step{s_y}}{\step{s_x}}. When the points are scattered, the correlation rr scales back that vertical step to r⋅syr \cdot \step{s_y}:

b=r⏟correlation⋅sysx⏟ratio of spreads,a=yˉ−bxˉ\displaystyle \begin{aligned} \step{b} &= \underbrace{r}_{\text{correlation}} \cdot \underbrace{\frac{\step{s_y}}{\step{s_x}}}_{\step{\text{ratio of spreads}}}, \\[6pt] \fit{a} &= \means{\bar{y}} - \step{b}\means{\bar{x}} \end{aligned}
Text solution
Scale the ratio of spreads by the correlation rr to find the slopeDivide the vertical spread sy=20 lb\step{s_y} = \step{20}\text{ lb} by the horizontal spread sx=4 in\step{s_x} = \step{4}\text{ in}, and multiply by r=0.80r = 0.80.
b\displaystyle \step{b} =0.80⋅204\displaystyle = 0.80 \cdot \frac{\step{20}}{\step{4}} =0.80⋅5\displaystyle = 0.80 \cdot \step{5} =4 lb/in\displaystyle = \step{4}\text{ lb/in}
Walk backward from the point of means (68,160)\means{(68, 160)} to x=0\data{x} = \data{0} to find the yy-interceptStart at yˉ=160 lb\means{\bar{y}} = \means{160}\text{ lb} at xˉ=68 in\means{\bar{x}} = \means{68}\text{ in} and subtract 68\means{68} steps of 4 lb/in\step{4}\text{ lb/in}.
a\displaystyle \fit{a} =160−68(4)\displaystyle = \means{160} - \means{68}(\step{4}) =160−272\displaystyle = \means{160} - 272 =−112 lb\displaystyle = \fit{-112}\text{ lb}
Write the equation of the least-squares linePut the intercept a=−112\fit{a} = \fit{-112} and slope b=4\step{b} = \step{4} into the line equation.
Weight^\displaystyle \fit{\widehat{\text{Weight}}} =−112+4(Height)\displaystyle = \fit{-112} + \step{4}(\data{\text{Height}})

Each additional 1 in1\text{ in} of height increases an adult's predicted weight by 4 lb\step{4}\text{ lb}. The intercept of −112 lb\fit{-112}\text{ lb} at 0 in\data{0}\text{ in} makes no physical sense because x=0\data{x} = \data{0} is far outside human heights: it is simply the starting value at x=0\data{x} = \data{0} needed to keep the line aimed through the points for real adults around (68,160)\means{(68, 160)}.

Even when the horizontal spread sx\step{s_x} and vertical spread sy\step{s_y} stay fixed, more scatter in the points lowers rr and flattens the slope from sysx\frac{\step{s_y}}{\step{s_x}} toward a horizontal line at yˉ\means{\bar{y}}, so extreme values in x\data{x} give less extreme predictions in y\data{y}.

Even when the horizontal and vertical spreads stay the same, more scatter in the cloud pulls the predicted rise down and tilts the line flatter toward the average height.
4

Reading Computer Output and Warnings for Regression

For large datasets, statistical software computes the least-squares line automatically and prints a regression table. We want to read the intercept a\fit{a} and slope b\step{b} directly off the printout to predict a used car's price (in dollars) from its mileage (in thousands of miles), and see when a regression line's predictions break down.

Reading Computer Output and Warnings for Regression
Predictor\htmlClass{lc-ink}{\text{Predictor}}
Coef\htmlClass{lc-ink}{\text{Coef}}
SE Coef\htmlClass{lc-ink}{\text{SE Coef}}
T\htmlClass{lc-ink}{\text{T}}
P\htmlClass{lc-ink}{\text{P}}
Price  (dollars)\htmlClass{lc-violet}{\text{Price}}\;\htmlClass{lc-ink}{\text{(dollars)}}
Mileage  (1000s of miles)\htmlClass{lc-blue}{\text{Mileage}}\;\htmlClass{lc-ink}{\text{(1000s of miles)}}
Text solution
Read the intercept and slope from the `Coef` columnIgnore `SE Coef`, `T`, and `P`, take the `Coef` number in the `Constant` row as the yy-intercept a\fit{a}, and take the `Coef` number in the `Mileage (1000s)` row as the slope b\step{b}.
Price^\displaystyle \fit{\widehat{\text{Price}}} =24500⏟a (Constant Coef)−150⏟b (Mileage Coef)(Mileage in thousands)\displaystyle = \underbrace{\fit{24500}}_{\fit{a}\text{ (Constant Coef)}} \underbrace{\step{- 150}}_{\step{b}\text{ (Mileage Coef)}}(\data{\text{Mileage in thousands}})
Test a prediction far outside the data at 200,000\data{200{,}000} miles (x=200\data{x} = \data{200})Substitute x=200\data{x} = \data{200} thousand miles into the line.
Price^x=200\displaystyle \fit{\widehat{\text{Price}}}_{\data{x=200}} =24500−150(200)\displaystyle = \fit{24500} - \step{150}(\data{200}) =24500−30000\displaystyle = \fit{24500} - 30000 =−$5500\displaystyle = \fit{-\$5500}

A brand-new car with 0\data{0} miles has a predicted price of $24,500\fit{\$24{,}500}, and each additional 1,0001{,}000 miles driven decreases the predicted price by $150\step{\$150}, but plugging in 200,000\data{200{,}000} miles (x=200\data{x} = \data{200}) goes far outside the mileage range of the data and predicts an impossible price of −$5,500\fit{-\$5{,}500}.

Extrapolation\htmlClass{lc-ink}{\text{Extrapolation}}
beyond the data\htmlClass{lc-ink}{\text{beyond the data}}
Curved pattern:\htmlClass{lc-ink}{\text{Curved pattern:}}
straight line\htmlClass{lc-ink}{\text{straight line}}
does not fit\htmlClass{lc-ink}{\text{does not fit}}
5050
100100
00
price\htmlClass{lc-ink}{\text{price}}
mileage (1000s)\htmlClass{lc-ink}{\text{mileage (1000s)}}
(200,−$5,500)(\htmlClass{lc-blue}{200}, \htmlClass{lc-violet}{-\$5{,}500})

Key concepts

The least-squares regression line y^=a+bx\fit{\hat{y}} = \fit{a} + \step{b}\data{x} is the one line that minimizes the sum of squared vertical gaps ∑(y−y^)2\sum (\data{y} - \fit{\hat{y}})^2, where each point's residual is actual minus predicted (y−y^\data{y} - \fit{\hat{y}}, such as 5−3.8=+1.2\data{5} - \fit{3.8} = \resid{+1.2} when a student's actual score of 5\data{5} is higher than the line's prediction of 3.8\fit{3.8}). Every least-squares line is pinned at the point of means (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, so once you find the slope b\step{b} from whichever information you are given, you always find the yy-intercept a\fit{a} by walking backward xˉ\means{\bar{x}} steps from yˉ\means{\bar{y}} to x=0\data{x} = \data{0}:

a\displaystyle \fit{a} =yˉ−bxˉ(from (xˉ,yˉ)=(3,5) with b=1.2,  a=5−3(1.2)=1.4)\displaystyle = \means{\bar{y}} - \step{b}\means{\bar{x}} \quad \left(\text{from }\means{(\bar{x}, \bar{y})} = \means{(3, 5)}\text{ with }\step{b} = \step{1.2},\; \fit{a} = \means{5} - \means{3}(\step{1.2}) = \fit{1.4}\right)

Pick how to find the slope b\step{b} based on what you have:

From a small table of data points (x,y)\data{(x, y)}

measure each point's horizontal and vertical steps from (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, multiply them, and divide by the squared horizontal steps:

b\displaystyle \step{b} =∑(x−xˉ)(y−yˉ)∑(x−xˉ)2(for the five quiz points around (3,5),  b=1210=1.2)\displaystyle = \frac{\sum (\data{x} - \means{\bar{x}})(\data{y} - \means{\bar{y}})}{\sum (\data{x} - \means{\bar{x}})^2} \quad \left(\text{for the five quiz points around }\means{(3, 5)},\; \step{b} = \frac{\positive{12}}{\step{10}} = \step{1.2}\right)

From summary statistics (xˉ,sx,yˉ,sy,r\means{\bar{x}}, \step{s_x}, \means{\bar{y}}, \step{s_y}, r)

scale the ratio of vertical-to-horizontal spreads by the correlation rr, because each +1sx\step{+1s_x} increase from xˉ\means{\bar{x}} changes the predicted y^\fit{\hat{y}} by +r⋅sy+r \cdot \step{s_y} from yˉ\means{\bar{y}}:

b\displaystyle \step{b} =rsysx(for adult heights and weights with r=0.80,  b=0.80⋅204=4)\displaystyle = r\frac{\step{s_y}}{\step{s_x}} \quad \left(\text{for adult heights and weights with }r = 0.80,\; \step{b} = 0.80 \cdot \frac{\step{20}}{\step{4}} = \step{4}\right)

From a computer printout

skip the slope formulas and read the `Coef` column directly: `Constant` is a\fit{a} (24500\fit{24500}) and the row named after the x\data{x}-variable is b\step{b} (−150\step{-150} for `Mileage (1000s)`), ignoring `SE Coef`, `T`, and `P`.

When not to use the line

never plug in an x\data{x}-value far outside the range of the collected data (extrapolation, like predicting −$5,500\fit{-\$5{,}500} at 200,000\data{200{,}000} miles or reading the −112 lb\fit{-112}\text{ lb} intercept at 0 in\data{0}\text{ in} as a real person's weight), and do not fit a straight line at all if the scatterplot shows a curved pattern such as a U-shape.

5

Practice

1

The least-squares regression line for predicting a tomato plant's height (in cm) from the amount of fertilizer it received (in grams) is y^=8.5+2.4x\fit{\hat{y}} = \fit{8.5} + \step{2.4}\data{x}. (a) A plant given 3\data{3} grams of fertilizer grew to an actual height of 14.2 cm\data{14.2}\text{ cm}. Find its predicted height, calculate its residual, and explain what the sign of the residual tells you. (b) Another plant was given 5\data{5} grams of fertilizer and had a residual of +1.8 cm\resid{+1.8}\text{ cm}. What was its actual height?

Plug the fertilizer amount x\data{x} into the line first to get the predicted height y^\fit{\hat{y}}; then write Residual=y−y^\resid{\text{Residual}} = \data{y} - \fit{\hat{y}} and check which of the three numbers (y\data{y}, y^\fit{\hat{y}}, or the residual) you are solving for in each part.

(a) Plug x=3\data{x} = \data{3} into the regression line to find the predicted height, then subtract actual−predicted\data{\text{actual}} - \fit{\text{predicted}}:
y^=8.5+2.4(3)=8.5+7.2=15.7 cmResidual=y−y^=14.2−15.7=−1.5 cm\displaystyle \begin{aligned} \fit{\hat{y}} &= \fit{8.5} + \step{2.4}(\data{3}) = \fit{8.5} + 7.2 = \fit{15.7}\text{ cm} \\ \resid{\text{Residual}} &= \data{y} - \fit{\hat{y}} = \data{14.2} - \fit{15.7} = \resid{-1.5}\text{ cm} \end{aligned}
Watch out for subtracting in reverse (y^−y=15.7−14.2=+1.5 cm\fit{\hat{y}} - \data{y} = \fit{15.7} - \data{14.2} = +1.5\text{ cm}), which flips the sign. The negative residual of −1.5 cm\resid{-1.5}\text{ cm} means the plant grew 1.5 cm\resid{1.5}\text{ cm} shorter than the line predicted for 3\data{3} grams of fertilizer.
(b) Find the predicted height at x=5\data{x} = \data{5}, then substitute Residual=+1.8\resid{\text{Residual}} = \resid{+1.8} and y^=20.5\fit{\hat{y}} = \fit{20.5} into Residual=y−y^\resid{\text{Residual}} = \data{y} - \fit{\hat{y}} (be careful not to subtract 20.5−1.8=18.7 cm\fit{20.5} - \resid{1.8} = 18.7\text{ cm}, which puts 20.5\fit{20.5} in place of the actual height y\data{y}):
y^=8.5+2.4(5)=8.5+12.0=20.5 cm+1.8=y−20.5y=20.5+1.8=22.3 cm\displaystyle \begin{aligned} \fit{\hat{y}} &= \fit{8.5} + \step{2.4}(\data{5}) = \fit{8.5} + 12.0 = \fit{20.5}\text{ cm} \\ \resid{+1.8} &= \data{y} - \fit{20.5} \\ \data{y} &= \fit{20.5} + \resid{1.8} = \data{22.3}\text{ cm} \end{aligned}
2

Using data from apartments located between 0.5\data{0.5} and 8\data{8} miles from downtown, a computer regression printout for predicting monthly rent (in dollars) from distance to downtown (in miles) gives:

``` Predictor Coef SE Coef T P Constant 2600 94.5 27.51 0.000 Distance (miles) -125 18.2 -6.87 0.000

S = 215.4 R-Sq = 71.2% R-Sq(adj) = 69.8% ```

(a) Write the equation of the least-squares regression line. (b) Explain what the slope and the yy-intercept mean for rent and distance. (c) What monthly rent does the line predict for an apartment 25\data{25} miles from downtown, and why shouldn't you trust this prediction?

Read only the `Coef` column to match `Constant` and `Distance (miles)` to a\fit{a} and b\step{b}; for part (c), compare x=25\data{x} = \data{25} miles to the 0.5\data{0.5}-to-8\data{8}-mile range where the apartment data were collected.

(a) From the `Coef` column, `Constant` gives a=2600\fit{a} = \fit{2600} and `Distance (miles)` gives b=−125\step{b} = \step{-125} (don't swap the two rows to get y^=−125+2600x\fit{\hat{y}} = -125 + 2600\data{x}, and don't pull 94.594.5 and 18.218.2 from the `SE Coef` column):
Rent^\displaystyle \fit{\widehat{\text{Rent}}} =2600−125(Distance)ory^\displaystyle = \fit{2600} - \step{125}(\data{\text{Distance}}) \quad \text{or} \quad \fit{\hat{y}} =2600−125x\displaystyle = \fit{2600} - \step{125}\data{x}
(b) Slope (−125\step{-125}): For each additional 11 mile from downtown, the predicted monthly rent decreases by $125\step{\$125}. Intercept (2600\fit{2600}): An apartment located 0\data{0} miles from downtown has a predicted monthly rent of $2,600\fit{\$2{,}600}.
(c) Plugging x=25\data{x} = \data{25} into the equation (watching the minus sign so you don't add 2600+3125=$5,725\fit{2600} + 3125 = \$5{,}725):
Rent^x=25\displaystyle \fit{\widehat{\text{Rent}}}_{\data{x=25}} =2600−125(25)\displaystyle = \fit{2600} - \step{125}(\data{25}) =2600−3125\displaystyle = \fit{2600} - 3125 =−$525\displaystyle = \fit{-\$525}
You shouldn't trust this prediction because 25\data{25} miles is far outside the 0.5\data{0.5}-to-8\data{8}-mile range of the data (extrapolation), where the straight-line trend breaks down and predicts an impossible negative rent of −$525\fit{-\$525}.
3

Five students recorded the number of hours they spent watching TV on the night before a 10-point quiz (x\data{x}) and their quiz scores (y\data{y}): (1,9)\data{(1, 9)}, (2,7)\data{(2, 7)}, (4,6)\data{(4, 6)}, (5,5)\data{(5, 5)}, and (8,3)\data{(8, 3)}. Find the point of means (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, use the horizontal and vertical steps from the point of means to calculate the slope b\step{b}, and walk backward to x=0\data{x} = \data{0} to find the yy-intercept a\fit{a} and write the equation of the least-squares regression line.

After finding (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, write the steps (x−xˉ)(\data{x} - \means{\bar{x}}) and (y−yˉ)(\data{y} - \means{\bar{y}}) for each point; when walking backward from xˉ\means{\bar{x}} to 0\data{0}, watch what subtracting xˉ\means{\bar{x}} steps of a negative slope does to the height.

Find the point of means (xˉ,yˉ)\means{(\bar{x}, \bar{y})}:
xˉ=1+2+4+5+85=205=4 hoursyˉ=9+7+6+5+35=305=6 points\displaystyle \begin{aligned} \means{\bar{x}} &= \frac{\data{1} + \data{2} + \data{4} + \data{5} + \data{8}}{5} = \frac{20}{5} = \means{4}\text{ hours} \\ \means{\bar{y}} &= \frac{\data{9} + \data{7} + \data{6} + \data{5} + \data{3}}{5} = \frac{30}{5} = \means{6}\text{ points} \end{aligned}
Measure the steps (x−4,y−6)(\data{x} - \means{4}, \data{y} - \means{6}) from (4,6)\means{(4, 6)}, add the step products, and divide by the sum of squared xx-steps (be careful to divide by ∑(x−4)2=30\sum (\data{x} - \means{4})^2 = \step{30}, not ∑(y−6)2=20\sum (\data{y} - \means{6})^2 = \step{20}, which would give b=−1.2\step{b} = -1.2):
∑(x−4)(y−6)=(−3)(+3)+(−2)(+1)+(0)(0)+(+1)(−1)+(+4)(−3)=−9−2+0−1−12=−24∑(x−4)2=(−3)2+(−2)2+02+12+42=9+4+0+1+16=30b=−2430=−0.8\displaystyle \begin{aligned} \sum (\data{x} - \means{4})(\data{y} - \means{6}) &= (\step{-3})(\step{+3}) + (\step{-2})(\step{+1}) + (\step{0})(\step{0}) + (\step{+1})(\step{-1}) + (\step{+4})(\step{-3}) \\ &= \negative{-9} - \negative{2} + 0 - \negative{1} - \negative{12} = \negative{-24} \\[4pt] \sum (\data{x} - \means{4})^2 &= (\step{-3})^2 + (\step{-2})^2 + \step{0}^2 + \step{1}^2 + \step{4}^2 \\ &= 9 + 4 + 0 + 1 + 16 = \step{30} \\[4pt] \step{b} &= \frac{\negative{-24}}{\step{30}} = \step{-0.8} \end{aligned}
Walk backward 4\means{4} steps from (4,6)\means{(4, 6)} to x=0\data{x} = \data{0} (watch the double negative in 6−4(−0.8)\means{6} - \means{4}(\step{-0.8}) so you don't subtract 6−3.2=2.8\means{6} - 3.2 = 2.8):
a=6−4(−0.8)=6+3.2=9.2y^=9.2−0.8x\displaystyle \begin{aligned} \fit{a} &= \means{6} - \means{4}(\step{-0.8}) = \means{6} + 3.2 = \fit{9.2} \\ \fit{\hat{y}} &= \fit{9.2} - \step{0.8}\data{x} \end{aligned}
4

In a study of adult falcons, wing length x\data{x} (in cm) has mean xˉ=35 cm\means{\bar{x}} = \means{35}\text{ cm} and standard deviation sx=2.5 cm\step{s_x} = \step{2.5}\text{ cm}, body mass y\data{y} (in grams) has mean yˉ=600 g\means{\bar{y}} = \means{600}\text{ g} and standard deviation sy=60 g\step{s_y} = \step{60}\text{ g}, and the correlation between wing length and body mass is r=0.75r = 0.75. Find the equation of the least-squares regression line for predicting body mass from wing length, and explain whether the yy-intercept makes physical sense for a falcon.

Put the vertical spread sy\step{s_y} of body mass on top of the spread ratio sysx\frac{\step{s_y}}{\step{s_x}} before multiplying by rr, then walk backward from (35,600)\means{(35, 600)} to x=0\data{x} = \data{0}.

Find the ratio of spreads sysx\frac{\step{s_y}}{\step{s_x}} and multiply by r=0.75r = 0.75 (don't flip the spreads to sxsy=2.560\frac{\step{s_x}}{\step{s_y}} = \frac{\step{2.5}}{\step{60}}, which gives b=0.03125\step{b} = 0.03125, and don't forget to multiply by r=0.75r = 0.75, which would leave b=24\step{b} = 24 and a=−240\fit{a} = -240):
sysx=602.5=24 g/cmb=rsysx=0.75(24)=18 g/cm\displaystyle \begin{aligned} \frac{\step{s_y}}{\step{s_x}} &= \frac{\step{60}}{\step{2.5}} = \step{24}\text{ g/cm} \\ \step{b} &= r\frac{\step{s_y}}{\step{s_x}} = 0.75(\step{24}) = \step{18}\text{ g/cm} \end{aligned}
Walk backward 35 cm\means{35}\text{ cm} from (35,600)\means{(35, 600)} to x=0\data{x} = \data{0}:
a=600−35(18)=600−630=−30 gMass^=−30+18(Wing Length)ory^=−30+18x\displaystyle \begin{aligned} \fit{a} &= \means{600} - \means{35}(\step{18}) = \means{600} - 630 = \fit{-30}\text{ g} \\ \fit{\widehat{\text{Mass}}} &= \fit{-30} + \step{18}(\data{\text{Wing Length}}) \quad \text{or} \quad \fit{\hat{y}} = \fit{-30} + \step{18}\data{x} \end{aligned}
The yy-intercept of −30 g\fit{-30}\text{ g} does not make physical sense because an adult falcon cannot have a 0 cm\data{0}\text{ cm} wing length or a negative mass; x=0\data{x} = \data{0} is far outside the range of the data, so −30 g\fit{-30}\text{ g} is just the starting value at x=0\data{x} = \data{0} needed to aim the line through the points for real falcons around (35,600)\means{(35, 600)}.
5

For a large group of runners, a least-squares regression line predicts 10K race time y\data{y} (in minutes) from fitness score x\data{x}. The correlation is r=−0.60r = -0.60, and the equation of the line is y^=84−0.8x\fit{\hat{y}} = \fit{84} - \step{0.8}\data{x}. (a) A runner whose fitness score is equal to the group mean xˉ\means{\bar{x}} has a predicted race time of 48\fit{48} minutes. What is the mean fitness score xˉ\means{\bar{x}} of the group? (b) Another runner has a fitness score that is 2\step{2} standard deviations above the mean (2sx\step{2s_x} above xˉ\means{\bar{x}}). How many standard deviations (sy\step{s_y}) above or below the mean race time yˉ\means{\bar{y}} is this runner's predicted race time?

For (a), use the fact that the line passes through (xˉ,yˉ)\means{(\bar{x}, \bar{y})}; for (b), remember that each 1sx\step{1s_x} step away from xˉ\means{\bar{x}} moves the predicted value y^\fit{\hat{y}} by rr standard deviations sy\step{s_y} from yˉ\means{\bar{y}}.

(a) Because the least-squares line always passes through (xˉ,yˉ)\means{(\bar{x}, \bar{y})}, the predicted race time at x=xˉ\data{x} = \means{\bar{x}} is yˉ=48\means{\bar{y}} = \means{48} minutes. Plug y^=48\fit{\hat{y}} = \fit{48} into the line and solve for xˉ\means{\bar{x}} (don't plug 4848 in for x\data{x}, which gives 84−0.8(48)=45.6\fit{84} - \step{0.8}(48) = 45.6):
48=84−0.8xˉ0.8xˉ=36xˉ=360.8=45\displaystyle \begin{aligned} \fit{48} &= \fit{84} - \step{0.8}\means{\bar{x}} \\ \step{0.8}\means{\bar{x}} &= 36 \\ \means{\bar{x}} &= \frac{36}{\step{0.8}} = \means{45} \end{aligned}
(b) Each 1\step{1}-standard-deviation increase in x\data{x} changes the predicted y\data{y} by r=−0.60r = -0.60 standard deviations (don't multiply by the slope b=−0.8\step{b} = \step{-0.8}, which would give −1.6sy-1.6\step{s_y}):
2×(−0.60)\displaystyle \step{2} \times (-0.60) =−1.2\displaystyle = \step{-1.2}
The runner's predicted race time is 1.2\step{1.2} standard deviations (1.2sy\step{1.2s_y}) below the mean race time yˉ\means{\bar{y}}.
6

For the three data points (1,2)\data{(1, 2)}, (2,2)\data{(2, 2)}, and (3,8)\data{(3, 8)}, a student proposes Line A: y^=4\fit{\hat{y}} = \fit{4}, while the least-squares regression line is Line B: y^=−2+3x\fit{\hat{y}} = \fit{-2} + \step{3}\data{x}. The student claims Line A fits just as well as Line B because the residuals for Line A add up to 0\resid{0}. Find the residuals and the sum of squared residuals for both lines to explain why the student's reasoning fails and why Line B is the better line.

Find y−y^\data{y} - \fit{\hat{y}} at x=1,2,3\data{x} = \data{1, 2, 3} for each line, then square each residual before adding the squares together.

For Line A (y^=4\fit{\hat{y}} = \fit{4}), find the residuals and square each one before adding (don't square the sum of the residuals 02=00^2 = 0, and remember (−2)2=+4(\resid{-2})^2 = +4, not −4-4):
ResidualsA:2−4=−2,2−4=−2,8−4=+4∑(y−y^)=−2+(−2)+4=0∑(y−y^)2=(−2)2+(−2)2+42=4+4+16=24\displaystyle \begin{aligned} \resid{\text{Residuals}_{\text{A}}} &: \quad \data{2} - \fit{4} = \resid{-2}, \quad \data{2} - \fit{4} = \resid{-2}, \quad \data{8} - \fit{4} = \resid{+4} \\ \sum (\data{y} - \fit{\hat{y}}) &= \resid{-2} + (\resid{-2}) + \resid{4} = \resid{0} \\ \sum (\data{y} - \fit{\hat{y}})^2 &= (\resid{-2})^2 + (\resid{-2})^2 + \resid{4}^2 = 4 + 4 + 16 = \resid{24} \end{aligned}
For Line B (y^=−2+3x\fit{\hat{y}} = \fit{-2} + \step{3}\data{x}), the predictions at x=1,2,3\data{x} = \data{1, 2, 3} are y^=1,4,7\fit{\hat{y}} = \fit{1, 4, 7}:
ResidualsB:2−1=+1,2−4=−2,8−7=+1∑(y−y^)=1+(−2)+1=0∑(y−y^)2=12+(−2)2+12=1+4+1=6\displaystyle \begin{aligned} \resid{\text{Residuals}_{\text{B}}} &: \quad \data{2} - \fit{1} = \resid{+1}, \quad \data{2} - \fit{4} = \resid{-2}, \quad \data{8} - \fit{7} = \resid{+1} \\ \sum (\data{y} - \fit{\hat{y}}) &= \resid{1} + (\resid{-2}) + \resid{1} = \resid{0} \\ \sum (\data{y} - \fit{\hat{y}})^2 &= \resid{1}^2 + (\resid{-2})^2 + \resid{1}^2 = 1 + 4 + 1 = \resid{6} \end{aligned}
Plain residuals cancel out positive and negative errors to 0\resid{0} on both lines, whereas squaring keeps every error positive and heavily penalizes Line A's large error of +4\resid{+4}, showing that Line B has a much smaller sum of squared residuals (6\resid{6} vs. 24\resid{24}).
7

Consider the five data points (1,5)\data{(1, 5)}, (2,2)\data{(2, 2)}, (3,1)\data{(3, 1)}, (4,2)\data{(4, 2)}, and (5,5)\data{(5, 5)}. Find the equation of the least-squares regression line for these five points, and explain what this example shows about using regression formulas without looking at a scatterplot first.

Calculate (xˉ,yˉ)\means{(\bar{x}, \bar{y})} and the step products (x−xˉ)(y−yˉ)(\data{x} - \means{\bar{x}})(\data{y} - \means{\bar{y}}) for all five points, then look at the U-shape of the five points on a graph compared to your line.

Find the point of means (xˉ,yˉ)\means{(\bar{x}, \bar{y})}:
xˉ=1+2+3+4+55=3yˉ=5+2+1+2+55=3\displaystyle \begin{aligned} \means{\bar{x}} &= \frac{\data{1} + \data{2} + \data{3} + \data{4} + \data{5}}{5} = \means{3} \\ \means{\bar{y}} &= \frac{\data{5} + \data{2} + \data{1} + \data{2} + \data{5}}{5} = \means{3} \end{aligned}
Find the step products (x−3)(y−3)(\data{x} - \means{3})(\data{y} - \means{3}) and the squared xx-steps (keep track of the signs on (−2)(+2)=−4(\step{-2})(\step{+2}) = \negative{-4} and (+1)(−1)=−1(\step{+1})(\step{-1}) = \negative{-1} so you don't add all positive products to get +10+10 and b=1\step{b} = 1):
∑(x−3)(y−3)=(−2)(+2)+(−1)(−1)+(0)(−2)+(+1)(−1)+(+2)(+2)=−4+1+0−1+4=0∑(x−3)2=(−2)2+(−1)2+02+12+22=10b=010=0,a=3−0(3)=3\displaystyle \begin{aligned} \sum (\data{x} - \means{3})(\data{y} - \means{3}) &= (\step{-2})(\step{+2}) + (\step{-1})(\step{-1}) + (\step{0})(\step{-2}) + (\step{+1})(\step{-1}) + (\step{+2})(\step{+2}) \\ &= \negative{-4} + \positive{1} + 0 - \negative{1} + \positive{4} = 0 \\[4pt] \sum (\data{x} - \means{3})^2 &= (\step{-2})^2 + (\step{-1})^2 + \step{0}^2 + \step{1}^2 + \step{2}^2 = \step{10} \\[4pt] \step{b} &= \frac{0}{\step{10}} = \step{0}, \qquad \fit{a} = \means{3} - \step{0}(\means{3}) = \fit{3} \end{aligned}
The least-squares regression line is the flat horizontal line y^=3\fit{\hat{y}} = \fit{3}. Even though the five points follow an exact U-shaped curve, the slope and intercept formulas can only fit a straight line and put a flat line right across the curve, which is why you must always check the scatterplot first to make sure the data actually follow a straight line.