Spearman Rank Correlation
calculator.
Measure how closely two lists agree in order, even when the trend is not a line.
| # | X values | Y values |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | ||
| 9 | ||
| 10 |
- p-value, t approximation
- 0.6272
- 95% interval for ρ
- −0.735 to 0.526
- Pairs
- 10
This is a small negative link in the order of the two lists. With 10 pairs, p = 0.6272, so it does not pass the 5% level. Pearson's r is −0.0702, a gap of 0.11, so look for a curve or an outlier.
Rank against rank
Each point is one pair placed by its two ranks. Points on the dotted line got the same rank in both lists, and points far from it are where the two orders disagree. ρ = −0.1758. The table of ranks gives the same data.
Working
- 1Rank each list, smallest firstX ranks: 7, 4, 1, 5, 3, 6, 2, 10, 9, 8Y ranks: 3, 7, 1, 10, 8, 9, 6, 4, 2, 5
- 2Square each rank difference and add themΣd² = 194
- 3Use the rank difference formulaρ = 1 −6 × 19410 × (10² − 1)= −0.1758
- 4Turn ρ into t, with 8 degrees of freedomt =−0.1758 × √8√(1 − −0.1758²)= −0.505, p = 0.6272
- 5Fisher's z, with the Fieller variance, gives the 95% interval−0.735 to 0.526
- 6Check: correlating the ranks directly gives the same ρ−14.5√(82.5 × 82.5)= −0.1758, and Σd = 0
Ranks and differences
| Pair | X | Y | d² | |||
|---|---|---|---|---|---|---|
| 1 | 106 | 7 | 7X 106 | 3Y 7 | 4d² 16 | 16 |
| 2 | 100 | 27 | 4X 100 | 7Y 27 | −3d² 9 | 9 |
| 3 | 86 | 2 | 1X 86 | 1Y 2 | 0d² 0 | 0 |
| 4 | 101 | 50 | 5X 101 | 10Y 50 | −5d² 25 | 25 |
| 5 | 99 | 28 | 3X 99 | 8Y 28 | −5d² 25 | 25 |
| 6 | 103 | 29 | 6X 103 | 9Y 29 | −3d² 9 | 9 |
| 7 | 97 | 20 | 2X 97 | 6Y 20 | −4d² 16 | 16 |
| 8 | 113 | 12 | 10X 113 | 4Y 12 | 6d² 36 | 36 |
| 9 | 112 | 6 | 9X 112 | 2Y 6 | 7d² 49 | 49 |
| 10 | 110 | 17 | 8X 110 | 5Y 17 | 3d² 9 | 9 |
ρ with each pair left out
| Pair left out | ||
|---|---|---|
| 1: (106, 7) | −0.0833 | +0.0924 |
| 2: (100, 27) | −0.1667 | +0.0091 |
| 3: (86, 2) | −0.6167 | −0.4409 |
| 4: (101, 50) | −0.1667 | +0.0091 |
| 5: (99, 28) | −0.1667 | +0.0091 |
| 6: (103, 29) | −0.1667 | +0.0091 |
| 7: (97, 20) | −0.1833 | −0.0076 |
| 8: (113, 12) | −0.0833 | +0.0924 |
Pair 3 moves ρ the most, by 0.4409, to −0.6167.
Spearman against Pearson
They differ by 0.11. A rising curve or an outlier usually explains that.
How big is this ρ?
- Cohen's bands for r, read across to ρ
- 0.10 small, 0.30 medium, 0.50 large
- Medical rule of thumb
- 0.30 low, 0.50 moderate, 0.70 high, 0.90 very high
- This ρ
- 0.1758, small
Bands from Cohen (1992) and Mukaka (2012). Both are rough guides, and they do not agree with each other, so say which you use.
How it's worked out
Spearman's rho, written , 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 is the difference between the two ranks of one pair, and is the number of pairs.
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.
The sums are taken over the ranks, around the mean rank of . 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 degrees of freedom.
The interval uses Fisher's z, with the Fieller, Hartley and Pearson variance of 1.06 over , the same choice the correlation package makes by default. It needs at least 4 pairs.
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.
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 moves to −0.617, so one person is doing a lot of work.
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 is 1 in size, so is 8 and 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.
A curve that only ever rises
Here y doubles at each step: 1, 2, 4, 8, 16, 32, 64. The order never breaks, so 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.
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, 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 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
Sources
- Mukaka, M. M. (2012), A guide to appropriate use of correlation coefficient in medical research, Malawi Medical Journal 24(3), 69-71
- Wikipedia, Spearman's rank correlation coefficient
- Cohen, J. (1992), A power primer, Psychological Bulletin 112(1), 155-159
- R documentation, cor.test
- SciPy documentation, scipy.stats.spearmanr
- correlation package for R, cor_to_ci source