Algorithm Search⌘K

Definitionintro

Spearman's rank correlation coefficient

Also called Spearman's rho, Spearman correlation.

The Pearson correlation of the ranks of two variables. It measures monotone association and is the basis of a rank test of independence.

Spearman's rank correlation coefficient rSr_S of paired data (x1,y1),…,(xn,yn)(x_1, y_1), \ldots, (x_n, y_n) is the ordinary (Pearson) correlation coefficient of the ranks of the xx values and the ranks of the yy values. It is +1+1 when yy is a strictly increasing function of xx, −1-1 when it is a strictly decreasing one, and near 0 when the order of the yy values has nothing to do with the order of the xx values. Because only ranks enter, it does not change under increasing transformations of either variable, and a single extreme value moves it by a bounded amount. Under independence of XX and YY, the ranks of the yy values are a uniform random permutation relative to those of the xx values, so rSr_S has an exact null law that depends only on nn, and it gives a permutation test of independence.

Definition

Let RiR_i be the rank of xix_i among x1,…,xnx_1, \ldots, x_n and SiS_i the rank of yiy_i among y1,…,yny_1, \ldots, y_n. Tied values get the average of the ranks they cover, the midrank. Both rank vectors have mean rˉ=(n+1)/2\bar r = (n+1)/2. Spearman's rank correlation coefficient is

rS=∑i(Ri−rˉ)(Si−rˉ)∑i(Ri−rˉ)2∑i(Si−rˉ)2,r_S = \frac{\sum_i (R_i - \bar r)(S_i - \bar r)}{\sqrt{\sum_i (R_i - \bar r)^2 \sum_i (S_i - \bar r)^2}},

defined when neither variable is constant. Without ties, both sums of squares equal n(n2−1)/12n(n^2 - 1)/12, and with di=Ri−Sid_i = R_i - S_i,

rS=1−6∑idi2n(n2−1).r_S = 1 - \frac{6 \sum_i d_i^2}{n(n^2 - 1)}.

With ties this short formula is not the correlation of the midranks.

Null law. If the pairs are independent and XX is independent of YY, with continuous distributions, then given the ranks RR, the vector SS is a uniform random permutation of 1,…,n1, \ldots, n. So the law of rSr_S is that of 1−6∑i(i−π(i))2/(n(n2−1))1 - 6\sum_i (i - \pi(i))^2 / (n(n^2 - 1)) for a uniform random permutation π\pi, the same for every pair of continuous distributions. Its mean is 0 and its variance is 1/(n−1)1/(n-1). With ties, the same holds conditionally on the midranks, with the midranks of yy permuted. The test of independence rejects for large ∣rS∣\lvert r_S \rvert, or for large or small rSr_S in one direction, with p-values from this law, computed by counting permutations for small nn, by sampling permutations, or from the approximation rSn−1≈N(0,1)r_S \sqrt{n - 1} \approx N(0, 1).

Population version. For a pair (X,Y)(X, Y) with continuous marginal distribution functions FF and GG, ρS=corr(F(X),G(Y))=12 E[F(X)G(Y)]−3\rho_S = \mathrm{corr}(F(X), G(Y)) = 12\, E[F(X) G(Y)] - 3, and rS→ρSr_S \to \rho_S as n→∞n \to \infty.

Examples and non-examples

A small sample. Hours of study x=2,5,1,8,4,6x = 2, 5, 1, 8, 4, 6 and scores y=55,70,52,80,75,68y = 55, 70, 52, 80, 75, 68. The ranks are R=2,4,1,6,3,5R = 2, 4, 1, 6, 3, 5 and S=2,4,1,6,5,3S = 2, 4, 1, 6, 5, 3, so d=0,0,0,0,−2,2d = 0, 0, 0, 0, -2, 2, ∑di2=8\sum d_i^2 = 8 and rS=1−48/210=27/35=0.7714r_S = 1 - 48/210 = 27/35 = 0.7714. The Pearson correlation of the raw values is 0.88730.8873, and Kendall's tau is 0.60.6.

Monotone but not linear. For x=1,…,10x = 1, \ldots, 10 and y=exy = e^x, rS=1r_S = 1, since the order is the same. The Pearson correlation is 0.71690.7169, because the relation is far from a line.

One extreme value. For x=1,…,10x = 1, \ldots, 10 and y=5,3,6,2,7,4,1,8,3.5,60y = 5, 3, 6, 2, 7, 4, 1, 8, 3.5, 60, rS=0.2848r_S = 0.2848 and the Pearson correlation is 0.52030.5203. Replace 6060 by 99: rSr_S stays 0.28480.2848, since 99 is still the largest value, while the Pearson correlation drops to 0.30410.3041.

