Algebra 1Data Analysis5 of 5
Data Analysis · 5

Correlation and Linear Regression

When we draw a line of fit through a scatter plot by hand, two people eyeballing the same cloud of dots will get slightly different equations.

1

The Least Squares Regression Line

To find the one best line through a scatter plot, we look for the least squares regression line: the line with the smallest total squared vertical distance from the points.

The Least Squares Regression Line
Which line fits best?\text{Which line fits best?}
Test score\text{Test score}
0\htmlClass{lc-mute}{0}
1\htmlClass{lc-mute}{1}
2\htmlClass{lc-mute}{2}
3\htmlClass{lc-mute}{3}
4\htmlClass{lc-mute}{4}
5\htmlClass{lc-mute}{5}
6\htmlClass{lc-mute}{6}
40\htmlClass{lc-mute}{40}
60\htmlClass{lc-mute}{60}
80\htmlClass{lc-mute}{80}
100\htmlClass{lc-mute}{100}
Hours studied\text{Hours studied}
y=8x+50\model{y = 8}x \model{+ 50}
y=7x+54\htmlClass{lc-violet}{y = 7}x \htmlClass{lc-violet}{+ 54}
Text solution
Plug xx into the line to find the predicted scoreFor the students at (3,80)\obs{(3, 80)} and (2,62)\obs{(2, 62)}, plug each study time into the line y=8x+50\model{y} = \model{8}x \model{{}+ 50} we drew by eye.
y=8(3)+50=74y=8(2)+50=66\displaystyle \begin{aligned} \model{y} &= \model{8}(3) \model{{}+ 50} = \pred{74} \\ \model{y} &= \model{8}(2) \model{{}+ 50} = \pred{66} \end{aligned}
Subtract predicted from actual to get each residualA positive residual means the actual dot sits above the line, and a negative residual means it sits below the line.
Residual=80⏟Actual−74⏟Predicted=+6Residual=62⏟Actual−66⏟Predicted=−4\displaystyle \begin{aligned} \resid{\text{Residual}} &= \underbrace{\obs{80}}_{\obs{\text{Actual}}} - \underbrace{\pred{74}}_{\pred{\text{Predicted}}} = \resid{+6} \\ \resid{\text{Residual}} &= \underbrace{\obs{62}}_{\obs{\text{Actual}}} - \underbrace{\pred{66}}_{\pred{\text{Predicted}}} = \resid{-4} \end{aligned}
Square each residual so positive and negative misses cannot cancelAdding the signed residuals around y=8x+50\model{y} = \model{8}x \model{{}+ 50} lets points above and below the line cancel out (6+8+1−4−3−2=6\resid{6} \resid{{}+ 8} \resid{{}+ 1} \resid{{}- 4} \resid{{}- 3} \resid{{}- 2} = 6), so we square every gap to get a positive area before adding them up.
(+6)2=36(−4)2=16\displaystyle \begin{aligned} \resid{(+6)}^2 &= \sqerr{36} \\ \resid{(-4)}^2 &= \sqerr{16} \end{aligned}

Even on a badly tilted line, positive and negative vertical gaps can cancel out. We choose the line that makes the total area of the error squares as small as possible.

Squaring each vertical gap keeps positive and negative misses from canceling out. The least squares regression line makes the total area of those squares as small as possible.
2

Finding the Line and Making Predictions

Instead of shrinking the error squares by hand, we can use a calculator to find the exact equation y=ax+b\model{y} = \model{a}x \model{{}+ b} of the least-squares regression line and use it to predict y\pred{y} from xx.

