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.
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 Plot each pair, the day and the height of the plant, as a dot.
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.
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.
- Sxx = 204 − 36² ÷ 8 = 204 − 162 = 42.
- Syy = 465.15 − 55.7² ÷ 8 = 465.15 − 387.81 = 77.34.
- Sxy = 306.8 − 36 × 55.7 ÷ 8 = 306.8 − 250.65 = 56.15.
- r = Sxy ÷ √(Sxx × Syy) = 56.15 ÷ √(42 × 77.34) = 56.15 ÷ 56.99.
- 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.
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̄, ȳ).
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.
- To 3 decimal places, the slope is b = Sxy ÷ Sxx = 56.15 ÷ 42 = 1.337.
- The intercept is a = ȳ − b x̄ = 6.9625 − 1.337 × 4.5 = 6.9625 − 6.0165 = 0.946.
- So the line is y = 0.946 + 1.337x, with y in cm and x in days.
- 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?
- 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.
- y = 0.946 + 1.337 × 5.5 = 0.946 + 7.3535 = 8.2995.
- So the predicted height is 8.30 cm, to 2 decimal places.
- 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
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.
- 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.
- Plot each pair as a dot. Put the hand span along the bottom and the forearm length up the side.
- 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.
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.
Which of these values cannot be a correlation coefficient?
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.
A correlation coefficient of −0.92 is found for two variables. What does it show?
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.
A set of points has r = 0. Which statement is true?
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.
On hot days the number of swimmers and the number of sunburn cases have a high positive correlation. What can we conclude?
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.
A line y = 2.1 + 0.9x was fitted to data with x from 1 to 8 days. Which prediction would you trust least?
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.
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?
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.
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?
See the answer
1.5
The standard error is 10 ÷ √25 = 2. Then z = (53 − 50) ÷ 2 = 1.5.
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.
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.
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.
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.