impera Open Impera

IB Diploma Mathematics AI · Statistics and probability

Spearman's rank correlation

1Why rank correlation?

Pearson's $r$ measures how well data fit a straight line. Sometimes the relationship is clearly increasing or decreasing but curved, or the data are ranks (like positions in a competition), or there are outliers.

Spearman's rank correlation coefficient $r_s$ measures how well the data fit a monotonic relationship: one that always increases, or always decreases, but not necessarily in a straight line.

  • $r_s = 1$: as one variable increases, the other always increases.
  • $r_s = -1$: as one increases, the other always decreases.
  • $r_s$ near 0: no consistent increasing or decreasing pattern.

A monotonic relationship: the ranks agree perfectly even though the points curve

Check yourself

Data follow a curve that always rises. Which coefficient would be exactly 1?

  • Spearman's r_s

  • Both of them

  • Neither of them

  • Pearson's r

Show the answer

Spearman's r_s

The ranks match perfectly even though the shape is curved.

2Ranking the data

  1. Rank each variable separately: 1 for the largest (or smallest, as long as you are consistent for both variables).
  2. If values are tied, give each the average of the ranks they would have taken. Two values tied for 3rd and 4th each get rank 3.5.
  3. Then find Pearson's $r$ for the ranks on your calculator. That value is $r_s$.
Worked example

Ranking with a tie

  1. Scores: 72, 85, 85, 60, 91.
  2. In order from highest: 91 is rank 1; the two 85s share ranks 2 and 3, so each gets 2.5; 72 is rank 4; 60 is rank 5.
  3. Ranks for the original list: 4, 2.5, 2.5, 5, 1.
Check yourself

Three values tie for ranks 4, 5 and 6. What rank does each get?

  • 4

  • 6

  • 5

  • 4.5

Show the answer

5

The average of 4, 5 and 6 is 5.

3Calculating and interpreting r_s

Worked example

Two judges

  1. Two judges rank six dancers. Judge 1: 1, 2, 3, 4, 5, 6. Judge 2: 2, 1, 4, 3, 6, 5.
  2. Pearson's $r$ on these ranks gives $r_s = 0.829$.
  3. Interpretation: a strong positive agreement between the judges.

When there are no ties, the same value comes from the formula $r_s = 1 - \frac{6\sum d^2}{n(n^2 - 1)}$, where $d$ is the difference in ranks: here $\sum d^2 = 6$ and $r_s = 1 - \frac{36}{210} = 0.829$.

Choosing between Pearson and Spearman:

  • Use Pearson when the relationship looks linear.
  • Use Spearman when it is monotonic but not linear, when the data are ranks, or when an outlier would distort Pearson's $r$.
Check yourself

Two judges give exactly opposite rankings. What is r_s?

  • 0.5

  • 1

  • −1

  • 0

Show the answer

−1

Perfect disagreement is a perfect negative relationship.

4Handling tied ranks

When values are tied, give each the average of the ranks they would occupy.

Worked example

  1. Scores: 85, 72, 72, 60.
  2. Ranks without ties would be 1, 2, 3, 4.
  3. The two 72s share ranks 2 and 3, so each gets 2.5.
  4. Final ranks: 1, 2.5, 2.5, 4.
Check yourself

Two values tie for ranks 4 and 5. What rank does each get?

  • 9.0

  • 5.0

  • 4.0

  • 4.5

Show the answer

4.5

Average of 4 and 5.

5Spearman versus Pearson

  • Pearson's $r$ measures linear correlation.
  • Spearman's $r_s$ measures monotonic correlation: whether one variable consistently increases (or decreases) as the other increases, even if not in a straight line.

Worked example

  1. Data follow $y = x^3$ for $x = 1$ to 5.
  2. Pearson's $r \approx 0.94$: strong but not perfect, because the relationship is curved.
  3. Spearman's $r_s = 1$: the ranks agree perfectly, because $y$ always increases with $x$.

Spearman is also useful when data are already ranks, such as judges' rankings, or when there are outliers.

Check yourself

Data follow a curved but always increasing pattern. What is Spearman's $r_s$?

  • 0.5

  • 0

  • $-1$

  • 1

Show the answer

1

Perfect monotonic.

6Going deeper: a full calculation, ties, and choosing between Spearman and Pearson

Spearman's coefficient $r_s$ is Pearson's coefficient calculated on the ranks of the data. It measures how far the relationship is monotonic: whether one variable consistently rises (or falls) as the other rises, in a straight line or a curve.

Worked example

two judges rank six contestants.

  • Judge A's ranks: 1, 2, 3, 4, 5, 6.
  • Judge B's ranks: 2, 1, 4, 3, 6, 5.
  1. Differences $d$: $-1, 1, -1, 1, -1, 1$.
  2. $\sum d^2 = 6$.
  3. With no ties, $r_s = 1 - \frac{6\sum d^2}{n(n^2 - 1)} = 1 - \frac{36}{6 \times 35} \approx 0.829$.
  4. Interpretation: strong positive agreement between the judges.
  5. GDC method: enter the two lists of ranks and run the ordinary linear regression; the $r$ it reports is $r_s$. This is the method expected in the exam, and it also handles ties correctly.

Ranking raw data, with ties

  1. Rank from largest to smallest (or smallest to largest), using the same direction for both variables.
  2. Tied values share the mean of the ranks they would occupy. For the values 20, 15, 15, 12 ranked from largest: 1, 2.5, 2.5, 4.
  3. Three values tied for ranks 4, 5 and 6 each get rank 5.
  4. Check: the ranks of $n$ values always add to $\frac{n(n + 1)}{2}$.

Spearman or Pearson?

  • Pearson's $r$ measures the strength of a linear relationship. It uses the actual values and is sensitive to outliers.
  • Spearman's $r_s$ measures a monotonic relationship. It uses only the order, so it is less affected by outliers and works for curved but steadily increasing data.
  • Example: for $y = x^3$ with $x = 1, 2, 3, 4, 5$, the points are not on a line, so Pearson's $r$ is less than 1 (about 0.94). The ranks agree perfectly, so $r_s = 1$.
  • Use Spearman when the data are already ranks (judges' positions, preferences), when there is a clear outlier, or when the scatter is curved but monotonic.

Interpreting values

  • $r_s = 1$: the rankings agree completely.
  • $r_s = -1$: the rankings are exactly reversed.
  • $r_s$ near 0: no monotonic relationship.

Limitations

  • Ranking throws away information about how far apart values are.
  • A relationship that rises and then falls gives $r_s$ near 0 even though the variables are related.
  • Like all correlation, it does not show cause.

Common mistakes

  • Ranking one variable from the top and the other from the bottom, which reverses the sign.
  • Giving tied values the same whole-number rank.
  • Calculating Pearson on the raw data when the question asks for Spearman.
Check yourself

For 5 pairs of ranks with no ties, the sum of d² is 4. What is Spearman's coefficient?

  • 0.2

  • 0.8

  • 0.96

  • −0.8

Show the answer

0.8

1 − (6 × 4) ÷ (5 × 24) = 1 − 0.2.

Now test yourself

This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.

Practise in Impera