Finding the Line and Making Predictions
Hours\text{Hours}
Score\text{Score}
156\obs{1}\hspace{3em}\obs{56}
262\obs{2}\hspace{3em}\obs{62}
274\obs{2}\hspace{3em}\obs{74}
380\obs{3}\hspace{3em}\obs{80}
483\obs{4}\hspace{3em}\obs{83}
695\obs{6}\hspace{3em}\obs{95}
LinReg(ax+b)\text{LinReg}(ax + b)
y=ax+b\model{y} = \model{a}x + \model{b}
a=  ?\model{a} = \;?
b=  ?\model{b} = \;?
Text solution
Substitute the slope a\model{a} and yy-intercept b\model{b} into y=ax+b\model{y} = \model{a}x \model{{}+ b}From the calculator's `LinReg(ax+b)` output for the six students, plug a=7.5\model{a} = \model{7.5} and b=52.5\model{b} = \model{52.5} directly into the linear equation.
y\displaystyle \model{y} =7.5⏟slope ax+52.5⏟y-intercept b\displaystyle = \underbrace{\model{7.5}}_{\model{\text{slope } a}}x + \underbrace{\model{52.5}}_{\model{y\text{-intercept } b}}
Plug in x=4.5x = 4.5 to interpolate inside the 1\range{1} to 6\range{6} hour data rangeHere 4.54.5 hours sits inside the range of hours we collected. We still need to check how well the line fits before trusting the prediction of about 86\pred{86} points.
y\displaystyle \model{y} =7.5(4.5)+52.5\displaystyle = \model{7.5}(4.5) \model{{}+ 52.5} =33.75+52.5\displaystyle = 33.75 \model{{}+ 52.5} =86.25\displaystyle = \pred{86.25}
Plug in x=20x = 20 to see how extrapolation outside the data breaks downBecause 2020 hours is far outside the 1\range{1} to 6\range{6} hour data range, extending the straight line predicts an impossible score of 202.5%\pred{202.5}\% on a 100100-point test.
y\displaystyle \model{y} =7.5(20)+52.5\displaystyle = \model{7.5}(20) \model{{}+ 52.5} =150+52.5\displaystyle = 150 \model{{}+ 52.5} =202.5\displaystyle = \pred{202.5}
Test score\text{Test score}
Hours studied\text{Hours studied}
1\range{1}
6\range{6}
10\htmlClass{lc-mute}{10}
15\htmlClass{lc-mute}{15}
2020
50\htmlClass{lc-mute}{50}
100100
150\htmlClass{lc-mute}{150}
200\htmlClass{lc-mute}{200}
Interpolationinside data range:x=4.5→86.25\begin{array}{c}\textbf{Interpolation}\\ \text{inside data range:}\\ x = 4.5 \rightarrow \pred{86.25}\end{array}
Extrapolationoutside data range:x=20→202.5\begin{array}{c}\textbf{Extrapolation}\\ \text{outside data range:}\\ x = 20 \rightarrow \pred{202.5}\end{array}
3

The Correlation Coefficient rr

Alongside the line's equation, we want a single number that measures both which way a straight-line trend goes and how tightly the dots follow the line: the correlation coefficient rr.

The Correlation Coefficient r
a=7.5\model{a = 7.5}
b=52.5\model{b = 52.5}
r=0.94r = 0.94
What does r measure?\text{What does } r \text{ measure?}

For the studying data, the sign and size of rr tell us the direction and tightness of the linear trend at a glance:

r=+⏟uphill trend0.94⏟tight around the line(−1≤r≤+1)\displaystyle \begin{gathered} r = \underbrace{+}_{\text{uphill trend}}\quad\underbrace{0.94}_{\text{tight around the line}} \\ (-1 \le r \le +1) \end{gathered}
r=−1r = -1
r=0r = 0
r=+1r = +1
r=−0.8r = -0.8
r=0r = 0
r=+0.8r = +0.8

Notice how rr is near +1+1 or −1-1 only when the dots closely follow a straight line. It drops toward 00 when the scatter spreads out, and also when the dots form a clean curve whose rising and falling sides cancel out.

rr gets close to +1+1 or −1-1 only when the dots hug a straight line. Both a cloud with no straight-line trend and a symmetric arch can have r=0r = 0.
4

Residual Plots

Because a calculator will happily draw a straight line through curved data, we need a way to test whether a straight line is the right model in the first place. A residual plot puts xx on the horizontal axis and Residual=Actual−Predicted\resid{\text{Residual}} = \obs{\text{Actual}} - \pred{\text{Predicted}} on the vertical axis, so the regression line corresponds to a horizontal line at 00.

