How to calculate Spearman's rank correlation
- Copy the two columns together with the header (ranks, scores or measurements all work).
- Select the two columns whose ranks to compare as Variable X and Variable Y.
- Press Analyze and check ρ, the p-value and the interpretation in the statistics panel.
Worked example with sample data
The sample data are 25 pairs of heating time (2-50 min, every 2 min) and hardness (HRC). Hardness rises quickly at first, then from about 22 minutes only fluctuates between 54.6 and 58.7 without rising further.
Spearman's ρ is 0.8419 (p=1.326e-07), a 'very strong positive monotonic relationship'. The Pearson r of the same data is 0.8069, smaller than ρ, because the relationship is not a straight line but a curve that bends and levels off.
The linear trendline in the statistics panel (R² = 0.6510) also fails to follow the points at the start and the end. For relationships that 'keep rising, but not in a straight line', the rank-based ρ describes the strength better.
The fact that hardness hardly rises beyond 25 minutes of heating does not show in the coefficient but is clear on the scatter plot. Look at the numbers and the chart together.
How it is calculated
X and Y are each converted to ranks from the smallest value (ties get the average rank), and ρ is the Pearson correlation of those ranks. The p-value is a two-sided test using the t distribution with n-2 degrees of freedom, the same as SciPy's spearmanr.
When does it differ from Pearson?
When the relationship is curved but keeps going in one direction, ρ comes out larger than r. A typical case is the heating time and hardness in the example, which rise quickly at first and then level off. ρ is also less affected when a few extreme values inflate r.
How to read Spearman's ρ
- The strength scale is the same as for Pearson (|ρ| cut-offs 0.1, 0.3, 0.5, 0.7). A positive sign means the variables increase together; negative means opposite directions.
- A p-value below 0.05 means the monotonic relationship is statistically significant.
- Even a high ρ cannot capture relationships that change direction, like a U shape. Check the shape of the plot too.
Frequently asked questions
What happens with ties (equal values)?
Equal values get the average rank. For example, if 2nd and 3rd place are equal, both get rank 2.5.
Can I use it for ordinal data (1-5 satisfaction scores)?
Yes. It only uses ranks, so it suits ordinal data such as Likert scales better than Pearson.
How is it different from Kendall?
Both are rank correlations. Kendall's τ is defined by the share of concordant pairs, comes out smaller than ρ and is more stable for small samples.