Spearman's Rank Correlation Coefficient

Spearman's rank correlation coefficient rsr_s measures the strength and direction of the monotonic association between two variables by applying the correlation idea to the ranks of the observations. This lesson covers the rank-difference formula, computation with and without tied ranks, and recovering di2\sum d_i^2 from a given rsr_s.

Step 1 of 119%

Tutorial

Ranks and the Spearman Formula

When the relationship between two variables is monotonic but not necessarily linear, Pearson's rr can understate the association. The Spearman rank correlation coefficient rsr_s fixes this by measuring correlation between the ranks of the observations rather than the raw values.

To compute rsr_s when no two xx-values are tied and no two yy-values are tied:

  1. Rank the xx-values from smallest (rank 11) to largest (rank nn). Do the same independently for the yy-values.
  2. For each pair (xi,yi),(x_i, y_i), compute the rank difference di=R(xi)R(yi).d_i = R(x_i) - R(y_i).
  3. Apply the formula
rs=16i=1ndi2n(n21).r_s = 1 - \dfrac{6\sum\limits_{i=1}^n d_i^2}{n(n^2-1)}.

The value of rsr_s always lies between 1-1 and 1.1. It equals +1+1 exactly when the two rankings are identical (perfect monotonic increase) and 1-1 when one ranking is the exact reverse of the other (perfect monotonic decrease).

Tiny example. With n=3n=3 and the data

x:1,  2,  3ranks 1,2,3,x: 1,\;2,\;3 \quad\longrightarrow\quad \text{ranks } 1,2,3, y:10,  30,  20ranks 1,3,2,y: 10,\;30,\;20 \quad\longrightarrow\quad \text{ranks } 1,3,2,

the rank differences are di=0,1,1,d_i = 0,\,-1,\,1, so di2=0+1+1=2\sum d_i^2 = 0+1+1 = 2 and

rs=1623(321)=11224=0.5.r_s = 1 - \dfrac{6 \cdot 2}{3(3^2-1)} = 1 - \dfrac{12}{24} = 0.5.
navigate · Enter open · Esc close · ⌘K/Ctrl K toggle