Residual Plots
Is a straight line the right model?\text{Is a straight line the right model?}
0\htmlClass{lc-mute}{0}
3\htmlClass{lc-mute}{3}
6\htmlClass{lc-mute}{6}
5\htmlClass{lc-mute}{5}
9\htmlClass{lc-mute}{9}
Text solution
Find the predicted score and residual at each xx-valueUsing y=7.5x+52.5\model{y} = \model{7.5}x \model{{}+ 52.5}, subtract the line's prediction from each student's actual score (shown here for x=1x = 1 and x=3x = 3).
At x=1:Predicted=7.5(1)+52.5=60,Residual=56−60=−4At x=3:Predicted=7.5(3)+52.5=75,Residual=80−75=+5\displaystyle \begin{aligned} &\text{At } x = 1: \\ &\quad \begin{aligned} \pred{\text{Predicted}} &= \model{7.5}(1) \model{{}+ 52.5} = \pred{60}, \\ \resid{\text{Residual}} &= \obs{56} - \pred{60} = \resid{-4} \end{aligned} \\[6pt] &\text{At } x = 3: \\ &\quad \begin{aligned} \pred{\text{Predicted}} &= \model{7.5}(3) \model{{}+ 52.5} = \pred{75}, \\ \resid{\text{Residual}} &= \obs{80} - \pred{75} = \resid{+5} \end{aligned} \end{aligned}
Plot each (x,Residual)(x, \resid{\text{Residual}}) pair around the horizontal zero lineGraphing all six residuals against hours studied puts the residuals at both ends below 00, with several middle residuals above 00. This may indicate a curve. With only six points, we should check more data before deciding whether that apparent curve is a real trend.
(x,Residual):(1,−4),  (2,−5.5),  (2,+6.5),  (3,+5),  (4,+0.5),  (6,−2.5)\displaystyle \begin{aligned} &(x, \resid{\text{Residual}}): \\ &\quad (1, \resid{-4}),\; (2, \resid{-5.5}),\; (2, \resid{+6.5}),\; \\ &\quad (3, \resid{+5}),\; (4, \resid{+0.5}),\; (6, \resid{-2.5}) \end{aligned}

Random scatter of residuals around zero supports a straight-line model. A clear curve in the residuals suggests that a straight line missed part of the trend.

When data rises and then levels off, a straight regression line can miss the bend, leaving an arch in the residual plot.
5

Correlation vs. Causation

Even when rr is close to +1+1 or −1-1 and the residual plot is a clean random scatter, we still need more evidence before claiming that changing xx causes yy to change. A third variable could affect both.

Correlation vs. Causation
Does ice cream cause sunburns?\text{Does ice cream cause sunburns?}
Sunburns\htmlClass{lc-violet}{\text{Sunburns}}
Ice cream sales\obs{\text{Ice cream sales}}
r=0.92r = 0.92

Key concepts

For messy two-variable data, run `LinReg(ax+b)` on your calculator to get the least squares regression line y=ax+b\model{y} = \model{a}x \model{{}+ b} (such as y=7.5x+52.5\model{y} = \model{7.5}x \model{{}+ 52.5}). This line makes the sum of the squared vertical gaps as small as possible, where each gap is

Residual\displaystyle \resid{\text{Residual}} =Actual−Predicted\displaystyle = \obs{\text{Actual}} - \pred{\text{Predicted}}

Before trusting the line, check three things:

Check the residual plot for model fit

Plot (x,Residual)(x, \resid{\text{Residual}}) around the horizontal zero line. A random scatter above and below 00 supports using a straight line as a model. A clear curve or arch suggests the line missed part of the trend.

Check rr for straight-line strength and direction

On the scale from −1-1 to +1+1, the sign of rr gives the direction (++ uphill, −- downhill) and its distance from 00 tells how tightly the dots follow the line (r=0.94r = 0.94 indicates a tight uphill trend). Remember that r=0r = 0 only rules out a straight-line trend (a symmetric arch of a thrown ball also has r=0r = 0), and even r=0.92r = 0.92 between ice cream sales and sunburns does not mean one causes the other.

Check the data range when predicting

Plugging in an xx-value inside your collected data range (interpolation, like x=4.5x = 4.5 inside 1≤x≤6\range{1 \le x \le 6}) is generally safer than predicting outside it (extrapolation, like x=20x = 20). Even inside the range, prediction accuracy depends on how well the line fits. Outside the range, the trend may change.

6

Practice

1

A teacher records how many times xx a student skipped class and their test score yy, then runs `LinReg(ax+b)` on a calculator and gets a=−4.5a = -4.5, b=92b = 92, and r=−0.88r = -0.88. Write the equation of the least-squares regression line, and explain what the slope and yy-intercept mean in plain English.

In `LinReg(ax+b)`, check which number multiplies xx as the rate of change per class skipped, and which number gives the starting score when x=0x = 0.

