Probability & Statistics · Unit 2 · Topic 07

Correlation: do two things move together?

Short answer

Karl Pearson's coefficient \(r = \dfrac{\operatorname{Cov}(x, y)}{\sigma_x \sigma_y}\) measures how closely the points lie on a straight line. It always lies between \(-1\) and \(1\).

For ranks, use Spearman's \(\rho = 1 - \dfrac{6\sum d^2}{n(n^2 - 1)}\). Example: \(\operatorname{Cov} = 18\), \(\sigma_x = 5\), \(\sigma_y = 6\) gives \(r = 0.6\).

Engineering MathsBScStatistics
01

What correlation measures

Do students who score well in maths also score well in physics? Does demand fall when price rises? Correlation answers questions like these with one number. It measures how closely two variables move together along a straight line.

Start with a scatter diagram: plot each pair \((x, y)\) as a dot. If the dots rise from left to right, the correlation is positive. If they fall, it is negative. If they form a shapeless cloud, there is little or no linear correlation.

Three scatter diagrams: points rising from left to right, points falling from left to right, and points with no pattern. positive r = 0.98 negative r = −0.94 no correlation r = 0.02
Each dot is one pair \((x, y)\). Left: as \(x\) grows, \(y\) tends to grow, so \(r\) is close to \(+1\). Middle: \(y\) tends to fall, so \(r\) is close to \(-1\). Right: no straight-line pattern, so \(r\) is near 0.
Karl Pearson's coefficient of correlation

\[r = \frac{\operatorname{Cov}(x, y)}{\sigma_x\,\sigma_y} = \frac{\sum (x - \bar x)(y - \bar y)}{\sqrt{\sum (x - \bar x)^2\,\sum (y - \bar y)^2}}\]

Working form (raw sums)

\[r = \frac{n\sum xy - \sum x \sum y}{\sqrt{n\sum x^2 - \left(\sum x\right)^2}\,\sqrt{n\sum y^2 - \left(\sum y\right)^2}}\]

Why it works: when \(x\) is above its mean and \(y\) is also above its mean, the product \((x - \bar x)(y - \bar y)\) is positive. Same when both are below. So if the variables move together, most products are positive and the sum is large and positive. Dividing by the two spreads turns this into a pure number between \(-1\) and \(1\).

02

Properties of r

  • \(-1 \le r \le 1\). \(r = 1\) means all points lie on a rising straight line, \(r = -1\) on a falling one.
  • \(r\) has no units. Heights in cm or in inches give the same \(r\).
  • Independent of change of origin and scale. If \(u = \dfrac{x - a}{h}\) and \(v = \dfrac{y - b}{k}\) with \(h, k > 0\), then \(r_{uv} = r_{xy}\). If \(h\) and \(k\) have opposite signs, \(r\) changes sign only.
  • Symmetric: \(r_{xy} = r_{yx}\).
  • Independent variables have \(r = 0\), but \(r = 0\) does not prove independence. For \(x = -2, -1, 0, 1, 2\) and \(y = x^2\), \(r = 0\) even though \(y\) is fixed by \(x\). The relation is just not a straight line.

The origin-and-scale property is what makes hand calculation bearable: subtract a convenient number from each value, divide by a common factor, and work with small integers.

03

Spearman's rank correlation

Sometimes you only have ranks (two judges ranking contestants), or the data are marks where only the order matters. Then use Spearman's coefficient, which is Pearson's \(r\) applied to the ranks, simplified.

Spearman's rank correlation

\[\rho = 1 - \frac{6\sum d^2}{n(n^2 - 1)}\]

\(d\) = difference between the two ranks of each item, \(n\) = number of items.

With tied ranks

Give tied values the average of the ranks they occupy. Then for each group of \(m\) tied values add \(\dfrac{m(m^2 - 1)}{12}\) to \(\sum d^2\): \[\rho = 1 - \frac{6\left[\sum d^2 + \sum \frac{m(m^2 - 1)}{12}\right]}{n(n^2 - 1)}\]

  1. Rank each variable separately, both in the same direction (largest = 1, say).
  2. Average the ranks of ties. Three values sharing places 2, 3, 4 each get rank 3.
  3. Find \(d\) and \(d^2\) for each item. Check that \(\sum d = 0\).
  4. Substitute, adding the tie correction if there were ties.
