Educerie

Educerie · IB Diploma · Mathematics: analysis and approaches

IB Mathematics AA 4.4 · SL and HL

Correlation and regression

When two quantities seem to move together, how do you measure how strongly, draw the straight line that best describes them, and know when a prediction from it can be trusted?

What you will learn

  • Know how to describe correlation on a scatter diagram by direction, strength and shape
  • Understand what Pearson's r measures, that it suits only straight-line patterns, and how a critical value is used
  • Know that the regression line of y on x passes through the mean point and is for predicting y
  • Understand why extrapolation is unreliable and why correlation does not show causation

You must be able to

  1. Find r and the regression line of y on x with a GDC, and use the line to predict y
  2. Interpret the gradient and intercept of y = ax + b in context
  3. Comment on the reliability of a prediction, naming interpolation or extrapolation
  4. Describe the correlation shown by a scatter diagram or a value of r
  5. Draw a line of best fit by eye through the mean point, and use the mean point to find a missing coefficient
  6. Explain why a correlation does not show cause, naming a likely hidden variable

In the exam. mainly Paper 2, where the GDC finds rr and the regression line: a typical question gives a table of 6 to 10 pairs and asks for rr, a description of the correlation, the equation of the line, a prediction, and a comment on its reliability (6 to 10 marks across its parts). Paper 1 can ask you to describe a printed scatter diagram, draw a line by eye through a given mean point, find a missing coefficient from the mean point, or interpret aa and bb in context. "Correlation does not imply causation" is a reliable 1 or 2 marks on either paper.

1Scatter diagrams and the language of correlation

Decide which variable is which before you draw anything.

  • The independent variable is the one you control, or the one you suspect is doing the influencing. It goes on the horizontal axis as xx.
  • The dependent variable responds. It goes on the vertical axis as yy.
  • Books also say explanatory and response.

Example: to predict a pupil's mark from revision hours, hours are xx and marks are yy.

Use even scales that fill the grid. Label each axis with quantity and unit. Mark each pair with a small cross. Figure 1 shows the six patterns you must be able to name.

Figure 1 · Six scatter diagrams and their r Strong positive: r = 0.98 x y Weak positive: r = 0.42 x y No correlation: r = 0.01 x y Weak negative: r = −0.40 x y Strong negative: r = −0.98 x y Strong, but not linear: r = 0.01 x y The last one has a clear pattern, but r is near 0 because the pattern is not a straight line.
Figure 1 · Six scatter diagrams and their r

Describe a scatter diagram in two parts, then check the shape.

  • Direction.
    • Positive: larger xx goes with larger yy, on the whole.
    • Negative: larger xx goes with smaller yy, on the whole.
    • None: the cloud slopes neither way.
  • Strength.
    • Strong: the points hug a straight line.
    • Weak: there is a trend, but the points straggle far from any line.
  • Shape. Does a straight line suit the points at all? A curve means linear correlation is the wrong idea, however tight the points are.

"On the whole" matters. Individual points often break the trend. Correlation describes the overall drift.

The last panel of Figure 1 is the warning case. The points follow a perfect arch, yet r≈0r \approx 0. rr only picks up straight-line patterns.

2Pearson's rr

Example (invented): one data set runs through the rest of this note. A drinks kiosk recorded the day's maximum temperature and the iced drinks it sold on ten days.

Temperature xx (∘C^{\circ}\mathrm{C})14171820222325272931
Iced drinks sold yy425551647068818690101

On the GDC, enter the xx values in one list and the yy values in a second. Then ask for a linear regression of the form ax+bax+b.

  • TI-84: STAT, CALC, LinReg(ax+b), after switching diagnostics on so that rr is shown.
  • Casio: Statistics, CALC, REG, then the ax+b option.

One run reports aa, bb and rr together.

For the kiosk, r=0.990r = 0.990 to 3 s.f.

rr always lies from −1-1 to 11. The sign tells the direction. The distance from zero tells the strength.

rrMeaning
r=1r = 1perfect positive linear correlation: every point exactly on a rising line
close to 11strong positive
a little above 00weak positive
about 00no linear correlation
a little below 00weak negative
close to −1-1strong negative
r=−1r = -1perfect negative linear correlation: every point exactly on a falling line

The syllabus gives no hard boundaries. A workable rule of thumb for ∣r∣\lvert r\rvert:

  • above about 0.750.75: strong
  • 0.50.5 to 0.750.75: moderate
  • 0.250.25 to 0.50.5: weak
  • below 0.250.25: very weak or none

