Spearman’s Rank Correlation Coefficient
Maths: Statistics for machine learning
2 min read
Published Oct 22 2025, updated Oct 23 2025
Guide Sections
Guide Comments
Spearman’s correlation measures the strength and direction of a monotonic relationship between two variables.
It’s a non-parametric test — meaning it doesn’t assume normality or linearity.
In simple terms:
“Spearman’s correlation checks whether two variables tend to increase or decrease together — even if the relationship isn’t perfectly straight.”
The Formula
Spearman’s ρ is computed using the ranks of the data rather than their raw values.

Where:
- di = difference between the ranks of each pair (xᵢ and yᵢ)
- n = number of observations
When to Use Spearman’s vs Pearson’s
- Data are continuous and linear - use Pearson’s r
- Data are ordinal (ranked) - use Spearman’s ρ
- Relationship is non-linear but monotonic - use Spearman’s ρ
- Data contain outliers or are not normal - use Spearman’s ρ
Interpretation of ρ
ρ value | Relationship | Description |
+1.0 | Perfect positive monotonic | As X increases, Y always increases |
+0.7 to +0.9 | Strong positive | High ranks of X → high ranks of Y |
0 | No relationship | No monotonic pattern |
–0.7 to –0.9 | Strong negative | High X → low Y |
–1.0 | Perfect negative monotonic | As X increases, Y always decreases |
Hypothesis Testing
- H₀ (Null Hypothesis) - No correlation between the two variables (ρ = 0)
- H₁ (Alternative Hypothesis) - There is a significant correlation (ρ ≠ 0)
If p ≤ 0.05, reject H₀ → significant monotonic correlation.
If p > 0.05, fail to reject H₀ → no significant correlation.
Example in Python
Let’s see how Spearman’s correlation performs on a non-linear but monotonic dataset.
Example Output:
Even though the relationship isn’t linear (log-shaped), Spearman detects a strong correlation while Pearson’s r might underestimate it.
Pearson vs Spearman — Key Differences
Feature | Pearson’s r | Spearman’s ρ |
Relationship type | Linear | Monotonic (increasing/decreasing) |
Data type | Continuous | Ordinal or continuous |
Assumes normality? | Yes | No |
Sensitive to outliers? | Yes | No |
Uses | Raw values | Ranked values |
Test type | Parametric | Non-parametric |
Assumptions
- Variables are ordinal, interval, or ratio - Not categorical
- Relationship is monotonic - Always increasing or decreasing
- Data have no strong ties - (Spearman can still handle them with corrections)














