Spearman correlation
Association and correlation · reference distribution: t(n−2) approx.
When to use it
Measure the monotonic relationship between two variables, even if non-linear or ordinal: it is Pearson computed on ranks.
Null hypothesis
There is no monotonic association.
Assumptions
- At least ordinal variables
- Independent pairs
Test statistic
\rho = 1 - \dfrac{6 \sum d_i^2}{n(n^2 - 1)}Effect size
ρ itself.
How to report it
ρ = .51, n = 30, p = .004
In R and Python
R
cor.test(x, y, method = "spearman")
Python
stats.spearmanr(x, y)
In Python, stats is scipy.stats and np is numpy.
Variants and alternatives
- Kendall’s tau, more stable with small samples and ties
Where it sits in the catalog
Association and correlation. Instead of comparing groups, they measure whether two variables move together, and how strongly.
In the decision tree
- What do you want to do? Measure the relationship between two variables
- What kind of variables are they? Both numeric
- Is the relationship linear, without strong extreme values? No, or the variables are ordinal
- Is the sample small, or does it have many ties? No