The correlation coefficient r¶
Statistics and data · level 7, lesson 4 of 7
A question to start¶
In 1973 the statistician Francis Anscombe published four small data sets, now called Anscombe's quartet. All four have, to two decimal places, the same mean of \(x\), the same mean of \(y\), the same standard deviations, the same line of best fit and the same correlation coefficient, about 0.82. Yet when you draw them, one is a loose upward cloud, one is a perfect curve, one is a perfect line with one stray point, and one is a vertical stack of points with a single point far off to the side.
How can one number be identical for four such different pictures? To answer that you need to know exactly what the number measures, and what it cannot see.
The idea¶
Words first, then a number¶
In level 6 you described scatter plots in words: positive or negative, strong or weak, straight or curved. The correlation coefficient \(r\) (also called Pearson's r) puts a number on two of those words: the direction and the strength of a straight-line pattern.
- \(r\) is always between \(-1\) and \(1\).
- \(r = 1\): every point lies exactly on an upward-sloping straight line.
- \(r = -1\): every point lies exactly on a downward-sloping straight line.
- \(r\) near 0: no straight-line pattern.
- The sign gives the direction; the size (ignoring the sign) gives the strength.
Rough words people use: \(|r|\) above about 0.8 is "strong", about 0.5 to 0.8 "moderate", below about 0.3 "weak". These are habits, not rules; a field like physics expects far stronger correlations than a field like psychology.
Building r from z-scores¶
Here is the idea behind the formula. Draw a dashed vertical line at the mean \(\bar{x}\) and a dashed horizontal line at the mean \(\bar{y}\). They cut the scatter plot into four quadrants.
For each point, find its deviations \(x - \bar{x}\) and \(y - \bar{y}\) and multiply them.
- A point to the upper right has both deviations positive: product positive.
- A point to the lower left has both negative: product positive again.
- Points in the other two quadrants have one positive and one negative deviation: product negative.
If the cloud slopes upward, most points sit in the two positive quadrants, so the products add to a large positive total. If it slopes down, the total is negative. If there is no straight-line trend, the positive and negative products roughly cancel.
The total depends on the units (centimetres give bigger numbers than metres), so we first turn each deviation into a z-score (lesson 3), which has no units. Then
So \(r\) is (almost) the average product of the z-scores. Writing \(s_x\) and \(s_y\) out and cancelling the \(n - 1\) gives the formula you will usually compute with:
where \(S_{xy}\), \(S_{xx}\) and \(S_{yy}\) are short names for the three sums.
Why r can never go past 1 (a real proof)¶
The standardised values satisfy \(\sum z_x^2 = n - 1\), because \(s_x^2 = \dfrac{\sum (x - \bar{x})^2}{n - 1}\) means \(\sum \left(\dfrac{x - \bar{x}}{s_x}\right)^2 = n - 1\). The same holds for \(z_y\).
Now look at the squares \((z_x - z_y)^2\). A square is never negative, so their sum is never negative:
The right side is \(2(n - 1)(1 - r)\). It is at least 0, so \(r \le 1\). Doing the same with \((z_x + z_y)^2\) gives \(2(n - 1)(1 + r) \ge 0\), so \(r \ge -1\).
The proof also tells you when \(r = 1\): only when every \(z_x - z_y\) is 0, so every point has \(z_y = z_x\). That means every point lies on one straight line with positive slope. A perfect correlation is a perfect line, nothing else.
What r does not notice¶
- Units and scale. Changing centimetres to inches, or Celsius to Fahrenheit, does not change the z-scores, so it does not change \(r\). Swapping \(x\) and \(y\) does not change it either.
- Curves. \(r\) measures only straight-line patterns. Five points exactly on the parabola \(y = x^2\), at \(x = -2, -1, 0, 1, 2\), have \(r = 0\): the left half slopes down, the right half slopes up, and the products cancel perfectly. There is a perfect relationship, but no straight-line one.
- Outliers. One point far from the rest can make \(r\) large or small almost on its own.
That is Anscombe's lesson: always draw the scatter plot. \(r\) summarises a picture; it does not replace it.
Worked examples¶
1. A perfect line. \(x\): 1, 2, 3, 4 and \(y = 2x + 1\): 3, 5, 7, 9.
\(\bar{x} = 2.5\), \(\bar{y} = 6\). Deviations: \(x\): \(-1.5, -0.5, 0.5, 1.5\); \(y\): \(-3, -1, 1, 3\). \(S_{xy} = 4.5 + 0.5 + 0.5 + 4.5 = 10\), \(S_{xx} = 2.25 + 0.25 + 0.25 + 2.25 = 5\), \(S_{yy} = 9 + 1 + 1 + 9 = 20\).
\(r = \dfrac{10}{\sqrt{5 \times 20}} = \dfrac{10}{10} =\) 1, as the proof promised for a perfect upward line.
2. A real-looking set, two ways. Hours of practice \(x\) and points \(y\): (1, 2), (2, 4), (3, 5), (4, 4), (5, 5).
\(\bar{x} = 3\), \(\bar{y} = 4\). Deviations: \(x\): \(-2, -1, 0, 1, 2\); \(y\): \(-2, 0, 1, 0, 1\). \(S_{xy} = 4 + 0 + 0 + 0 + 2 = 6\), \(S_{xx} = 10\), \(S_{yy} = 6\).
\(r = \dfrac{6}{\sqrt{60}} \approx\) 0.77: a moderately strong positive correlation.
The z-score way gives the same: \(s_x = \sqrt{10/4} \approx 1.581\), \(s_y = \sqrt{6/4} \approx 1.225\), so \(\sum z_x z_y = \dfrac{S_{xy}}{s_x s_y} = \dfrac{6}{1.936} \approx 3.10\), and \(r \approx 3.10 \div 4 \approx 0.77\). ✓
3. A negative correlation. \(x\): 2, 4, 6, 8; \(y\): 9, 7, 8, 4.
\(\bar{x} = 5\), \(\bar{y} = 7\). Deviations: \(x\): \(-3, -1, 1, 3\); \(y\): \(2, 0, 1, -3\). \(S_{xy} = -6 + 0 + 1 - 9 = -14\), \(S_{xx} = 20\), \(S_{yy} = 4 + 0 + 1 + 9 = 14\).
\(r = \dfrac{-14}{\sqrt{280}} \approx\) −0.84: strong and negative.
4. The parabola. \(x\): \(-2, -1, 0, 1, 2\), \(y = x^2\): 4, 1, 0, 1, 4.
\(\bar{x} = 0\), \(\bar{y} = 2\). \(S_{xy} = (-2)(2) + (-1)(-1) + 0 + (1)(-1) + (2)(2) = -4 + 1 + 0 - 1 + 4 = 0\). So \(r = 0\), although \(y\) is completely decided by \(x\).
5. One outlier. The five points (1, 3), (2, 1), (3, 4), (4, 2), (5, 3) are a shapeless cloud: technology gives \(r \approx 0.14\). Add a sixth point (12, 12), far out to the upper right. Now \(r \approx 0.91\). One point created a "strong correlation" that the other five do not show. Before reporting \(r\), look for points like this and ask if they belong.
Try it¶
- Without calculating, give \(r\) for: (a) Celsius and Fahrenheit temperatures of the same 20 days; (b) the price of an item and the price after a 10% discount; (c) the time left in a race and the distance already run, at a steady speed.
- Compute \(r\) for \(x\): 1, 2, 3, 4 and \(y\): 1, 3, 2, 4.
- Compute \(r\) for \(x\): 1, 2, 3 and \(y\): 5, 3, 1. Explain the answer from a sketch.
- A data set of heights in centimetres and weights in kilograms has \(r = 0.62\). What is \(r\) if heights are changed to metres and weights to pounds?
- Explain why five points on \(y = (x - 2)^2\) at \(x = 0, 1, 2, 3, 4\) have \(r = 0\). Then, with technology, find \(r\) for \(y = x^2\) at \(x = 1, 2, 3, 4, 5, 6\). What does this show?
- For each statement, say true or false and why. (a) \(r = 0.9\) means 90% of the points are on the line. (b) \(r = -0.9\) is a weaker correlation than \(r = 0.5\). (c) \(r = 0\) means \(x\) and \(y\) are not related.
- Use the proof above to show that if \(r = -1\), then \(z_y = -z_x\) for every point.
Answers
- (a) \(r = 1\): \(F = 1.8C + 32\) is an exact upward line. (b) \(r = 1\): the new price is \(0.9 \times\) the old one. (c) \(r = -1\): distance run goes up exactly as time left goes down, in a straight line.
- Means 2.5 and 2.5. Deviations \(x\): \(-1.5, -0.5, 0.5, 1.5\); \(y\): \(-1.5, 0.5, -0.5, 1.5\). \(S_{xy} = 2.25 - 0.25 - 0.25 + 2.25 = 4\), \(S_{xx} = S_{yy} = 5\). \(r = \dfrac{4}{\sqrt{25}} = 0.8\).
- Means 2 and 3. Deviations \(x\): \(-1, 0, 1\); \(y\): \(2, 0, -2\). \(S_{xy} = -2 + 0 - 2 = -4\), \(S_{xx} = 2\), \(S_{yy} = 8\). \(r = \dfrac{-4}{\sqrt{16}} = -1\). The points lie exactly on the line \(y = 7 - 2x\), sloping down.
- Still 0.62. Changing units multiplies each variable by a positive number, which does not change the z-scores.
- \(y\): 4, 1, 0, 1, 4, mean 2; \(x\) deviations \(-2, -1, 0, 1, 2\); \(y\) deviations \(2, -1, -2, -1, 2\). Products: \(-4 + 1 + 0 - 1 + 4 = 0\), so \(r = 0\). For \(y = x^2\) at 1 to 6, \(r \approx 0.98\): a curved pattern can still give a large \(r\). A large \(r\) does not prove the pattern is straight; draw it.
- (a) False: \(r\) is not a percent of points; it measures how closely the whole cloud follows a line. (b) False: strength is the size, so \(-0.9\) is stronger than \(0.5\). (c) False: it means no straight-line relation; there may be a curved one (as in the parabola).
- \(\sum (z_x + z_y)^2 = 2(n - 1)(1 + r)\). If \(r = -1\), this sum is 0. A sum of squares is 0 only if every square is 0, so \(z_x + z_y = 0\), that is \(z_y = -z_x\), for every point: all points lie on one downward line.
Common mistake¶
Reporting r without looking at the graph. A single number cannot tell a line from a curve, or a real trend from one stray point. Draw the scatter plot first, every time.
Reading a strong r as a cause. Even \(r = 0.95\) says nothing about which variable affects which, or whether a third variable drives both. See level 6: correlation is not causation.
Where it leads¶
- Back: z-scores and percentiles · Next: Least-squares regression
- Level 7 page · Statistics topic page
- The idea of \(r\) as a "dot product" of two lists, and the proof that \(|r| \le 1\), is the Cauchy–Schwarz inequality of MAT247 Unit 1 (inner product spaces): \(r\) is the cosine of the angle between the two lists of deviations.
- Covariance and correlation of random variables: Probability.