Spearman’s rank correlation measures how well the ranking of one variable matches the ranking of another. The Spearman correlation calculator takes the number of pairs and the sum of squared rank differences, and gives Spearman’s ρ, the t statistic, the p-value, ρ² and a 95 % confidence interval.
How the calculation works
- Rank each variable from smallest to largest, giving tied values the average of their ranks. For every pair, take the difference d between the two ranks.
- Square the differences and add them to get Σd². This is the number you enter, with the number of pairs n.
- ρ = 1 − 6 × Σd² ÷ (n × (n² − 1)). It is +1 for a perfect increasing relationship, −1 for a perfect decreasing one and near 0 for none.
- The t statistic is ρ × √((n − 2) ÷ (1 − ρ²)) with n − 2 degrees of freedom, which gives the p-value. The confidence interval uses the Fisher transformation with the Bonett and Wright standard error.
Example
Ten students are ranked on hours of study and on exam score, and the squared rank differences add up to Σd² = 24. Then ρ = 1 − 6 × 24 ÷ (10 × 99) = 0.855. The t statistic is 4.654 with 8 degrees of freedom, so the p-value is about 0.0016. The 95 % confidence interval runs from 0.386 to 0.973, which indicates a very strong relationship.
Why it matters
Many data, such as survey ratings, rankings and skewed measurements, do not suit Pearson’s correlation. Spearman’s coefficient works on ranks, so it is robust to outliers and to curved but steady relationships, and it is simple to compute by hand.
Good to know
The formula is exact when there are no tied ranks. The p-value uses a t approximation that is good for samples of about 10 or more, and exact tables are used for very small ones. The confidence interval uses the Bonett and Wright variance, and with 4 pairs or fewer the result is not reliable.
Related tools
The correlation significance calculator tests Pearson’s r, and the Mann-Whitney U calculator compares two groups by ranks.