Ties. For x=1,2,2,3,4,4,5x = 1, 2, 2, 3, 4, 4, 5 and y=2,1,3,3,5,4,4y = 2, 1, 3, 3, 5, 4, 4, the midranks are 1,2.5,2.5,4,5.5,5.5,71, 2.5, 2.5, 4, 5.5, 5.5, 7 and 2,1,3.5,3.5,7,5.5,5.52, 1, 3.5, 3.5, 7, 5.5, 5.5. The correlation of the midranks is rS=5/6=0.8333r_S = 5/6 = 0.8333. The short formula gives 1−6⋅9/336=47/56=0.83931 - 6 \cdot 9/336 = 47/56 = 0.8393, a different number.

The exact null law for n=4n = 4. The 24 permutations give ∑di2=0,2,4,…,20\sum d_i^2 = 0, 2, 4, \ldots, 20 with counts 1,3,1,4,2,2,2,4,1,3,11, 3, 1, 4, 2, 2, 2, 4, 1, 3, 1, so rSr_S takes the values 1,0.8,0.6,…,−11, 0.8, 0.6, \ldots, -1, and the law is symmetric about 0. P(rS=1)=1/24=0.0417P(r_S = 1) = 1/24 = 0.0417, so with four pairs no one-sided test at level 0.010.01 can reject. Counting all permutations gives the upper 5% points below; each is the smallest value cc with P(rS≥c)≤0.05P(r_S \ge c) \le 0.05:

nn cc P(rS≥c)P(r_S \ge c)
5 0.9 0.0417
6 0.8286 0.0292
7 0.7143 0.0440
8 0.6429 0.0481
9 0.6 0.0484

The same counts confirm the mean 0 and the variance 1/(n−1)1/(n-1) for n=4,…,9n = 4, \ldots, 9. For n=9n = 9, P(rS≥2/3)=0.02944P(r_S \ge 2/3) = 0.02944, and the normal approximation with standard deviation 1/81/\sqrt{8} gives 0.029670.02967.

A population value. For a bivariate normal pair with correlation rr, ρS=(6/π)arcsin⁡(r/2)\rho_S = (6/\pi) \arcsin(r/2), which is 0.48260.4826 for r=0.5r = 0.5. In a Monte Carlo run with n=2000n = 2000 pairs, 200200 samples and seed 81, the mean of rSr_S was 0.48150.4815.

Non-example: a relation that is not monotone. For x=−3,…,3x = -3, \ldots, 3 and y=x2y = x^2, rS=0r_S = 0, although yy is a function of xx. rSr_S measures monotone association only; rS=0r_S = 0 does not mean independence.

Non-example: Pearson's coefficient. The Pearson correlation of the raw values measures linear association and can change under increasing transformations, as the examples above show. Spearman's coefficient is Pearson's coefficient applied to the ranks, not to the values.

  • Kendall's tau. The share of concordant minus the share of discordant pairs, a linear function of the Kendall tau distance between the two rankings. Enumeration of all permutations for n=5,…,8n = 5, \ldots, 8 found −1≤3τ−2rS≤1-1 \le 3\tau - 2r_S \le 1, with both ends reached. See also comparing rankings with Kendall's tau.
  • Spearman's footrule. ∑i∣Ri−Si∣\sum_i \lvert R_i - S_i \rvert, the footrule distance, with absolute differences in place of squares.
  • Kendall's coefficient of concordance. For bb rankings of the same kk items, WW measures agreement, and the mean of the (b2)\binom{b}{2} pairwise Spearman coefficients is (bW−1)/(b−1)(bW - 1)/(b - 1). Its test is the Friedman test.
  • Rank tests of association. For categorical data the chi-squared test of independence plays the role that the Spearman test plays for ordered data.

References

  1. C. Spearman, The proof and measurement of association between two things, American Journal of Psychology 15(1), 1904, pp. 72 to 101 (the measurement of correlation from the ranks of the two variables)
  2. Myles Hollander, Douglas A. Wolfe and Eric Chicken, Nonparametric Statistical Methods, third edition, Wiley, 2014, The chapter on the independence problem (the Spearman rank correlation test, its exact null law and its large-sample approximation)
  3. E. L. Lehmann, Nonparametrics, Statistical Methods Based on Ranks, revised edition, Springer, 2006, The chapter on tests of randomness and independence (the rank correlation statistics and their null laws)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/5M1BYQ/text.yaml