Spearman’s Rank Correlation Explained: Formula and When to Use It
Spearman rho is Pearson correlation applied to ranks. It measures whether one list rises as the other rises, without requiring a straight line, and it limits the damage an outlier can do. This guide derives it, works an example with ties, and states when it beats Pearson and when it does not.
Sometimes the question is not whether two lists follow a straight line, but whether they move together in order: when one rises, does the other tend to rise too, by any amount, at any rate? Spearman rank correlation answers that question, and it does so by forgetting the values and remembering only their ranks.
- Spearman rho is the Pearson correlation of the ranks. It measures monotonic association, the tendency to move together in order, rather than straight-line association.
- When there are no ties, rho can be computed from the squared differences of ranks: 1 minus 6 times the sum of squared rank differences, divided by n times n squared minus 1.
- Spearman is resistant to outliers, because a distant value becomes only the highest or lowest rank, and it works for ordinal data, where Pearson values have no meaning.
- Spearman does not measure the strength of a straight line, does not give a slope, and does not prove causation. A strong rho with a curved relationship still needs a plot.
- Ranks, not values: the core idea
- Monotonic association, and why it is broader than linear
- The formula, with and without ties
- Worked example: eight pairs, with a tie
- Spearman versus Pearson, on the same data
- When to use Spearman, and when not to
- Ordinal data, ratings, and ranks that were never numbers
- Reporting rho honestly
Ranks, not values: the core idea
Spearman rank correlation, written rho or rs, begins by replacing each value with its rank. The smallest value in a list gets rank 1, the next gets rank 2, and so on up to rank n for the largest. The paired ranks are then correlated with the Pearson formula. That single step, replacing values by ranks, changes what the coefficient measures and what it is protected against. The values no longer matter, only their order. A pair that is ten times larger than its neighbours becomes merely the largest rank, and its distance from the rest, which would dominate a Pearson calculation, is forgotten. A list measured in arbitrary units, or in ordered categories such as poor, fair, good, and excellent, becomes a list of ranks, and the correlation becomes meaningful where Pearson, applied to the arbitrary numbers, would be meaningless or misleading.
The rank step also changes the question. Pearson asks whether the points cluster around a straight line. Spearman asks whether the points rise together in order, at any rate, along any increasing curve. A relationship that doubles, then doubles again, an exponential rise, gives a Spearman rho of 1 if the order is perfectly preserved, because the ranks rise together perfectly, while Pearson r, which demands a straight line, gives a lower value, because the curve bends away from the line. A relationship that rises steeply then flattens, a saturating curve, likewise gives rho near 1 and a lower r. Spearman is therefore the coefficient for the question, does more go with more, in order, and Pearson is the coefficient for the question, does more go with more, along a straight line. The two questions are different, and the choice between the coefficients is the choice of which question is being asked.
The calculator on the Correlation Coefficient Calculator page computes Pearson r. Spearman rho can be computed from the same paired lists by ranking each list first, then applying the Pearson formula to the ranks, which is a short spreadsheet exercise, described in the reporting section. The worked example below does the ranking by hand, including a tie, so that the tie rule, which is the only complication in the method, is visible in the open rather than hidden in a formula.
Monotonic association, and why it is broader than linear
A relationship is monotonic increasing if, whenever x rises, y never falls: it may stay the same, it may rise a little, it may rise a lot, but it does not go down. It is monotonic decreasing if, whenever x rises, y never rises. Perfect monotonic association gives a Spearman rho of plus 1 or minus 1, respectively, because the ranks match exactly, or exactly in reverse. Imperfect monotonic association gives a rho between, with the value reflecting how often the order is preserved and how badly it is broken. A single swapped pair among many lowers rho slightly. A thoroughly shuffled order gives rho near zero. A U-shaped relationship, which rises and then falls, gives rho near zero as well, because the order is preserved on one arm and reversed on the other, and the two cancel. Spearman, like Pearson, is blind to non-monotonic patterns, and a U-shape needs a plot and a different analysis, not a rank correlation.
The breadth of monotonic association is both the strength and the weakness of Spearman. It detects relationships that Pearson misses, including curved, accelerating, and saturating relationships, and it does so without assuming anything about the shape of the curve beyond its direction. But it also discards information: the size of the gaps between values, which Pearson uses, is thrown away, and with it the ability to say how much y changes per unit of x, or to fit a line, or to predict a value. A Spearman rho of 0.8 says the order is strongly preserved. It does not say the relationship is strong in any quantitative sense beyond order, and it does not license a prediction. The coefficient should be reported as what it is, a rank association, and not dressed in the language of linear strength or of prediction.
The formula, with and without ties
The general definition of Spearman rho is the Pearson correlation of the ranks. Compute the ranks of x, compute the ranks of y, and apply the Pearson formula to the two rank lists. That definition is always correct, with ties or without, and it is the definition to use in software, where the ranking and the Pearson calculation are both built in. The simplified formula, often quoted in textbooks, applies only when there are no tied ranks, and it is: rho equals 1 minus 6 times the sum of the squared differences of the paired ranks, divided by n times (n squared minus 1). The difference for each pair, d, is the x rank minus the y rank, and the sum is over all pairs. The simplified formula is shorter to compute by hand, and it is exact when there are no ties, because the rank lists then have the same mean and the same sum of squares, and the Pearson formula reduces to the simplified form. When ties exist, the simplified formula is approximate, and the Pearson-on-ranks definition should be used instead, with tied values given the average of the ranks they would have occupied.
Ties are handled by mid-ranks. If two values tie for ranks 3 and 4, each receives rank 3.5, the average. If three values tie for ranks 5, 6, and 7, each receives rank 6. The mid-rank preserves the sum of the ranks, which is what keeps the Pearson calculation honest, and it reflects the information actually available: the tied values are known to be equal, and no order between them should be invented. The worked example below contains one tie, and the mid-rank is shown explicitly, so that the rule can be followed on any data. A data set with many ties, such as a rating scale with only four levels, will have many mid-ranks, and the simplified formula will be noticeably wrong, which is a further reason to use the general definition in practice, and to treat the simplified formula as a teaching device for the no-tie case.
Worked example: eight pairs, with a tie
Eight applicants are ranked by two interviewers, or, equivalently, eight products have a price and a customer rating, and the question is whether higher price goes with higher rating, in order. The pairs, as (x, y), are: (10, 3), (20, 5), (30, 4), (40, 7), (50, 6), (60, 9), (70, 8), and (80, 10). The x values are already in order, so their ranks are 1 through 8. The y values, in order of size, are 3, 4, 5, 6, 7, 8, 9, 10, but two y values tie in the data as given? No: the y values are all distinct, 3, 4, 5, 6, 7, 8, 9, 10, so a tie must be introduced honestly. Change the fourth pair to (40, 6), so that y values 6 appear twice, in pairs 4 and 5, and the example carries a tie. The pairs are now: (10, 3), (20, 5), (30, 4), (40, 6), (50, 6), (60, 9), (70, 8), (80, 10).
Rank x: 1, 2, 3, 4, 5, 6, 7, 8. Rank y: the y values sorted are 3, 4, 5, 6, 6, 8, 9, 10. The value 3 gets rank 1, 4 gets rank 2, 5 gets rank 3, the two 6 values share ranks 4 and 5, so each gets 4.5, 8 gets rank 6, 9 gets rank 7, and 10 gets rank 8. The y ranks, in pair order, are therefore 1, 3, 2, 4.5, 4.5, 7, 6, 8. The differences d, x rank minus y rank, are: 0, minus 1, 1, minus 0.5, 0.5, minus 1, 1, 0. The squared differences are: 0, 1, 1, 0.25, 0.25, 1, 1, 0, summing to 4.50. The simplified formula, applied despite the tie as an approximation, gives rho equal to 1 minus 6 times 4.50, divided by 8 times 63, or 1 minus 27 divided by 504, or 1 minus 0.0536, which is 0.946. The Pearson-on-ranks calculation, which is exact with the tie, gives a very close value, about 0.946, and the agreement confirms that a single tie moves the result only slightly. The association is strongly monotonic: higher x goes with higher y, in order, with two small swaps, pairs 2 and 3, and pairs 6 and 7, breaking the perfect order.
Pearson r on the original values, for comparison, is about 0.94, also high, because the relationship in this example is roughly linear as well as monotonic. The two coefficients agree when the relationship is both linear and monotonic, and they diverge when it is monotonic but curved, or when outliers distort the values. The divergence, not the agreement, is the diagnostic: compute both, and if they differ substantially, plot the data and ask whether the relationship is curved, whether an outlier is driving Pearson, or whether the values themselves are unreliable. The example is deliberately clean, so that the mechanics are visible. Real data are messier, and the mess is where the choice of coefficient earns its keep.
Spearman versus Pearson, on the same data
| Situation | Pearson r | Spearman rho | Which to report |
|---|---|---|---|
| Straight line, no outliers | High | High | Either; Pearson gives slope too |
| Curved but monotonic rise | Moderate | High | Spearman for order; plot for shape |
| Straight line with one distant outlier | Distorted | Nearly unchanged | Spearman, with outlier stated |
| U-shaped relationship | Near zero | Near zero | Neither; plot and model the curve |
| Ordinal ratings, no true numbers | Meaningless | Meaningful | Spearman |
| Constant list, or n below 3 | Undefined or meaningless | Undefined or meaningless | Neither; report the data |
The table summarises the decision, and the pattern is that Spearman is the safer default when the question is about order, when the values are ranks or ratings, when outliers are present and cannot be resolved, or when the relationship is expected to be monotonic but not linear. Pearson is the right choice when the question is about a straight line, when a slope and a prediction are needed, when the values are measured on an interval scale and the relationship is plausibly linear, and when the data have been checked for outliers and curvature. Neither coefficient is a general-purpose measure of association, and neither should be reported without the plot, the sample size, and a statement of which question was asked. The choice should be made before seeing the results, on the basis of the question and the data type, not after seeing which coefficient gives the more impressive value, because choosing the larger coefficient after the fact is a form of selective reporting.
When to use Spearman, and when not to
Use Spearman when the data are ordinal, when the relationship is monotonic but not necessarily linear, when outliers are present, when the distributions are skewed and the values themselves are less trustworthy than their order, or when the sample is small and the Pearson assumptions are doubtful. Do not use Spearman when a straight-line fit, a slope, or a prediction is the goal, because Spearman gives none of those, and a Pearson analysis, with its assumptions checked, is the right tool. Do not use Spearman as a cure for a non-monotonic relationship, because it will return near zero for a U-shape, just as Pearson does, and the cure for a U-shape is to model the curve, not to change the coefficient. And do not use Spearman to hide an outlier problem: the outlier should be stated, investigated, and reported with and without, whether the coefficient is Pearson or Spearman, because the outlier is information about the data, and hiding it behind a robust coefficient conceals the information along with the distortion.
Sample size matters for Spearman as it does for Pearson, though the small-sample behaviour is slightly kinder, because ranks are bounded. With n below about 10, a Spearman rho must be very high to be distinguishable from chance, and a moderate rho from a handful of pairs is a suggestion, not a finding. Significance tables and software p-values for Spearman exist, and they should be used with the same caution as Pearson p-values: they test the null hypothesis of no monotonic association, under assumptions about independence and random sampling, and they do not measure the size or the importance of the association. Report rho, report n, report the plot, and let the reader judge. The p-value is a companion to the report, not a substitute for it.
Ordinal data, ratings, and ranks that were never numbers
Ordinal data are data with an order but no meaningful spacing: a Likert scale from strongly disagree to strongly agree, a quality rating from poor to excellent, a finishing position in a race, a priority ranking. The numbers assigned to such categories, 1 to 5, or 1 to 10, are labels, and the gaps between them are not equal in any measured sense. Pearson correlation applied to such labels treats the gaps as equal, which invents information the data do not contain, and the resulting r depends on the arbitrary numbering. Spearman, which uses only the order, respects the data as they are, and its rho is invariant to any monotonic renumbering of the labels, which is the correct behaviour for ordinal data. The same logic applies to ranks themselves: a rank correlation of ranks is Spearman by definition, and it should not be dressed as Pearson.
The invariance property is worth stating precisely, because it is the formal reason Spearman is the right coefficient for ordinal data. Any strictly increasing transformation of a list, replacing each value by a larger value for larger original values, leaves the ranks unchanged, and therefore leaves rho unchanged. Pearson r, by contrast, changes under non-linear increasing transformations, because it uses the values, not only their order. A relationship that is perfectly monotonic will have rho equal to 1 under any such transformation, while r will vary with the transformation chosen. The coefficient that is stable under the transformations the data actually allow is the coefficient that measures what the data can support, and for ordinal data that coefficient is Spearman.
Reporting rho honestly
Report Spearman rho with the same companions Pearson requires, plus one extra: the tie information. Give rho, n, the fact that ranks were used, the number and size of ties if any, and a description of the plot. In a spreadsheet, rho is computed by ranking each list with RANK.AVG, which assigns mid-ranks to ties, then applying CORREL to the rank ranges. In the worked example, with x in A1:A8 and y in B1:B8, the x ranks in C1:C8 are =RANK.AVG(A1,$A$1:$A$8,1), the y ranks in D1:D8 are =RANK.AVG(B1,$B$1:$B$8,1), and rho is =CORREL(C1:C8,D1:D8). In statistical software, the Spearman option performs the same steps. The calculator on the hub page computes Pearson r; to obtain rho, rank the lists first, enter the ranks as the paired lists, and read the Pearson output as rho, labelling it as such in the report, because the output label will say r, and the reader must be told that the input was ranks.
A complete report sentence reads: Spearman rho equals 0.95, n equals 8, with one tie of two values in y, and the ranks rise together with two small swaps. That sentence can be judged: the sample is small, the tie is stated, the pattern is described, and the value is not asked to carry more than it can. A bare rho, without n, without the tie note, and without the plot, is as unfinished as a bare r, and it invites the same misreadings: causation, linearity, prediction, and importance, none of which rho provides. The discipline is the same for both coefficients, because the discipline is about reporting, not about arithmetic, and it is the discipline that makes a correlation a finding rather than a number.
Frequently asked questions
What is Spearman rank correlation?
Spearman rho is the Pearson correlation computed on the ranks of the data rather than on the values themselves. It measures monotonic association, the tendency for one list to rise as the other rises, in order, without requiring a straight-line relationship.
How do you calculate Spearman rho?
Rank each list from smallest to largest, giving tied values the average of the ranks they share, then apply the Pearson formula to the two rank lists. When there are no ties, the simplified formula applies: rho equals 1 minus 6 times the sum of squared rank differences, divided by n times n squared minus 1.
When should I use Spearman instead of Pearson?
Use Spearman when the question is about order rather than a straight line, when the data are ordinal ratings or ranks, when the relationship is monotonic but curved, or when outliers are present and cannot be resolved. Use Pearson when a straight-line fit, a slope, or a prediction is needed and the data have been checked for outliers and curvature.
What does Spearman rho measure that Pearson r does not?
Spearman measures whether the order is preserved, at any rate of increase, including curved, accelerating, and saturating relationships. Pearson measures only straight-line clustering, so a perfect curved rise can give rho equal to 1 while r is substantially lower.
How are ties handled in Spearman correlation?
Tied values receive the average of the ranks they would have occupied, called mid-ranks. Two values tying for ranks 4 and 5 each receive rank 4.5. The Pearson-on-ranks definition should be used when ties exist, since the simplified squared-difference formula is exact only without ties.
Does a high Spearman rho prove causation?
No. Like Pearson, Spearman measures association, in this case monotonic association, and it cannot distinguish causation from a shared third factor, a shared trend, or chance. It also does not give a slope or a prediction. Report rho with n, the tie information, and a plot.
Try it on the calculator
Rank two lists, enter the ranks as paired data, and read the Pearson output as Spearman rho, with the tie information and the plot alongside.
Open the Correlation Coefficient Calculator →- 1Pearson Correlation Coefficient: Formula and Worked Example
Pearson r measures the strength of a straight-line relationship between two lists of numbers. This guide…
- 2
- 3
- 4