04

Solved examples

Example 1: Deviations from the mean

Easy

Find Karl Pearson's \(r\) for \(x\): 1, 2, 3, 4, 5 and \(y\): 2, 4, 5, 4, 5.

  1. \(\bar x = 3\), \(\bar y = 4\). Deviations \(X = x - 3\): \(-2, -1, 0, 1, 2\). \(Y = y - 4\): \(-2, 0, 1, 0, 1\).
  2. \(\sum XY = 4 + 0 + 0 + 0 + 2 = 6\), \(\sum X^2 = 10\), \(\sum Y^2 = 4 + 0 + 1 + 0 + 1 = 6\).
  3. \(r = \dfrac{6}{\sqrt{10 \times 6}} = \dfrac{6}{\sqrt{60}}\).

Answer\(r \approx 0.7746\), a fairly strong positive correlation

Example 2: Raw sums, negative correlation

Medium

Price \(x\) (in ₹) and demand \(y\) (in units): \(x\): 2, 4, 6, 8, 10 and \(y\): 20, 17, 15, 10, 8. Find \(r\).

  1. \(n = 5\), \(\sum x = 30\), \(\sum y = 70\), \(\sum x^2 = 220\), \(\sum y^2 = 1078\), \(\sum xy = 358\).
  2. Numerator: \(5(358) - 30(70) = 1790 - 2100 = -310\).
  3. \(n\sum x^2 - (\sum x)^2 = 1100 - 900 = 200\) and \(n\sum y^2 - (\sum y)^2 = 5390 - 4900 = 490\).
  4. \(r = \dfrac{-310}{\sqrt{200 \times 490}} = \dfrac{-310}{\sqrt{98000}} = \dfrac{-310}{313.05}\).

Answer\(r \approx -0.9903\): as price rises, demand falls almost linearly

Example 3: Change of origin and scale

Medium

Find \(r\) for \(x\): 10, 12, 14, 16, 18, 20 and \(y\): 14, 15, 19, 18, 22, 26.

  1. Take \(u = \dfrac{x - 14}{2}\): \(-2, -1, 0, 1, 2, 3\). Take \(v = y - 18\): \(-4, -3, 1, 0, 4, 8\).
  2. \(\sum u = 3\), \(\sum v = 6\), \(\sum u^2 = 19\), \(\sum v^2 = 106\), \(\sum uv = 8 + 3 + 0 + 0 + 8 + 24 = 43\).
  3. Numerator: \(6(43) - 3(6) = 240\). Denominator: \(\sqrt{6(19) - 9}\,\sqrt{6(106) - 36} = \sqrt{105}\,\sqrt{600}\).
  4. \(r_{uv} = \dfrac{240}{\sqrt{63000}} = \dfrac{240}{251.00}\), and \(r_{xy} = r_{uv}\) because \(h = 2\) and \(k = 1\) are both positive.

Answer\(r \approx 0.9562\)

Example 4: From covariance and variances

Easy

Given \(\operatorname{Cov}(x, y) = 18\), \(\operatorname{Var}(x) = 25\) and \(\operatorname{Var}(y) = 36\), find \(r\).

  1. \(\sigma_x = 5\) and \(\sigma_y = 6\).
  2. \(r = \dfrac{18}{5 \times 6} = \dfrac{18}{30}\).

Answer\(r = 0.6\)

Example 5: Correcting a wrongly copied pair

Exam level

