What Is Spearman Rank Correlation?
The method was developed by the British psychologist Charles Spearman and first published in 1904. Spearman used it to study the relationship between students' scores in different subjects — a question that needed correlation but did not assume the scores followed a normal distribution. That same logic applies today whenever your data is ordinal, contains outliers, or follows a monotonic pattern that is not strictly linear.
Understanding what "monotonic" means is the key to understanding when Spearman applies. A monotonic relationship means that as one variable increases, the other either always increases or always decreases — but not necessarily at a constant rate. A linear relationship is a special case of a monotonic one. The Pearson Correlation specifically measures linear relationships; Spearman measures the broader monotonic class. Both are covered in depth at Statistics Fundamentals.
- Symbol: ρ (rho) for population; rs often used in samples
- Range: −1 to +1 inclusive
- Type: Nonparametric — does not assume normality
- Data type: Works on ordinal data, ranks, and continuous data with violations of normality
- Outlier sensitivity: Robust — extreme values only get the highest/lowest rank
- Relationship detected: Monotonic (not restricted to linear)
- Null hypothesis: H₀: ρ = 0 (no monotonic relationship in the population)
The Spearman Rank Correlation Formula
There are two equivalent ways to compute Spearman's rho. For most classroom and hand-calculation purposes, the rank difference formula is the standard approach.
The Rank Difference Formula
ρ = Spearman's rho
d = rank(Xi) − rank(Yi) for each pair
Σd² = sum of squared rank differences
n = number of data pairs
This formula is a shortcut derived from the Pearson correlation formula applied to ranks. It gives the exact same answer as computing Pearson's r on the ranked data when there are no tied values. The "6" in the numerator is a mathematical constant that comes from the derivation, not something you choose.
When there are many tied ranks in your data, the rank difference formula becomes slightly inaccurate. In that case, use the Pearson formula directly on the ranked values: ρ = Σ[(rankX − mean rankX)(rankY − mean rankY)] / √[Σ(rankX − mean rankX)² × Σ(rankY − mean rankY)²]. Statistical software uses this approach automatically.
Variables and Notation Explained
| Symbol | Meaning | Example (n = 5) |
|---|---|---|
| n | Total number of paired observations | 5 students, so n = 5 |
| rank(Xi) | Rank of the i-th value of variable X | Rank of student i's effort score |
| rank(Yi) | Rank of the i-th value of variable Y | Rank of student i's exam score |
| di | Rank difference for pair i: rank(X) − rank(Y) | If effort rank = 3, exam rank = 4: d = −1 |
| d²i | Squared rank difference | (−1)² = 1 |
| Σd² | Sum of all squared rank differences | e.g., 1 + 4 + 0 + 1 + 0 = 6 |
| ρ | Spearman's rho — the correlation coefficient | Result after applying the formula |
How to Calculate Spearman Rank Correlation (Step by Step)
The 5-step procedure below works for any dataset without ties. A worked example immediately follows each step so you can see the numbers at every stage.
Rank Each Variable Separately
Sort the X values from smallest to largest and assign rank 1 to the smallest, rank 2 to the next, and so on up to rank n. Do the same for Y, independently of X. Do not rank the pairs together — each variable gets its own ranking.
Calculate the Rank Difference (d) for Each Pair
For each observation i, subtract: di = rank(Xi) − rank(Yi). Differences can be positive or negative — that is expected. A positive d means the X rank was higher than the Y rank for that pair.
Square Each Difference: d²
Square every d value to remove negative signs. All d² values must be zero or positive. If you have any negative d², you made an arithmetic error — recheck your ranks.
Sum the Squared Differences: Σd²
Add all the d² values together to get Σd². This single number summarizes how much the ranks disagreed across all pairs. A Σd² of 0 would mean the ranks were identical for every pair — giving ρ = +1.
Apply the Formula: ρ = 1 − (6Σd²) / n(n² − 1)
Substitute your Σd² and n into the formula. The result is ρ, which will be between −1 and +1. Values close to +1 indicate that the two rankings agree closely; values near −1 indicate they are nearly reversed; values near 0 indicate little to no monotonic relationship.
Worked Example 1: Student Effort vs Exam Score
Problem: A teacher records effort ratings (1–10) and end-of-term exam scores for 8 students. Does student effort correlate with exam performance?
| Student | Effort (X) | Exam Score (Y) | Rank X | Rank Y | d = Rank X − Rank Y | d² |
|---|---|---|---|---|---|---|
| A | 8 | 75 | 6 | 5 | 1 | 1 |
| B | 3 | 42 | 2 | 2 | 0 | 0 |
| C | 9 | 91 | 7 | 7 | 0 | 0 |
| D | 5 | 68 | 4 | 4 | 0 | 0 |
| E | 1 | 35 | 1 | 1 | 0 | 0 |
| F | 7 | 80 | 5 | 6 | −1 | 1 |
| G | 10 | 95 | 8 | 8 | 0 | 0 |
| H | 4 | 55 | 3 | 3 | 0 | 0 |
| Σd² = | 2 | |||||
Ranking X (Effort): Values sorted: 1, 3, 4, 5, 7, 8, 9, 10 → ranked 1 through 8 respectively. Each student gets the rank corresponding to their effort value's position in the sorted list.
Ranking Y (Exam Score): Values sorted: 35, 42, 55, 68, 75, 80, 91, 95 → ranked 1 through 8 respectively.
Rank differences d and d²: Most students have d = 0 — their effort rank matched their exam rank exactly. Students A and F have d = ±1 because their ranks differ by one position.
Sum of squared differences: Σd² = 1 + 0 + 0 + 0 + 0 + 1 + 0 + 0 = 2
Apply the formula with n = 8:
ρ = 1 − (6 × 2) / (8 × (64 − 1))
ρ = 1 − 12 / (8 × 63)
ρ = 1 − 12 / 504
ρ = 1 − 0.0238
ρ = 0.976
✅ Conclusion: ρ = 0.976. There is a very strong positive monotonic relationship between student effort and exam scores. Students who put in more effort almost always scored higher.
How to Handle Tied Ranks
Ties occur when two or more observations have the same value. The standard solution is to assign each tied observation the average of the ranks they would have received if they were slightly different.
If observations would have received ranks 3, 4, and 5 but all three have the same value, each receives rank (3 + 4 + 5) / 3 = 4. The next distinct value then receives rank 6.
Worked Example 2: Customer Satisfaction Ratings (With Ties)
Problem: A market researcher records customer satisfaction scores (X) and repurchase intention scores (Y) for 6 customers. Two customers share the same satisfaction score of 7.
| Customer | Satisfaction (X) | Repurchase (Y) | Rank X | Rank Y | d | d² |
|---|---|---|---|---|---|---|
| 1 | 4 | 3 | 1 | 1 | 0 | 0 |
| 2 | 6 | 5 | 2 | 2 | 0 | 0 |
| 3 | 7 | 6 | 3.5 | 3 | 0.5 | 0.25 |
| 4 | 7 | 7 | 3.5 | 4 | −0.5 | 0.25 |
| 5 | 8 | 9 | 5 | 5 | 0 | 0 |
| 6 | 9 | 10 | 6 | 6 | 0 | 0 |
| Σd² = | 0.50 | |||||
Tied ranks for X: Two customers scored 7. They would have occupied ranks 3 and 4 (the next two available). Their average rank is (3 + 4) / 2 = 3.5. Both receive rank 3.5. The next customer (score = 8) gets rank 5.
No ties in Y: All repurchase scores are distinct, so ranks 1–6 are assigned normally.
Apply the formula: ρ = 1 − (6 × 0.50) / (6 × (36 − 1)) = 1 − 3 / 210 = 1 − 0.0143 = 0.986
✅ ρ = 0.986 — an extremely strong positive monotonic relationship. Customer satisfaction rankings and repurchase intention rankings are almost perfectly aligned.
For datasets with many ties, the rank difference formula produces a slightly biased result. In that case, compute Pearson's r directly on the ranked data (including averaged tied ranks). R, Python (SciPy), SPSS, and Excel all do this automatically when you request Spearman correlation.
How to Interpret Spearman's Rho
The sign tells you the direction; the magnitude tells you the strength. These two pieces of information are independent.
In social sciences, ρ = 0.50 might be considered substantial. In engineering quality control, ρ = 0.95 might be the minimum acceptable. Always interpret your ρ relative to the conventions and practical requirements of your specific field. A coefficient without a significance test is incomplete — a large ρ in a small sample may not be statistically meaningful.
Testing the Statistical Significance of ρ
Getting a non-zero ρ does not guarantee the relationship is real — it could be due to chance, especially with small samples. A significance test tells you the probability of observing your ρ (or a more extreme one) if the true population correlation is zero.
H₀: ρ = 0 (no monotonic relationship). H₁: ρ ≠ 0 (two-tailed) or ρ > 0 / ρ < 0 (one-tailed). Test statistic: t = ρ√(n−2) / √(1−ρ²), with df = n−2. Reject H₀ when |t| exceeds the critical value from the t-distribution table at your chosen α.
ρ = your calculated Spearman's rho
n = number of pairs
df = n − 2
For the student effort example above with ρ = 0.976 and n = 8:
Testing ρ = 0.976 at α = 0.05 (two-tailed, n = 8)
df = n − 2 = 8 − 2 = 6
Test statistic: t = 0.976 × √6 / √(1 − 0.952) = 0.976 × 2.449 / √0.048 = 2.390 / 0.219 = 10.91
Critical value from the t-distribution table at df = 6, α = 0.05 (two-tailed): t* = ±2.447
Decision: |t| = 10.91 > 2.447 → Reject H₀. The correlation is statistically significant at the 5% level (p < 0.001).
✅ Conclusion: The Spearman correlation of 0.976 is statistically significant (t(6) = 10.91, p < 0.001). The relationship between student effort and exam scores is not due to chance.
Spearman vs Pearson Correlation: When to Use Each
Both measure the relationship between two variables, but they ask different questions. Choosing between them depends on your data type, your distribution assumptions, and whether the relationship is linear or merely monotonic. The full details on the Pearson formula are at the Pearson Correlation guide.
| Property | Spearman (ρ) | Pearson (r) |
|---|---|---|
| Data type | Ordinal, ranked, or continuous | Continuous (interval or ratio) |
| Relationship detected | Monotonic (linear is a special case) | Linear only |
| Normality assumption | Not required (nonparametric) | Required for inference |
| Outlier sensitivity | Robust — outliers only get extreme rank | Sensitive — outliers pull the line |
| Data with ties | Handles via averaged ranks | Not designed for tied ordinal data |
| Small samples | Preferred when n < 20 and distribution is unknown | Can be used; t-distribution adjusts for small n |
| Efficiency | Slightly less efficient when normality holds | More efficient under normality |
| Calculation | Rank first, then apply formula | Apply formula directly to raw values |
| Introduced by | Charles Spearman (1904) | Karl Pearson (1895) |
Which Correlation to Use? — Decision Guide
Interactive Scatter Plot — See Spearman vs Pearson
The visualization below plots two variables and shows how Spearman and Pearson correlation differ for four classic dataset types. Select a dataset from the dropdown to see why the two methods can give meaningfully different results.
Raw data points are shown as dots. Each axis also shows the rank position. Notice how the outlier dataset (option 3) produces very different Pearson and Spearman values.
Assumptions of Spearman Rank Correlation
Spearman has fewer requirements than Pearson, but it is not assumption-free. Violating these conditions means the coefficient does not mean what you think it means.
Monotonic Relationship
The relationship between X and Y should be monotonic — as X increases, Y either consistently increases or consistently decreases. Spearman is not appropriate for U-shaped or other non-monotonic relationships. A scatter plot before calculating is always a good idea.
Ordinal or Continuous Data
Both variables must be at least ordinal — meaning values can be ordered from lowest to highest. Spearman is not suitable for nominal data (categories with no inherent order, like hair color or country of origin).
Paired Observations
Each X value must be paired with exactly one Y value. Both measurements must come from the same subject, time point, or experimental unit. Missing data in either variable eliminates that pair from the analysis.
Independence of Pairs
Each subject (row) must be independent of the others. If the same subject is measured multiple times, you have repeated measures data and may need a different approach. Independence also requires that measuring one pair does not influence another.
Real-World Applications of Spearman Rank Correlation
Education Research
Correlating student effort rankings with academic performance. Works for ordinal effort ratings that may not be normally distributed.
Clinical Medicine
Ranking pain severity (ordinal scale 1–10) against mobility scores. Spearman handles these scales without normality assumptions.
Market Research
Relating customer satisfaction ratings to repeat purchase likelihood. Survey Likert scales are ordinal — a natural fit for Spearman.
Finance
Comparing asset performance rankings across time periods. Useful when return distributions are skewed and outliers are present.
Biology & Ecology
Relating species abundance rankings across habitats. Field data is often non-normal with large variance.
Sports Analytics
Correlating team rankings in offense with their defensive rankings across a season. Ranks are the natural data format in standings.
Machine Learning
Feature selection: ranking features by importance and correlating with target variable rankings. Robust to non-linear relationships.
Social Science
Relating country rankings on freedom indices to rankings on quality-of-life measures. Cross-national data rarely meets normality.
Case Study Example — Pain Research
Researchers studying chronic pain used Spearman to correlate pain intensity rankings (NRS 0–10) with sleep quality rankings across 45 patients.
Pain ratings are measured on an 11-point numerical rating scale — ordinal data where the intervals between values cannot be assumed equal. Sleep quality is similarly ordinal. A Pearson correlation on these raw ordinal scores would make an unjustified assumption about equal intervals. The Spearman approach respects the ordinal nature of both measures by converting them to ranks first. This is the standard practice described in the BMJ Statistics Notes on Spearman's rank correlation.
Limitations of Spearman Rank Correlation
| Limitation | What It Means Practically | How to Address It |
|---|---|---|
| Loses information from raw values | Two datasets with very different raw patterns can produce the same ρ if their ranks match | Always inspect a scatter plot of raw data alongside ρ |
| Only detects monotonic relationships | A U-shaped relationship where Y first decreases then increases will show ρ ≈ 0 even though a clear relationship exists | Plot the data first; if non-monotonic, Spearman is the wrong tool |
| Sensitive to many ties | When most values are tied (e.g., a 5-point scale with large n), the rank difference formula becomes inaccurate | Use Pearson formula on ranks instead, as implemented in statistical software |
| Significance test assumes large n | The t-approximation for significance is less accurate for n < 10 | Use exact p-values from the Spearman Correlation Table for small samples |
| Does not establish causation | ρ = 0.95 does not mean X causes Y | Interpret in context; correlation is not causation regardless of the method used |
Spearman Rank Correlation Calculator
Enter your paired data below — one pair per row, X and Y values separated by a comma. The calculator will rank both variables, compute Σd², calculate ρ, and run the significance test automatically.
Spearman Rank Correlation Calculator
How to Calculate Spearman Correlation in Software
| Software | Command / Function | Notes |
|---|---|---|
| R | cor(x, y, method = "spearman") | Test significance with cor.test(x, y, method = "spearman") |
| Python (SciPy) | scipy.stats.spearmanr(x, y) | Returns (rho, p-value) directly |
| Python (Pandas) | df.corr(method='spearman') | Returns full correlation matrix |
| SPSS | Analyze → Correlate → Bivariate → check Spearman | Produces rho and two-tailed significance |
| Excel | Rank both columns with RANK.AVG(), then use CORREL() | No built-in Spearman function — must rank manually first |
| Stata | spearman varX varY | Reports rho and exact p-value |
| Minitab | Stat → Basic Statistics → Correlation → Spearman | Available in Minitab 19+ |
| SAS | PROC CORR SPEARMAN; | Inside a PROC CORR block with the SPEARMAN option |
Spearman Rank Correlation: Cheat Sheet
| Item | Value / Formula |
|---|---|
| Symbol | ρ (rho) or rs |
| Range | −1 ≤ ρ ≤ +1 |
| Perfect positive | ρ = +1 (ranks identical) |
| Perfect negative | ρ = −1 (ranks reversed) |
| No relationship | ρ = 0 |
| Main formula | ρ = 1 − (6Σd²) / n(n²−1) |
| Tied rank rule | Average the ranks: (rank₁ + rank₂) / 2 |
| Significance test | t = ρ√(n−2) / √(1−ρ²), df = n−2 |
| Null hypothesis | H₀: ρ = 0 |
| Data requirement | At least ordinal; no normality needed |
| Outlier sensitivity | Low — robust |
| Non-linearity | Handles monotonic non-linear relationships |
| R function | cor(x, y, method="spearman") |
| Python function | scipy.stats.spearmanr(x, y) |
Common Misconceptions About Spearman Correlation
| Misconception | Wrong | Correct |
|---|---|---|
| Spearman only works on ordinal data | False | Spearman works on any data that can be ranked, including continuous data with outliers or non-normal distributions |
| ρ = 0 means no relationship | False | ρ = 0 means no monotonic relationship. A strong U-shaped pattern would give ρ ≈ 0 even though a relationship clearly exists |
| Spearman is always better than Pearson | False | When the data is continuous, normally distributed, and the relationship is linear, Pearson is more statistically efficient (more power) |
| A significant ρ proves causation | False | No correlation statistic establishes causation. A significant ρ means the monotonic relationship is unlikely due to chance, nothing more |
| ρ = 0.70 means 70% of Y is explained by X | False | That interpretation applies to r² in Pearson regression. Spearman's ρ² does not have a direct variance-explained interpretation |
Frequently Asked Questions
Sources and Further Reading
- Spearman, C. (1904). The proof and measurement of association between two things. American Journal of Psychology, 15(1), 72–101. doi:10.2307/1412159 — The original paper introducing Spearman's method.
- Zar, J.H. (1972). Significance testing of the Spearman rank correlation coefficient. Journal of the American Statistical Association, 67(339), 578–580. — Standard reference for the t-based significance test.
- Myers, J.L., Well, A.D., & Lorch, R.F. (2010). Research Design and Statistical Analysis (3rd ed.). Routledge. — Comprehensive treatment of Spearman vs Pearson in Chapter 9.
- Hauke, J., & Kossowski, T. (2011). Comparison of values of Pearson's and Spearman's correlation coefficients on the same sets of data. Quaestiones Geographicae, 30(2), 87–93. doi:10.2478/v10117-011-0021-1
- NIST/SEMATECH Engineering Statistics Handbook — Spearman Rank Correlation. National Institute of Standards and Technology.
- SciPy Documentation: scipy.stats.spearmanr. — Python implementation reference.
- Bland, J.M., & Altman, D.G. (2011). Statistics Notes: Correlation, regression, and repeated data. BMJ, 343:d6209. — Practical guidance on choosing Spearman in clinical research.