Interpreting rr in context = give direction, strength and both variables by name.

  • Example: for the kiosk, "There is a strong positive linear correlation between maximum temperature and iced drinks sold. Hotter days tend to have more sales."
  • A value close to ±1\pm 1 also tells you a straight-line model is sensible, because the points lie near a line. A value near 0, or a curved scatter diagram, tells you a regression line is not appropriate.
  • Technology finds rr in the exam. Seeing the working once explains how rr behaves.
  • Draw a vertical and a horizontal line through the mean point (xˉ,yˉ)=(22.6,70.8)(\bar{x}, \bar{y}) = (22.6, 70.8). They cut the diagram into four quadrants, as in Figure 2.
  • For every point, multiply how far it sits from xˉ\bar{x} (left or right) by how far it sits from yˉ\bar{y} (below or above).
    • Upper right and lower left give positive products.
    • Upper left and lower right give negative ones.
  • Adding all the products gives:
Figure 2 · Why r is positive here 10 15 20 25 30 35 Maximum temperature x (°C) 30 40 50 60 70 80 90 100 110 Iced drinks sold y above and right: + × + = + below and left: − × − = + above and left: − × + = − below and right: + × − = − x̄ = 22.6 ȳ = 70.8 Points top-right and bottom-left of the mean point add to r; top-left and bottom-right would subtract.
Figure 2 · Why r is positive here
Sxy=∑(x−xˉ)(y−yˉ)=912.2almost every point lies in a + quadrantS_{xy} = \sum (x - \bar{x})(y - \bar{y}) = 912.2 \qquad \textcolor{#838c91}{\text{almost every point lies in a }+\text{ quadrant}}Sxx=∑(x−xˉ)2=270.4,Syy=∑(y−yˉ)2=3141.6S_{xx} = \sum (x - \bar{x})^{2} = 270.4, \quad S_{yy} = \sum (y - \bar{y})^{2} = 3141.6r=SxySxx×Syy=912.2270.4×3141.6=0.990r = \frac{S_{xy}}{\sqrt{S_{xx} \times S_{yy}}} = \frac{912.2}{\sqrt{270.4 \times 3141.6}} = 0.990
  • The top is large and positive because nearly all the points are in the two positive quadrants. Points sprinkled over all four would cancel, and rr would sit near 0.
  • Dividing by the square root only rescales the answer into −1-1 to 11, whatever the units. You will not do this by hand, but it explains three facts:
    • rr has no units.
    • Swapping the roles of xx and yy leaves rr unchanged.
    • One point far from the mean point, in the wrong quadrant, can drag rr a long way (Figure 6 shows this).
  • With few pairs, a pattern can show up by luck. A question may give a critical value for your number of pairs. Compare it with ∣r∣\lvert r\rvert.
    • If ∣r∣\lvert r\rvert is larger, the linear correlation is significant: it is unlikely to be a fluke of a small sample.
    • If not, the evidence is too weak to rely on.
  • Critical values are always supplied.
    • Example: for ten pairs a question might give 0.6320.632. The kiosk has r=0.990>0.632r = 0.990 > 0.632, so its correlation is significant.

3A line of best fit by eye

A line of best fit summarises the trend in one straight line. Drawn by eye, it must pass through the mean point (xˉ,yˉ)(\bar{x}, \bar{y}). The points should sit about equally above and below it along its whole length.

Figure 3 shows one for the kiosk.

Figure 3 · A line of best fit by eye, through the mean point 10 15 20 25 30 35 Maximum temperature x (°C) 30 40 50 60 70 80 90 100 110 Iced drinks sold y (x̄, ȳ) = (22.6, 70.8) Mean point (22.6, 70.8). Pivot a ruler about it until the points are balanced either side.
Figure 3 · A line of best fit by eye, through the mean point

The method:

  • Work out xˉ\bar{x} and yˉ\bar{y}, and plot that mean point clearly.
  • Lay a ruler on it and pivot it until the points balance on both sides.

The line need not go through the origin or through the first and last points. Both are common errors.

To find the equation of a line drawn by eye, read a second point off your line. Use it with the mean point to get the gradient.

Example: suppose the line in Figure 3 also passes through (30,95)(30, 95).

gradient=95−70.830−22.6=24.27.4=3.27…\text{gradient} = \frac{95 - 70.8}{30 - 22.6} = \frac{24.2}{7.4} = 3.27\ldotsy−70.8=3.27(x−22.6)⇒y≈3.27x−3.1a line drawn by eye depends on your ruler, so answers differ a littley - 70.8 = 3.27(x - 22.6) \quad \Rightarrow \quad y \approx 3.27x - 3.1 \qquad \textcolor{#838c91}{\text{a line drawn by eye depends on your ruler, so answers differ a little}}

This is not the regression line, which is why its numbers differ from the GDC's.

4The regression line of yy on xx

  • Lines drawn by eye vary. Every calculator agrees on the regression line of yy on xx.
    • It is chosen so that the vertical gaps between the points and the line are as small as possible overall. It minimises the sum of the squares of those gaps, so it is also called the least squares line.
  • Each vertical gap is a residual. A point above the line has a positive residual, because the line predicted too little there. A point below has a negative one. Figure 4 draws them.
Figure 4 · The regression line of y on x 10 15 20 25 30 35 Maximum temperature x (°C) 30 40 50 60 70 80 90 100 110 Iced drinks sold y y = 3.37x − 5.44 vertical distances, e.g. 51 below 55.3 It makes the vertical distances from the points as small as possible overall (least squares).
Figure 4 · The regression line of y on x

For the kiosk, the GDC gives:

a=3.37352…,b=−5.44156…a = 3.37352\ldots, \quad b = -5.44156\ldotsy=3.37x−5.44coefficients to 3 s.f.y = 3.37x - 5.44 \qquad \textcolor{#838c91}{\text{coefficients to 3 s.f.}}check: 3.37352×22.6−5.44156=70.8=yˉ, so the line passes through the mean point\text{check: } 3.37352 \times 22.6 - 5.44156 = 70.8 = \bar{y}\text{, so the line passes through the mean point}

The regression line always passes through (xˉ,yˉ)(\bar{x}, \bar{y}). This is a Paper 1 favourite, with no GDC. Two kinds of question use it:

  • Missing intercept. If y=0.6x+by = 0.6x + b passes through the mean point (35,52)(35, 52), then 52=0.6×35+b=21+b52 = 0.6 \times 35 + b = 21 + b, so b=31b = 31.
  • Missing mean. If the regression line is y=0.8x+6.4y = 0.8x + 6.4 and xˉ=20\bar{x} = 20, then yˉ=0.8×20+6.4=22.4\bar{y} = 0.8 \times 20 + 6.4 = 22.4.

Interpret aa and bb by saying what each one means in the context of the question, with units.

  • a=3.37a = 3.37. Each extra 1 ∘C1\ ^{\circ}\mathrm{C} of maximum temperature goes with about 3.373.37 more iced drinks sold, on average.
  • A change in xx. Multiply aa by the change in xx. A 5 ∘C5\ ^{\circ}\mathrm{C} rise gives 5×3.37=16.95 \times 3.37 = 16.9, roughly 17, extra drinks. The intercept cancels out, so bb is not needed.
  • b=−5.44b = -5.44. It is the line's value at x=0x = 0, a day at 0 ∘C0\ ^{\circ}\mathrm{C}. It is negative, so not a sales figure. 0 ∘C0\ ^{\circ}\mathrm{C} lies far outside the data (14 ∘C14\ ^{\circ}\mathrm{C} to 31 ∘C31\ ^{\circ}\mathrm{C}). So bb has no real meaning here. Say that: it is where the line meets the vertical axis.

A second example shows a case where bb does mean something.

Example (invented): a canteen noted the portions of soup left, yy, at xx minutes after opening, at six times.

Minutes since opening xx1030507090110
Portions left yy806658443324
r=−0.998,y=−0.561x+84.5a = -0.56143…, b = 84.519…r = -0.998, \quad y = -0.561x + 84.5 \qquad \textcolor{#838c91}{\text{a = -0.56143\ldots, b = 84.519\ldots}}
  • Here rr is close to −1-1, so a straight line suits the data.
    • The gradient says that every extra minute the canteen is open uses up about 0.560.56 portions, on average.
    • The intercept says that about 84 or 85 portions were available at opening. x=0x = 0 is a real moment, just outside the data. So this time the intercept deserves a sentence.
  • At 40 minutes the line predicts −0.56143×40+84.519=62.06-0.56143 \times 40 + 84.519 = 62.06, so about 62 portions.
  • Keep full calculator precision. Round only the final answer.

5Predictions: interpolation, extrapolation and direction

To predict, substitute an xx value into the line. Example: a 24 ∘C24\ ^{\circ}\mathrm{C} day.

y=3.37352×24−5.44156=75.5about 75 or 76 drinksy = 3.37352 \times 24 - 5.44156 = 75.5 \qquad \textcolor{#838c91}{\text{about 75 or 76 drinks}}

24 ∘C24\ ^{\circ}\mathrm{C} lies within the xx values observed, so this is interpolation. Combined with r=0.990r = 0.990, it is a reliable estimate. Figure 5 shades the region where the line can be trusted.

Figure 5 · Inside the data, and outside it 0 5 10 15 20 25 30 35 40 Maximum temperature x (°C) −20 0 20 40 60 80 100 120 140 Iced drinks sold y interpolation extrapolation extrapolation 24 °C: ≈ 75.5 40 °C: ≈ 129? Predictions for 14 ≤ x ≤ 31 °C are interpolation. At 0 °C the line predicts −5 drinks.
Figure 5 · Inside the data, and outside it
  • Extrapolation = a prediction outside the observed range of xx.
    • Example: the line gives about 129 drinks at 40 ∘C40\ ^{\circ}\mathrm{C}. The data say nothing about whether the straight-line pattern survives that far. The kiosk may sell out. At 0 ∘C0\ ^{\circ}\mathrm{C} the line gives −5-5 drinks, which is plainly absurd.
  • However high rr is, an extrapolated value is unreliable. Say so precisely: "x=40x = 40 lies outside the data range 14≤x≤3114 \le x \le 31, so this is extrapolation and the prediction is unreliable."
  • The soup line reaches zero at about 150 minutes, but the data stop at 110. That too is a guess.

Predicting xx

  • The yy-on-xx line is built to predict yy, because it minimises vertical gaps. Turning it around to find xx does not minimise the right gaps, so the answer is not the best estimate.
  • The right tool is the regression line of xx on yy. It minimises horizontal gaps and is the subject of 4.10. Use it whenever a question gives it or asks for an estimate of xx.
  • The two lines coincide only when r=±1r = \pm 1. The weaker the correlation, the further apart they pull. They cross at the mean point.

Use the yy-on-xx line only to predict yy, and only for an xx inside the data range. A strong rr does not rescue an extrapolation.

How much to trust a prediction: run through these and mention whichever apply.

  • Is ∣r∣\lvert r\rvert large, ideally past the critical value?
  • Is the xx value inside the observed range?
  • Is the sample big enough, and from the population you are predicting for? One kiosk's line may fail in another city.

One odd pair can reshape rr.

Example: in Figure 6, a single extra day has a maximum of 30 ∘C30\ ^{\circ}\mathrm{C} and only 40 drinks sold, because the ice ran out. It cuts rr from 0.9900.990 to 0.6230.623.

Then decide what to do with the odd point (4.1).

  • A mistake in recording or plotting: correct it or leave it out.
  • A genuine observation with a cause, as the empty ice box is: keep it, name the cause, and note that it weakens the correlation.
Figure 6 · One unusual day changes r a lot 10 days: r = 0.990 10 15 20 25 30 35 Temperature (°C) 30 50 70 90 110 Drinks sold 11 days: r = 0.623 10 15 20 25 30 35 Temperature (°C) 30 50 70 90 110 Adding a single day (30 °C, 40 drinks: the kiosk ran out of ice) drops r from 0.990 to 0.623.
Figure 6 · One unusual day changes r a lot

6Correlation is not causation

A strong correlation says that two variables move together. It does not say that one makes the other move.

There are three usual explanations when correlation has no direct cause behind it:

  • A hidden (confounding) variable. It drives both. Across a summer, iced drink sales and cases of sunburn rise and fall together. Neither causes the other: hot, sunny weather causes both, as Figure 7 shows.
  • Coincidence. This is likely when there are few points, or when many pairs of variables have been tried and only the impressive ones reported.
  • The cause runs the other way. Pupils who sleep less tend to get lower marks. Poor sleep might hurt performance. Worry about low marks might also keep pupils awake. A heavy workload might do both.
Figure 7 · Correlation without causation Hot weather the hidden variable Iced drinks sold rises on hot days Sunburn cases rise on hot days causes causes correlated no arrow Hot weather drives both. Banning iced drinks would not prevent a single sunburn.
Figure 7 · Correlation without causation
  • The guide's own example shows the other side of the coin. The link between smoking and lung cancer first appeared as a correlation in data. It was later scientific work on how smoke harms lung tissue, not the correlation by itself, that established a cause.
  • In the exam, the bare sentence "correlation does not imply causation" is rarely enough. Add a believable hidden variable from the question's context, or a reason the cause might run backwards.

Practice questions

46 questions on this note, from easy to hard. Each one you get right lights a star of this topic's constellation.