StatGardenREF. DESK
Calculators/Statistics/Spearman’s rank correlation
Statistics

Spearman’s rank correlation calculator

Measures a monotonic relationship between two variables using their ranks, ties included.

Published 6 August 2026 · Updated 25 September 2026

What this calculator does

Spearman correlation replaces the data with its ranks and correlates those instead. It measures whether the relationship is consistently increasing or decreasing, not whether it is a straight line.

That distinction matters. A relationship that rises steeply then levels off is not linear at all, so Pearson correlation would report less than 1, but Spearman returns exactly 1 because the ordering is perfectly preserved. Working on ranks also makes the measure indifferent to outliers, since an extreme value simply becomes the highest rank.

The formula

Formularₛ = 1 − 6Σd² / (n(n²−1)), using average ranks for tied values

Both variables are converted to ranks, with tied values receiving the average of the ranks they span. The correlation is then 1 minus 6 times the sum of squared rank differences divided by n(n²−1). Where ties are present the calculator uses the average-rank method, which keeps the result consistent with computing Pearson correlation on the ranks directly.

TermMeaning
MonotonicConsistently increasing or decreasing, without needing to be a straight line.
RankPosition when sorted, with ties averaged.
rₛThe Spearman coefficient, from −1 to 1.
Pearson correlationThe linear alternative, which Spearman becomes when applied to ranks.

The inputs explained

FieldWhat to enter
X valuesX values, comma or space separated.
Y valuesY values, in the same order and the same count as X.

When to use it

Working with ordinal data

Rankings, ratings and ordered categories have no meaningful arithmetic, so a rank-based measure is the correct choice.

Handling a curved relationship

Where the association is clearly monotonic but not linear, Spearman describes it properly and Pearson understates it.

Data with outliers

An extreme value becomes just the top rank, so it cannot distort the measure the way it distorts Pearson.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

What does Spearman give for different relationships?

Perfect, moderate and perfectly inverse relationships.

Three pairs of variables
Y values (X = 1 to 6)Spearman’s rsSum of squared rank differencesStrength
6, 5, 4, 3, 2, 1-1.00070.000Strong
2, 1, 5, 3, 6, 40.657112.000Moderate
1, 2, 3, 4, 5, 61.0000Strong
The two perfect rows give exactly −1 and 1, with squared rank differences of 70 and 0 respectively. The middle row scrambles the order moderately and lands at 0.6571. The sum of squared rank differences is the whole computation: zero means the orderings match exactly.

Questions

When should I use Spearman instead of Pearson?

When the data is ordinal, when the relationship is monotonic but curved, or when outliers would distort a Pearson correlation. Pearson remains preferable for genuinely linear relationships in interval data, where it uses more of the information available.

Can Spearman be 1 when Pearson is not?

Yes, and this is the key difference. Any strictly increasing relationship gives a Spearman of exactly 1, however curved. Pearson would report less than 1 for the same data because it measures departure from a straight line, not departure from consistent ordering.

How are ties handled?

Tied values share the average of the ranks they would have occupied. Two values tied for third and fourth both receive rank 3.5. The simple 1 − 6Σd² formula is technically exact only without ties, so with ties the calculation falls back to correlating the averaged ranks directly.

Does Spearman detect any relationship?

Only monotonic ones. A U-shaped relationship, where y falls then rises, can give a Spearman near zero despite y being perfectly determined by x. No single correlation coefficient detects all dependence, which is why plotting the data remains essential.

For the linear version, see the correlation coefficient calculator. For the unstandardised measure, see the covariance calculator.