M5.7.8 Chapter 8

Correlation and regression

A bean plant grows taller each day. How closely do the days and the height go together, and can I predict the height on a day I did not measure?

Your guess

Pick one before you read on. It is fine to be wrong.

Your guess
  • You picked A. Read on. At the end, the chapter comes back to your guess.

  • You picked B. Read on. At the end, the chapter comes back to your guess.

  • You picked C. Read on. At the end, the chapter comes back to your guess.

By the end you can

  • Find and read a correlation coefficient
  • Find a regression line and use it with care
  • Say why correlation does not show cause

So far each chapter had one variable. Often we have two, measured on the same things. A bean plant has a number of days since it was planted and a height. A scatter diagram plots each pair as a point. If the points slope up, the variables are positively correlated. If they slope down, they are negatively correlated. If there is no pattern, there is no correlation.

Draw it first

Draw the scatter diagram and the line

  1. A scatter diagram with the x axis named days from 0 to 9 and the y axis named height in cm from 0 to 14. Step 1 plots eight dots that rise from the left to the right. Step 2 draws a straight line that passes close to all the dots.12345678924681012140daysheight in cm

    1 Plot each pair, the day and the height of the plant, as a dot.

  2. A scatter diagram with the x axis named days from 0 to 9 and the y axis named height in cm from 0 to 14. Step 1 plots eight dots that rise from the left to the right. Step 2 draws a straight line that passes close to all the dots.12345678924681012140daysheight in cm

    2 Draw one straight line through the middle of the dots. This is the line of best fit, and we will find it by a rule, not by eye.

We want a number for how closely the dots follow a straight line. It is the product moment correlation coefficient, r. It is built from three sums that measure spread. For n pairs: Sxx = Σx² − (Σx)² ÷ n, Syy = Σy² − (Σy)² ÷ n and Sxy = Σxy − (Σx)(Σy) ÷ n. Sxx and Syy are the sums of squared deviations from chapter 2, written another way. Sxy does the same with the pairs together: it is positive when high x goes with high y. Then r = Sxy ÷ √(Sxx × Syy).

Why divide like this? The division scales the result. Whatever units we use, r always falls from −1 to 1. The value r = 1 means all the points lie exactly on a rising line, and r = −1 means exactly on a falling line. The nearer r is to 0, the weaker the straight line pattern. Changing the unit, such as cm to mm, does not change r.

A table with the heads x, y, xy and y². The rows read 1, 2.4, 2.4 and 5.76; 2, 3.1, 6.2 and 9.61; 3, 5.5, 16.5 and 30.25; 4, 5.8, 23.2 and 33.64; 5, 8.3, 41.5 and 68.89; 6, 8.4, 50.4 and 70.56; 7, 11, 77 and 121; 8, 11.2, 89.6 and 125.44; and a last row total, 55.7, 306.8 and 465.15.xyxyy²12.42.45.7623.16.29.6135.516.530.2545.823.233.6458.341.568.8968.450.470.5671177121811.289.6125.44total55.7306.8465.15
The days x are 1 to 8, and they add to 36. The squares of the days, x², add to 204. The columns of this table give the other sums.

Worked example

The table gives the height y in cm of a bean plant on day x. The sums are Σx = 36, Σy = 55.7, Σx² = 204, Σy² = 465.15 and Σxy = 306.8, with n = 8. Find the correlation coefficient.

  1. Sxx = 204 − 36² ÷ 8 = 204 − 162 = 42.
  2. Syy = 465.15 − 55.7² ÷ 8 = 465.15 − 387.81 = 77.34.
  3. Sxy = 306.8 − 36 × 55.7 ÷ 8 = 306.8 − 250.65 = 56.15.
  4. r = Sxy ÷ √(Sxx × Syy) = 56.15 ÷ √(42 × 77.34) = 56.15 ÷ 56.99.
  5. So r = 0.985, to 3 decimal places. The relationship is strongly positive and very nearly a straight line.

Answer: r = 0.985

Some values to learn. A value of r near 1 or −1 shows a strong linear relationship. A value near 0 shows no linear relationship. But there is a warning: r measures only straight line patterns.

A scatter diagram with the x axis named x from −4 to 4 and the y axis named y from 0 to 10. Seven dots form a U shaped curve: (−3, 9), (−2, 4), (−1, 1), (0, 0), (1, 1), (2, 4) and (3, 9). The dots are exactly symmetric about the y axis.−4−3−2−112342468100xy
The seven points follow the exact rule y = x², yet r = 0. The left side falls and the right side rises, and these cancel.

