---
tag: M092V97ZET
kind: definition
name: Spearman's rank correlation coefficient
msc: [62H20, 62G10]
defines: DJFYTQJ3SH
uses: [04CTY6XYWN, 0MXMS3AE13]
sources:
  - url: https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient
---

## Definition

Let $(x_1, y_1), \dots, (x_n, y_n)$ be $n \ge 2$ pairs of real numbers, with $x_1, \dots, x_n$ distinct and $y_1, \dots, y_n$ distinct.
Let $r_i$ be the rank of $x_i$ among $x_1, \dots, x_n$ and $s_i$ the rank of $y_i$ among $y_1, \dots, y_n$, with rank $1$ for the smallest.
*Spearman's rank correlation coefficient* is the sample [[correlation coefficient|04CTY6XYWN]] of the pairs $(r_i, s_i)$.
With $d_i = r_i - s_i$ it equals
$$\rho_s = 1 - \frac{6 \sum_{i=1}^{n} d_i^2}{n(n^2 - 1)}.$$

## Remarks

The closed formula holds because the ranks of each variable are the numbers $1, \dots, n$, whose mean and variance are known.
For random variables $X$ and $Y$ with continuous [[distribution functions|0MXMS3AE13]] $F$ and $G$, the population version is the correlation of $F(X)$ and $G(Y)$, which equals $12 \, E[F(X) G(Y)] - 3$.

Example: $x = (1, 2, 3)$ and $y = (1, 3, 2)$.
The ranks are $r = (1, 2, 3)$ and $s = (1, 3, 2)$, so $d = (0, -1, 1)$ and $\rho_s = 1 - 6 \cdot 2 / (3 \cdot 8) = 1/2$.
For $y = (1, 4, 9)$ instead, $d = 0$ and $\rho_s = 1$.

Non-example: for data with ties, such as $y = (1, 1, 2)$, the ranks are not defined by the clause above.
The usual fix gives tied values the average of their ranks and takes the Pearson correlation; the formula with $\sum d_i^2$ is then no longer exact.

The [[Kendall rank correlation coefficient|DYFY16SFHZ]] is another rank correlation, based on pairs of observations.