Substitute a=−4.5\model{a} = \model{-4.5} for the slope and b=92\model{b} = \model{92} for the yy-intercept in y=ax+b\model{y} = \model{a}x \model{{}+ b} (be careful not to swap aa and bb to get y=92x−4.5y = 92x - 4.5, and do not plug the correlation coefficient r=−0.88r = -0.88 in as the slope to get y=−0.88x+92y = -0.88x + 92):
y\displaystyle \model{y} =−4.5x+92\displaystyle = \model{-4.5}x \model{{}+ 92}
The yy-intercept, 92\model{92}, is the test score we expect if a student skips 00 classes, and the slope, −4.5\model{-4.5}, means each class skipped lowers the expected test score by about 4.5\model{4.5} points.
2

Using the regression line y=7.5x+52.5y = 7.5x + 52.5 for hours studied xx and test score yy, find the predicted score and residual for a student who studied 55 hours and scored 8787. Then find the actual test score of a student who studied 44 hours and had a residual of −3.5-3.5.

Find the line's predicted score at each xx first, then plug into Residual=Actual−Predicted\text{Residual} = \text{Actual} - \text{Predicted}.

At x=5x = 5, plug 55 into the regression equation to find the predicted score:
y\displaystyle \model{y} =7.5(5)+52.5\displaystyle = \model{7.5}(5) \model{{}+ 52.5} =90\displaystyle = \pred{90}
Subtract in the order Actual−Predicted\obs{\text{Actual}} - \pred{\text{Predicted}} (watch out for subtracting Predicted−Actual=90−87\text{Predicted} - \text{Actual} = 90 - 87, which flips the sign to +3+3):
Residual\displaystyle \resid{\text{Residual}} =87−90\displaystyle = \obs{87} - \pred{90} =−3\displaystyle = \resid{-3}
At x=4x = 4, the predicted score is
y\displaystyle \model{y} =7.5(4)+52.5\displaystyle = \model{7.5}(4) \model{{}+ 52.5} =82.5\displaystyle = \pred{82.5}
Using Residual=Actual−Predicted\resid{\text{Residual}} = \obs{\text{Actual}} - \pred{\text{Predicted}}, a residual of −3.5\resid{-3.5} means the actual score sits 3.5\resid{3.5} points below 82.5\pred{82.5} (be careful not to subtract −3.5-3.5 from 82.582.5 to get 8686):
−3.5=Actual−82.5Actual=79\displaystyle \begin{aligned} \resid{-3.5} &= \obs{\text{Actual}} - \pred{82.5} \\ \obs{\text{Actual}} &= \obs{79} \end{aligned}
3

A classmate draws a line through a scatter plot of four dots and finds the residuals are +9,+5,−6,+9, +5, -6, and −8-8. They claim, "The residuals add up to 00, so my line is the best-fit line!" Explain why a residual sum of 00 does not guarantee a good line, and how a calculator actually measures total error.

Think about what happens to positive misses above a line and negative misses below it even when the line is tilted the wrong way, and what operation stops them from canceling.

Positive residuals above the line and negative residuals below it cancel out when added (9+5−6−8=0\resid{9} \resid{{}+ 5} \resid{{}- 6} \resid{{}- 8} = 0), which can happen even on a terrible line tilted the wrong way through the dots. A calculator squares every residual first, keeping the negative signs inside parentheses so (−6)2=+36\resid{(-6)}^2 = \sqerr{+36} and (−8)2=+64\resid{(-8)}^2 = \sqerr{+64} rather than −62=−36-6^2 = -36 and −82=−64-8^2 = -64 (which would wrongly give 81+25−36−64=681 + 25 - 36 - 64 = 6):
(+9)2+(+5)2+(−6)2+(−8)2\displaystyle \resid{(+9)}^2 + \resid{(+5)}^2 + \resid{(-6)}^2 + \resid{(-8)}^2 =81+25+36+64\displaystyle = \sqerr{81} + \sqerr{25} + \sqerr{36} + \sqerr{64} =206\displaystyle = 206
Squaring makes every error positive and heavily penalizes large misses, and the calculator finds the line with the smallest total squared error.
4

Data collected on temperatures xx from 50∘F50^\circ\text{F} to 85∘F85^\circ\text{F} and iced coffees sold yy at a café gives the regression line y=3x−110y = 3x - 110. Predict the number of iced coffees sold on a 70∘F70^\circ\text{F} day and on a 20∘F20^\circ\text{F} day, name each type of prediction, and explain what the data range tells you about their reliability.

After plugging each temperature in for xx, compare 70∘F70^\circ\text{F} and 20∘F20^\circ\text{F} to the 50∘F50^\circ\text{F} to 85∘F85^\circ\text{F} range where the data was collected.