The regression line. A line y = a + bx through the points is a good fit when the vertical gaps between the points and the line, the residuals, are small. The least squares line makes the sum of the squared residuals as small as possible. It is the line of y on x, with y the quantity we want to predict. Its slope and intercept are b = Sxy ÷ Sxx and a = ȳ − b x̄, where x̄ and ȳ are the means. The line always passes through the point (x̄, ȳ).

A scatter diagram with the x axis named days from 0 to 9 and the y axis named height in cm from 2 to 12, with a break mark at 2. Eight dots rise from left to right. A straight line passes through the middle of them. A short vertical line joins each dot to the line. These are the residuals.012345678924681012daysheight in cm
The short green lines are the residuals. The least squares line makes the sum of their squares as small as it can be. The residuals above the line and below it add to 0.

Worked example

For the bean plants, Sxx = 42 and Sxy = 56.15, the mean day is 4.5 and the mean height is 6.9625. Find the regression line of height on day.

  1. To 3 decimal places, the slope is b = Sxy ÷ Sxx = 56.15 ÷ 42 = 1.337.
  2. The intercept is a = ȳ − b x̄ = 6.9625 − 1.337 × 4.5 = 6.9625 − 6.0165 = 0.946.
  3. So the line is y = 0.946 + 1.337x, with y in cm and x in days.
  4. In words: on average the plant grows 1.337 cm each day.

Answer: a = 0.946 and b = 1.337

Use the line with care. A prediction from a value of x inside the range of the data, here 1 to 8 days, is an interpolation, and it is usually reliable. A prediction far outside the range is an extrapolation. It assumes the straight line pattern goes on, and it often does not. A plant does not grow 1.3 cm a day for ever.

Worked example

Use the line y = 0.946 + 1.337x to predict the height of the plant on day 5.5. Would you also use it for day 40?

  1. Day 5.5 lies inside the data, which run from day 1 to day 8. This is an interpolation, so we can use the line.
  2. y = 0.946 + 1.337 × 5.5 = 0.946 + 7.3535 = 8.2995.
  3. So the predicted height is 8.30 cm, to 2 decimal places.
  4. Day 40 is far outside the data. The line would give 54.4 cm, but there is no reason to think the plant keeps growing at this rate, so we would not trust it.

Answer: The height is about 8.30 cm.

One more warning, and the most important. Two variables can be strongly correlated without one causing the other. In hot weather more people swim, and more people also get sunburn. Swimming and sunburn have a high correlation, but the heat is a cause of both. A high r shows that two things go together. Only a careful experiment can show that one causes the other. Also, the line of y on x is for predicting y from x. Do not use it to predict x from y.

See it three ways

With things

Measure the hand span and the forearm length of eight people. Plot the pairs. People with larger spans tend to have longer forearms, and the points rise from left to right.

As a picture

A table with the heads r near and means. The rows read 1 and rising line; 0 and no line; −1 and falling line.r nearmeans1rising line0no line−1falling line

In words

The correlation coefficient says how closely the points follow a straight line, from −1 to 1. The regression line is the best straight line for predicting y.

In symbols

r = Sxy ÷ √(Sxx Syy). b = Sxy ÷ Sxx. a = ȳ − b x̄. The line is y = a + bx.

Try it

Plot your own pairs

You need: a ruler in centimetres, eight people, graph paper or plain paper.

  1. Measure the hand span of each person, tip of thumb to tip of little finger, in cm. Then measure their forearm, elbow to wrist, in cm.
  2. Plot each pair as a dot. Put the hand span along the bottom and the forearm length up the side.
  3. Hold a ruler on the page and slide it until it runs through the middle of the dots. Draw the line.

What you will see: Most people see the dots rise from left to right with some scatter. A calculator can give r and the regression line. You will usually find a clear positive r, but one unusual person can change the line a lot.

If you cannot try it, this is what happens.
A scatter diagram with the x axis named hand span in cm from 14 to 24 and the y axis named forearm in cm from 20 to 30. Eight dots rise from the left to the right.141618202224202224262830hand span in cmforearm in cm

A wrong idea many people have

A correlation coefficient close to 0 means the two variables are not related at all.

Why it feels right: A coefficient of 0 sounds like "nothing going on", and a related pair should show a pattern.

The test that breaks it: Take the seven points on the curve y = x² at x = −3, −2, −1, 0, 1, 2, 3. The relation is exact, yet r = 0, because the left side falls, the right side rises, and the two cancel.

What is true: The coefficient r measures only a straight line pattern. A value near 0 means there is no linear relationship. There may still be a curved one, so always look at the scatter diagram.

A wrong idea many people have

A high correlation shows that one variable causes the other.

Why it feels right: When two things move together, it feels natural to think that one pulls the other along.

