MathsStatistics & Probability

Spearman Rank Correlation
calculator.

Measure how closely two lists agree in order, even when the trend is not a line.

How it's worked out

Spearman's rho, written ρ\rho, replaces each value with its rank in its own list, smallest first. It is then Pearson's correlation worked out on those ranks. The original sizes no longer matter, only the order. So +1 means the two orders match exactly, −1 means one is the reverse of the other, and 0 means no consistent order at all.

When no value repeats, a short formula gives the same answer. Here dd is the difference between the two ranks of one pair, and nn is the number of pairs.

ρ\displaystyle \rho=1−6∑d2n(n2−1)\displaystyle {}= 1 - \frac{6 \sum d^2}{n(n^2 - 1)}

Tied values each take the average of the ranks they cover, so two values tied for second and third both get 2.5. The short formula is then no longer exact, so this tool works out the correlation of the ranks directly.

ρ\displaystyle \rho=SxySxxSyy\displaystyle {}= \frac{S_{xy}}{\sqrt{S_{xx} S_{yy}}}

The sums are taken over the ranks, around the mean rank of n+12\frac{n + 1}{2}. For the p-value, up to 9 pairs with no ties get an exact test: the tool checks every possible ordering of the ranks and counts how many are as extreme as yours, which is 362,880 orderings at 9 pairs. R also treats its figures as exact only below 10 pairs. Everything else uses this t approximation, with n−2n - 2 degrees of freedom.

t\displaystyle t=ρn−21−ρ2\displaystyle {}= \rho \sqrt{\frac{n - 2}{1 - \rho^2}}

The interval uses Fisher's z, with the Fieller, Hartley and Pearson variance of 1.06 over n−3n - 3, the same choice the correlation package makes by default. It needs at least 4 pairs.

z\displaystyle z=atanh⁡(ρ),\displaystyle {}= \operatorname{atanh}(\rho),SE\displaystyle \text{SE}=1.06n−3\displaystyle {}= \sqrt{\frac{1.06}{n - 3}}

Worked examples

Do people with higher IQ scores watch less TV?

Ten people give an IQ score (106, 100, 86, 101, 99, 103, 97, 113, 112, 110) and their weekly hours of TV (7, 27, 2, 50, 28, 29, 20, 12, 6, 17). The squared rank differences add to 194.

ρ\displaystyle \rho=1−6×19410×99\displaystyle {}= 1 - \frac{6 \times 194}{10 \times 99}=−0.176\displaystyle {}= -0.176

With 10 pairs, the tool uses the t approximation, and p = 0.627. The 95% interval runs from −0.735 to 0.526, which holds 0 and also holds fairly strong links in both directions. These ten people cannot settle the question. Leave out the third pair, at (86, 2), and ρ\rho moves to −0.617, so one person is doing a lot of work.

Open this example in the tool

Two judges who only swap neighbors

Two judges rank eight entries. They agree closely, but swap each neighboring pair: 2, 1, 4, 3 and so on. Each dd is 1 in size, so ∑d2\sum d^2 is 8 and ρ\rho is 0.905.

With 8 pairs and no ties, the exact test applies, and p is 0.005. You can enter placings like these as they are. Ranking a list of ranks gives the same ranks, so nothing changes.

Open this example in the tool

A curve that only ever rises

Here y doubles at each step: 1, 2, 4, 8, 16, 32, 64. The order never breaks, so ρ\rho is exactly 1, and the exact p is below 0.001. Pearson's r is only 0.878, because the points do not lie on a straight line. The gap is the useful part: it tells you the trend is steady but curved.

Open this example in the tool

Reading your result

Read the size against a stated scale. Cohen's bands for r call 0.10 small, 0.30 medium and 0.50 large, and people often read them across to rho. A medical rule of thumb from Mukaka is stricter: below 0.30 is negligible and 0.70 is where high begins. The two do not line up, so name the one you use.

A very small sample has a limit. The exact test has only so many orderings to count. With 5 pairs, even perfect agreement can only reach p = 0.017, which is 2 in 120, and with 4 pairs the smallest possible p is 0.083, which can never pass the 5% level.

Compare rho with Pearson's r. If the two are close, a straight line and the order tell a similar story. A large gap points to a curve or an outlier. For x from 1 to 10 and y from 1 to 9 and then 100, ρ\rho is 1 while r is only 0.593. The TV data show a smaller gap, −0.18 against −0.07, and the third pair explains much of it.

A significant rho says the order is consistent. It does not say the trend is straight, or that one thing causes the other.

Common mistakes

  • Reading rho of 0 as no relationship. Rho only sees trends that keep going one way. For x from −3 to 3 and y = x², y depends completely on x, yet ρ\rho is 0.
  • Using the short formula with ties. The rank difference formula assumes no repeats. On tied survey ratings, use the full form, as this tool does. Its answer for the ratings example is 0.777.
  • Sorting one column on its own. Each x must keep its own y. Sort both columns together by one of them, or leave them unsorted, as rho does not need sorted input.
  • Reading the square as a share of the original spread. Rho squared describes how much the ranks vary together. It is not the share of variation in your original numbers that Pearson's r squared reports.

Questions people ask

Start from the question. Pearson asks whether the points follow a straight line, and it suits two measured variables with roughly normal spread. Mukaka (2012) recommends Spearman when a variable is skewed or ordinal, and notes it holds up against extreme values. Reporting both is fine, and a large gap between them is worth explaining.

Sources