🏠 Home
Correlation & Regression
Unit IV · Lecture 30

BDS113 — Introduction to Statistics

Spearman's Rank Correlation Coefficient

Rank Data · Formula · Tied Ranks · Worked Examples · Comparison with Pearson's r


Unit IV · Lecture 30 of 40 · B.Sc. Data Science, 1st Year, Semester II

Correlation & Regression
Unit IV · Lecture 30

🤔 Why Spearman's Rank Correlation?


📖 Limitations of Pearson's r

Pearson's r requires quantitative data and measures only linear relationships. But what if:
  • The data is ordinal (rankings, ratings, preferences)?
  • The relationship is monotonic but not linear?
  • The data contains outliers that distort Pearson's r?

Spearman's rank correlation (ρ, rho) addresses all three issues.


💡 Analogy: The Beauty Contest

Two judges rank 5 contestants. Judge A ranks them 1, 2, 3, 4, 5. Judge B ranks them 2, 1, 3, 5, 4. Do the judges agree? We can't use Pearson's r on rankings (they're ordinal, not interval). Instead, we compare the ranks directly using Spearman's ρ. The judges mostly agree — their rank correlation is high.


📖 Charles Spearman (1863–1945)

Charles Edward Spearman was a British psychologist who pioneered the use of factor analysis and rank-based statistics. He developed the rank correlation coefficient in 1904. Interestingly, Spearman's ρ is mathematically equivalent to Pearson's r computed on the ranks rather than the original data values.

Correlation & Regression
Unit IV · Lecture 30

📊 Spearman's Rank Correlation Formula


📖 Formula (No Tied Ranks)

ρ = 1 − [6Σdᵢ²] / [n(n² − 1)]

Where:
  • dᵢ = difference between the ranks of the i-th pair: dᵢ = R(xᵢ) − R(yᵢ)
  • n = number of paired observations
  • Σdᵢ² = sum of squared rank differences

Range: −1 ≤ ρ ≤ +1
  • ρ = +1: Perfect agreement in ranks
  • ρ = −1: Perfect disagreement (one ranking is the reverse of the other)
  • ρ = 0: No monotonic relationship between ranks


💡 Shortcut: This formula is a shortcut that works when there are no tied ranks. It is derived from applying Pearson's formula to ranks and simplifying. If there are ties, use the general Pearson formula on ranks (shown later).
Correlation & Regression
Unit IV · Lecture 30

🪜 Step-by-Step: Computing Spearman's ρ


1Rank the x-values from smallest (rank 1) to largest (rank n). Assign R(xᵢ).
2Rank the y-values similarly. Assign R(yᵢ).
3Compute dᵢ = R(xᵢ) − R(yᵢ) for each pair.
4Compute dᵢ² and Σdᵢ².
5Apply the formula: ρ = 1 − 6Σdᵢ² / [n(n²−1)]
6Interpret: Sign (direction), magnitude (strength), context.
Correlation & Regression
Unit IV · Lecture 30

✏️ Example 1: Student Rankings


📝 Problem

Two judges rank 6 students. Find Spearman's rank correlation.

StudentABCDEF
Judge 1132564
Judge 2213456

StudentR₁ (Judge 1)R₂ (Judge 2)d = R₁−R₂d²
A12−11
B31+24
C23−11
D54+11
E65+11
F46−24
Σd² =12

📖 Solution

n = 6, Σd² = 12

ρ = 1 − 6(12) / [6(36−1)]
  = 1 − 72 / [6 × 35]
  = 1 − 72/210
  = 1 − 0.3429
  = 0.6571


Result

ρ = 0.657

Moderate to strong positive agreement between the two judges' rankings. They generally agree on who is better, but differ on some specific placements.

Correlation & Regression
Unit IV · Lecture 30

✏️ Example 2: Tied Ranks


📖 What Are Tied Ranks?

When two or more observations have the same value, they receive the average of the ranks they would have occupied. For example, if the 3rd and 4th values are tied, both get rank (3+4)/2 = 3.5.


📝 Problem

Find Spearman's ρ for the following data (note the tie in y):

x1020304050
y1525253545

xyR(x)R(y)dd²
10151100
202522.5−0.50.25
302532.5+0.50.25
40354400
50455500
Σd² =0.50

📖 Solution

Method 1 (Shortcut — approximate with ties):
ρ = 1 − 6(0.50) / [5(25−1)] = 1 − 3/120 = 1 − 0.025 = 0.975

Method 2 (Exact — Pearson's formula on ranks):
When ties exist, use the general formula:
ρ = [ΣR(x)R(y) − n·R̄(x)·R̄(y)] / √{[ΣR(x)² − n·R̄(x)²] · [ΣR(y)² − n·R̄(y)²]}

R̄(x) = (1+2+3+4+5)/5 = 3, R̄(y) = (1+2.5+2.5+4+5)/5 = 3
ΣR(x)R(y) = 1(1)+2(2.5)+3(2.5)+4(4)+5(5) = 1+5+7.5+16+25 = 54.5
ΣR(x)² = 1+4+9+16+25 = 55, ΣR(y)² = 1+6.25+6.25+16+25 = 54.5

ρ = [54.5 − 5(3)(3)] / √{[55−45][54.5−45]} = 9.5 / √{10 × 9.5} = 9.5/√95 = 9.5/9.747 = 0.9747


💡 Tied Ranks: With ties, the shortcut formula slightly overestimates |ρ|. For exact results, always use Pearson's formula on ranks. In exams, if the question says "no ties," use the shortcut. If ties exist, mention both methods.
Correlation & Regression
Unit IV · Lecture 30

🎬 Interactive: Spearman's ρ Calculator






Correlation & Regression
Unit IV · Lecture 30

⚖️ Pearson's r vs Spearman's ρ


FeaturePearson's rSpearman's ρ
Data typeQuantitative (interval/ratio)Ordinal, ranked, or quantitative
MeasuresLinear relationshipMonotonic relationship
Based onActual valuesRanks of values
Outlier sensitivityHighly sensitiveRobust (outliers get extreme ranks but less weight)
Range−1 to +1−1 to +1
r = +1 or ρ = +1 meansPerfect linear fitPerfect rank agreement
Non-linear relationshipsMay give r ≈ 0Detects monotonic non-linear patterns
When to useContinuous data, linear relationship, no outliersOrdinal data, outliers present, monotonic relationship

💬 Key Rule: If the relationship is linear, Pearson's r and Spearman's ρ will give similar values. If the relationship is monotonic but non-linear (e.g., exponential), ρ will be higher than r. If the data has outliers, ρ is more reliable.
Correlation & Regression
Unit IV · Lecture 30

🔑 Summary: Spearman's Rank Correlation


Correlation & Regression
Unit IV · Lecture 30

🧠 Quick Quiz — Lecture 30


Q1: Spearman's ρ measures:

A) Linear relationships only
B) Monotonic relationships
C) Only positive relationships
D) Causal relationships