For 20 pairs, someone found \(\sum x = 102\), \(\sum y = 82\), \(\sum x^2 = 608\), \(\sum y^2 = 444\), \(\sum xy = 476\). Later it was found that the pair \((8, 12)\) had been copied in place of the correct pair \((6, 10)\). Find the correct \(r\).

  1. Remove the wrong pair and add the right one. \(\sum x = 102 - 8 + 6 = 100\), \(\sum y = 82 - 12 + 10 = 80\).
  2. \(\sum x^2 = 608 - 64 + 36 = 580\), \(\sum y^2 = 444 - 144 + 100 = 400\), \(\sum xy = 476 - 96 + 60 = 440\).
  3. Numerator: \(20(440) - 100(80) = 800\).
  4. \(20(580) - 100^2 = 1600\) and \(20(400) - 80^2 = 1600\), so the denominator is \(\sqrt{1600 \times 1600} = 1600\).

AnswerCorrect \(r = \dfrac{800}{1600} = 0.5\) (the wrong figures would have given about 0.594)

Example 6: Two judges, no ties

Easy

Two judges rank 8 contestants. Judge A: 1, 2, 3, 4, 5, 6, 7, 8. Judge B: 2, 1, 4, 3, 6, 8, 5, 7. Find the rank correlation.

  1. \(d = A - B\): \(-1, 1, -1, 1, -1, -2, 2, 1\). (Check: \(\sum d = 0\).)
  2. \(\sum d^2 = 1 + 1 + 1 + 1 + 1 + 4 + 4 + 1 = 14\).
  3. \(\rho = 1 - \dfrac{6 \times 14}{8(64 - 1)} = 1 - \dfrac{84}{504}\).

Answer\(\rho \approx 0.8333\): the judges largely agree

Example 7: Ranks from marks

Medium

Marks of 6 students. Maths: 78, 65, 90, 55, 70, 84. Physics: 72, 60, 85, 62, 75, 80. Find Spearman's \(\rho\).

  1. Rank maths (highest = 1): 3, 5, 1, 6, 4, 2. Rank physics: 4, 6, 1, 5, 3, 2.
  2. \(d\): \(-1, -1, 0, 1, 1, 0\), so \(\sum d^2 = 4\).
  3. \(\rho = 1 - \dfrac{6 \times 4}{6(36 - 1)} = 1 - \dfrac{24}{210}\).

Answer\(\rho \approx 0.8857\)

Example 8: Tied ranks

Exam level

Find the rank correlation for \(x\): 50, 62, 45, 62, 70, 38, 55, 62 and \(y\): 40, 52, 40, 60, 65, 35, 48, 45.

  1. Rank \(x\) (highest = 1): 70 is 1st. The three 62s share places 2, 3, 4, so each gets 3. Then 55 is 5th, 50 is 6th, 45 is 7th, 38 is 8th. Ranks: 6, 3, 7, 3, 1, 8, 5, 3.
  2. Rank \(y\): 65 is 1, 60 is 2, 52 is 3, 48 is 4, 45 is 5, the two 40s share places 6 and 7 so each gets 6.5, and 35 is 8. Ranks: 6.5, 3, 6.5, 2, 1, 8, 4, 5.
  3. \(d\): \(-0.5, 0, 0.5, 1, 0, 0, 1, -2\), so \(\sum d^2 = 0.25 + 0.25 + 1 + 1 + 4 = 6.5\).
  4. Tie correction: a group of 3 gives \(\dfrac{3(9 - 1)}{12} = 2\), a group of 2 gives \(\dfrac{2(4 - 1)}{12} = 0.5\). Total 2.5.
  5. \(\rho = 1 - \dfrac{6(6.5 + 2.5)}{8(64 - 1)} = 1 - \dfrac{54}{504}\).

Answer\(\rho \approx 0.8929\)

Vipul Sir's tip

Before you divide, look at the numerator. If it is negative, \(r\) must come out negative; if your final \(r\) is bigger than 1, a sum is wrong. I make students write \(\sum d = 0\) as a check line under every rank table. It catches a wrong rank in five seconds.

05

Common mistakes

1. Giving tied values the same whole-number rank

Three values tied for 2nd place do not all get rank 2. They occupy places 2, 3 and 4, so each gets \(\dfrac{2 + 3 + 4}{3} = 3\), and the next value is 5th.

2. Ranking the two variables in opposite directions