Plug x=70x = 70 and x=20x = 20 into y=3x−110\model{y} = \model{3}x \model{{}- 110} (at x=20x = 20, watch the negative sign on 60−11060 - 110 so you don't write +50+50):
At 70∘F:y=3(70)−110=100 iced coffeesAt 20∘F:y=3(20)−110=−50 iced coffees\displaystyle \begin{aligned} \text{At } 70^\circ\text{F}:\quad \model{y} &= \model{3}(70) \model{{}- 110} = \pred{100}\text{ iced coffees} \\ \text{At } 20^\circ\text{F}:\quad \model{y} &= \model{3}(20) \model{{}- 110} = \pred{-50}\text{ iced coffees} \end{aligned}
Be careful not to mix up interpolation (inside the data range) and extrapolation (outside it). The 70∘F70^\circ\text{F} prediction is interpolation, so it is generally more reasonable if the line fits the data well. The range alone does not guarantee its accuracy. The 20∘F20^\circ\text{F} prediction is extrapolation, and the result is impossible because you cannot sell −50\pred{-50} coffees.
5

Match each correlation coefficient (r=−0.95r = -0.95, r=0r = 0, r=+0.35r = +0.35) to its scatter plot: (A) dots drifting loosely uphill, (B) dots tightly following a straight downhill line, and (C) dots forming a clean, symmetric arch that rises to a peak and falls back down. Why does Graph C have r=0r = 0 even though it has a clear pattern?

Use the sign of rr for uphill versus downhill, the distance from 00 for how tightly the dots follow a straight line, and consider what happens when a straight line is fit across a symmetric arch.

Do not match Graph C to −0.95-0.95 or +0.35+0.35 just because the arch is a tight curve; rr only sees straight-line trends. Graph A is r=+0.35r = +0.35 (positive for uphill, close to 00 for loose scatter), Graph B is r=−0.95r = -0.95 (negative for downhill, close to −1-1 for tight scatter), and Graph C is r=0r = 0. Graph C has r=0r = 0 because rr only measures straight-line correlation, so the uphill first half and downhill second half of the arch cancel out when a straight line is fit through the middle.
6

Two datasets are each fit with a straight regression line. Dataset 1 has residuals (in order from left to right along the xx-axis) of +3,−4,+1,−2,+3,−1+3, -4, +1, -2, +3, -1. Dataset 2 has residuals of −6,−2,+5,+6,+1,−4-6, -2, +5, +6, +1, -4. For each dataset, state whether a straight line is a good model and explain how the residual plot tells you.

Follow the signs of the residuals from left to right: do they bounce randomly above and below 00, or do they group below 00, arch above 00, and drop back below 00?

Do not just add the residuals together: both datasets add up to 00 (+3−4+1−2+3−1=0\resid{+3} \resid{{}- 4} \resid{{}+ 1} \resid{{}- 2} \resid{{}+ 3} \resid{{}- 1} = 0 and −6−2+5+6+1−4=0\resid{-6} \resid{{}- 2} \resid{{}+ 5} \resid{{}+ 6} \resid{{}+ 1} \resid{{}- 4} = 0), which tells you nothing about whether the pattern is curved. A straight line looks reasonable for Dataset 1 because the residuals alternate above and below zero without a clear curve, though that does not prove the residuals are random. A straight line is not a good model for Dataset 2 because the residuals start negative on the left (−6,−2\resid{-6}, \resid{-2}), are positive in the middle (+5,+6,+1\resid{+5}, \resid{+6}, \resid{+1}), and drop negative on the right (−4\resid{-4}), showing a curved pattern that the line missed.
7

Across the days of a year, a city finds r=0.89r = 0.89 between the number of umbrellas sold and the number of car accidents, with a random scatter on the residual plot. A council member concludes that buying umbrellas causes car accidents. Explain what the math shows, why the council member's conclusion is not justified, and give a plausible third factor that could affect both numbers.

Separate what r=0.89r = 0.89 and the residual plot show about the graph from what a third factor could explain on days with lots of umbrella sales and car crashes.

Do not claim that r=0.89r = 0.89 is a math mistake. It shows a strong positive linear association in the data, and the random residual plot supports using a straight-line model. That does not establish that buying umbrellas causes crashes. Rainy weather is a possible third factor. Rain can increase umbrella sales, while wet roads can increase the risk of car accidents.