Q2: If two students are tied for ranks 3 and 4, they both receive rank:

A) 3
B) 3.5
C) 4
D) 7

Q3: If Σd² = 0 in Spearman's formula, then ρ equals:

A) 0
B) +1
C) −1
D) Cannot be determined

Q4: Spearman's ρ is more robust than Pearson's r when the data has:

A) Ties
B) Outliers
C) A perfect linear relationship
D) Negative correlation

Q5: Spearman's ρ is mathematically equivalent to Pearson's r computed on:

A) The original data
B) The ranks of the data
C) The logarithms of the data
D) The squared values
Correlation & Regression
Unit IV · Lecture 30

📝 Homework & Next Lecture


📝 Practice Tasks

1. Find Spearman's ρ for: x = 85, 72, 90, 65, 78 and y = 80, 68, 88, 70, 75.

2. Two professors rank 7 students. Their rankings are:
   Prof A: 1, 2, 3, 4, 5, 6, 7
   Prof B: 2, 1, 4, 3, 6, 5, 7
Find ρ. Do the professors agree?

3. Compute both Pearson's r and Spearman's ρ for: x = 1, 2, 3, 4, 5 and y = 1, 4, 9, 16, 25. Compare the results. Why do they differ?

4. Explain why Spearman's ρ is preferred over Pearson's r when data contains outliers.

5. BONUS: Show that if all ranks are in perfect agreement (R(xᵢ) = R(yᵢ) for all i), then Σd² = 0 and ρ = 1.


Upcoming

Lecture 31: Simple Linear Regression — regression lines, least squares, and the relationship between correlation and regression.