If maths marks are ranked highest = 1 but physics marks lowest = 1, a perfect agreement shows up as \(\rho = -1\). Rank both the same way.

3. Reading r = 0 as "no relationship"

\(r = 0\) only says there is no linear relationship. The points could lie exactly on a parabola. Look at the scatter diagram.

06

Practice questions

Try each one on paper before you open the answer.

Q1Find \(r\) for \(x\): 1, 2, 3, 4 and \(y\): 2, 3, 5, 6.

\(\bar x = 2.5\), \(\bar y = 4\). \(\sum XY = 7\), \(\sum X^2 = 5\), \(\sum Y^2 = 10\).

\(r = \dfrac{7}{\sqrt{50}} \approx 0.9899\).

Q2Given \(n = 10\), \(\sum x = 60\), \(\sum y = 40\), \(\sum x^2 = 400\), \(\sum y^2 = 200\), \(\sum xy = 260\), find \(r\).

Numerator \(= 2600 - 2400 = 200\). Both brackets are \(4000 - 3600 = 400\) and \(2000 - 1600 = 400\).

\(r = \dfrac{200}{400} = 0.5\).

Q3\(r_{xy} = 0.8\). Find the correlation between \(u = \dfrac{x - 5}{2}\) and \(v = \dfrac{y - 10}{-3}\).

The scale factors 2 and \(-3\) have opposite signs, so the size stays and the sign flips: \(r_{uv} = -0.8\).

Q4Ranks by two judges for 5 items: A: 1, 2, 3, 4, 5 and B: 2, 1, 4, 3, 5. Find \(\rho\).

\(\sum d^2 = 1 + 1 + 1 + 1 + 0 = 4\). \(\rho = 1 - \dfrac{24}{5 \times 24} = 0.8\).

Q5Find Spearman's \(\rho\) for \(x\): 10, 20, 20, 30, 40 and \(y\): 5, 15, 10, 25, 20.

Ranks of \(x\) (highest = 1): 5, 3.5, 3.5, 2, 1. Ranks of \(y\): 5, 3, 4, 1, 2.

\(\sum d^2 = 0 + 0.25 + 0.25 + 1 + 1 = 2.5\). One pair of ties adds \(\dfrac{2 \times 3}{12} = 0.5\).

\(\rho = 1 - \dfrac{6 \times 3}{5 \times 24} = 1 - 0.15 = 0.85\).

Q6The rank correlation for 10 items is 0.8. Find \(\sum d^2\).

\(0.8 = 1 - \dfrac{6\sum d^2}{10 \times 99}\), so \(\dfrac{6\sum d^2}{990} = 0.2\) and \(\sum d^2 = 33\).

Stuck on a question?

Bring it to a free demo class and work through it with Vipul Sir. Book on WhatsApp.

07

Frequently asked questions

What does the correlation coefficient tell you?

The direction and strength of the straight-line relationship between two variables. Values near \(+1\) or \(-1\) mean the points lie close to a line; values near 0 mean they don't.

Can r be greater than 1?

No. \(-1 \le r \le 1\) always. If you get a value outside this range, one of your sums is wrong.

What is the difference between Pearson's and Spearman's correlation?

Pearson's \(r\) uses the actual values and measures linear association. Spearman's \(\rho\) uses only the ranks, so it suits ranked data and is less affected by one extreme value.

Does correlation mean one thing causes the other?

No. Ice-cream sales and drowning cases both rise in summer, so they are correlated, but neither causes the other. Correlation is a measure of association only.

Related lessons

← All 10 Probability & Statistics topics
Vipul Sir
Written by Vipul Sir

Vipul Sir has taught mathematics for over 15 years to HSC, CBSE, ICSE, IGCSE/IB, Diploma, Engineering and BSc students at VVS Classes in Goregaon and Vile Parle, Mumbai. He teaches every class himself, concepts first and exam technique second.

Probability and Statistics

Get Probability & Statistics right, with Vipul Sir beside you.

Concept-first classes in small batches in Goregaon and Vile Parle, or online. Your first class is free.

WhatsApp↗