The test that breaks it: On hot days more people swim, and more people get sunburn. The number of swimmers and the number of sunburn cases have r close to 1. Yet swimming does not cause sunburn here: the sun does, and the sun is also why people swim.

What is true: Correlation shows that two variables go together. It does not show why. A third variable may cause both, or the link may be chance.

Key words

correlation coefficient
r, from −1 to 1, which measures how closely points follow a straight line.
regression line
the least squares line y = a + bx, used to predict y from x.
residual
the vertical distance from a point to the line. The least squares line makes the sum of their squares smallest.
extrapolation
using the line for x far outside the data. It is unreliable. Using it inside the data is interpolation.

Back to your guess

The answer is A: The points lie close to a rising line, so a correlation coefficient of about 0.98 fits.

The coefficient is about 0.98. It is positive because the line rises, and it is close to 1 because the points lie close to the line. A correlation coefficient can never be below −1 or above 1, so 1.98 is impossible.

Check yourself

Try each one before you look. A wrong answer tells you where to go next.

  1. Which of these values cannot be a correlation coefficient?

    Tap your answer.
    1. Not this one. A value from −1 to 1 is possible, and 0.4 is a weak positive correlation. Read this page again. Try another.

    2. Yes, that is right. The correlation coefficient always lies from −1 to 1. The value 1.3 is outside this range, so it cannot be r.

    3. Not this one. A value from −1 to 1 is possible, and −0.8 is a strong negative correlation. Read this page again. Try another.

    See the answer

    1.3

    The correlation coefficient always lies from −1 to 1. The value 1.3 is outside this range, so it cannot be r.

    • If you chose A: A value from −1 to 1 is possible, and 0.4 is a weak positive correlation. Read this page again.
    • If you chose C: A value from −1 to 1 is possible, and −0.8 is a strong negative correlation. Read this page again.
  2. A correlation coefficient of −0.92 is found for two variables. What does it show?

    Tap your answer.
    1. Yes, that is right. The size, 0.92, is close to 1, so the points lie close to a straight line. The minus sign means the line falls as x rises.

    2. Not this one. The sign is negative, so one variable falls as the other rises. And 0.92 is close to 1, so it is strong. Read this page again. Try another.

    3. Not this one. The size 0.92 is strong, but the minus sign means the line falls as x rises. Read this page again. Try another.

    See the answer

    A strong negative linear relationship.

    The size, 0.92, is close to 1, so the points lie close to a straight line. The minus sign means the line falls as x rises.

    • If you chose B: The sign is negative, so one variable falls as the other rises. And 0.92 is close to 1, so it is strong. Read this page again.
    • If you chose C: The size 0.92 is strong, but the minus sign means the line falls as x rises. Read this page again.
  3. A set of points has r = 0. Which statement is true?

    Tap your answer.
    1. Yes, that is right. The coefficient r measures only straight line patterns. A curve such as y = x² can have r = 0.

    2. Not this one. The points on y = x² are exactly related, yet r = 0. A zero value only rules out a straight line pattern. Read this page again. Try another.

    3. Not this one. A flat line has no change in y, so r is not defined for it. A value of 0 is for a cloud or a curve with no linear pattern. Read this page again. Try another.

    See the answer

    There is no linear relationship, but there might be a curved one.

    The coefficient r measures only straight line patterns. A curve such as y = x² can have r = 0.

    • If you chose B: The points on y = x² are exactly related, yet r = 0. A zero value only rules out a straight line pattern. Read this page again.
    • If you chose C: A flat line has no change in y, so r is not defined for it. A value of 0 is for a cloud or a curve with no linear pattern. Read this page again.
  4. On hot days the number of swimmers and the number of sunburn cases have a high positive correlation. What can we conclude?

    Tap your answer.
    1. Not this one. The sun burns the skin, not the water. A high r alone cannot show what causes what. Read this page again. Try another.

    2. Not this one. No evidence points that way. Correlation does not say which variable acts on the other. Read this page again. Try another.

    3. Yes, that is right. A third variable, the heat, can drive both counts. Correlation shows that the two go together, not that one causes the other.

    See the answer

    Hot weather may cause both, so correlation alone does not show cause.

    A third variable, the heat, can drive both counts. Correlation shows that the two go together, not that one causes the other.

    • If you chose A: The sun burns the skin, not the water. A high r alone cannot show what causes what. Read this page again.
    • If you chose B: No evidence points that way. Correlation does not say which variable acts on the other. Read this page again.
  5. A line y = 2.1 + 0.9x was fitted to data with x from 1 to 8 days. Which prediction would you trust least?

    Tap your answer.
    1. Not this one. Day 4 is inside the data from 1 to 8 days, so this is an interpolation and is usually reliable. Read this page again. Try another.

    2. Not this one. Day 7 is inside the data from 1 to 8 days, so this is an interpolation and is usually reliable. Read this page again. Try another.

    3. Yes, that is right. The x value 30 is far outside the data, which run from 1 to 8. That is an extrapolation, and the straight line pattern may not continue.

    See the answer

    The value at x = 30 days.

    The x value 30 is far outside the data, which run from 1 to 8. That is an extrapolation, and the straight line pattern may not continue.

    • If you chose A: Day 4 is inside the data from 1 to 8 days, so this is an interpolation and is usually reliable. Read this page again.
    • If you chose B: Day 7 is inside the data from 1 to 8 days, so this is an interpolation and is usually reliable. Read this page again.
  6. In the line y = a + bx, the slope is b = 0.9, with y the height in cm and x the day. What does it mean?

    Tap your answer.
    1. Not this one. That would be the intercept a, the value of y when x = 0. The slope is the change per day. Read this page again. Try another.

    2. Yes, that is right. The slope b is the change in y for a change of 1 in x. Here that is 0.9 cm of growth for each extra day.

    3. Not this one. That is true only when a = 0. The slope is the change in height for one more day. Read this page again. Try another.

    See the answer

    The plant grows 0.9 cm more for each extra day, on average.

    The slope b is the change in y for a change of 1 in x. Here that is 0.9 cm of growth for each extra day.

    • If you chose A: That would be the intercept a, the value of y when x = 0. The slope is the change per day. Read this page again.
    • If you chose C: That is true only when a = 0. The slope is the change in height for one more day. Read this page again.
  7. From an earlier chapter

    H₀: μ = 50, the standard deviation is 10 and a sample of 25 values has mean 53. What is the test statistic z?

    Tap your answer.
    1. Not this one. You divided by the standard deviation of one value, 10. Divide by the standard error, 10 ÷ √25 = 2. Go to M5.7.7. Try another.

    2. Yes, that is right. The standard error is 10 ÷ √25 = 2. Then z = (53 − 50) ÷ 2 = 1.5.

    3. Not this one. You divided by 10 ÷ 25. The standard error divides σ by the square root of n, which is 5. Go to M5.7.7. Try another.

    See the answer

    1.5

    The standard error is 10 ÷ √25 = 2. Then z = (53 − 50) ÷ 2 = 1.5.

    • If you chose A: You divided by the standard deviation of one value, 10. Divide by the standard error, 10 ÷ √25 = 2. Go to M5.7.7.
    • If you chose C: You divided by 10 ÷ 25. The standard error divides σ by the square root of n, which is 5. Go to M5.7.7.
  8. For some data, Sxx = 25, Syy = 64 and Sxy = 36. Find the correlation coefficient r.

    See the answer

    0.9

    r = Sxy ÷ √(Sxx × Syy) = 36 ÷ √(25 × 64) = 36 ÷ √1600 = 36 ÷ 40 = 0.9.

  9. For 10 pairs, Σx = 50, Σy = 140, Σx² = 290 and Σxy = 760. Find the slope b of the regression line of y on x.

    See the answer

    1.5

    Sxx = 290 − 50² ÷ 10 = 290 − 250 = 40. Sxy = 760 − 50 × 140 ÷ 10 = 760 − 700 = 60. So b = 60 ÷ 40 = 1.5.

  10. For the same 10 pairs, Σx = 50, Σy = 140, Σx² = 290 and Σxy = 760, the slope is b = 1.5. Find the intercept a.

    See the answer

    6.5

    The mean of x is 50 ÷ 10 = 5 and the mean of y is 140 ÷ 10 = 14. Then a = ȳ − b x̄ = 14 − 1.5 × 5 = 14 − 7.5 = 6.5.

  11. A regression line is y = 2.1 + 0.9x, with x in days and y the height in cm. Predict the height on day 6, in cm.

    See the answer

    7.5

    y = 2.1 + 0.9 × 6 = 2.1 + 5.4 = 7.5 cm.

Keep it

Copy this into your exercise book.

r = Sxy ÷ √(Sxx Syy), from −1 to 1. Line y = a + bx: b = Sxy ÷ Sxx, a = ȳ − b x̄, through (x̄, ȳ). Predict inside the data. Correlation is not cause.

Draw: A scatter diagram with a line through the middle and a short residual line from each dot to it.

Reading with a child? A short page for the adult: what this chapter teaches and three questions to ask.

No internet tomorrow? Save the whole book as one file (1.1 MB). It opens on any phone.