A Spearman's rank correlation calculator measures how well the relationship between two variables can be described by a rising or falling trend, without assuming a straight line. Enter the pairs of values, and the calculator ranks each variable, treats ties properly and gives Spearman's ρ, the test statistic and the p-value. It suits ordinal data, data with outliers and curved but steady relationships. It runs in your browser.
How to use the Spearman's rank correlation calculator
- Type your data as pairs, one pair on each line, with the x value first.
- Press Calculate.
- Read ρ, the test statistic and the p-value.
What Spearman's ρ is
The Wikipedia article on Spearman's rank correlation defines the coefficient as the Pearson correlation coefficient between the rank variables. The raw values are replaced by their ranks, and the correlation is worked out on the ranks. The value runs from −1 to 1. It assesses monotonic relationships, whether linear or not: a value of +1 or −1 means that each variable is a perfect monotone function of the other, and 0 means no tendency for the ranks to rise or fall together.[1]
The shortcut formula
When all the ranks are distinct, the page gives ρ = 1 − 6 × Σdᵢ² ÷ (n(n² − 1)), where dᵢ is the difference between the two ranks of the i-th pair and n is the number of pairs. It says that the formula applies only when all n ranks are distinct integers.[1] If there are tied values, each is given the average of the positions that they occupy in the ascending order, and the page says that the shortcut then gives incorrect results, so ρ must be found as the Pearson correlation of the ranks.[1] The calculator does this, and it shows the sum of squared differences when there are no ties.
The worked example from the page
The page's example uses made-up data on IQ and the hours of television that people watch each week. The pairs are (106, 7), (100, 27), (86, 2), (101, 50), (99, 28), (103, 29), (97, 20), (113, 12), (112, 6) and (110, 17). The ranks of the IQ run from 1 for 86 to 10 for 113, and the sum of the squared rank differences is 194, with n = 10. Then ρ = 1 − 6 × 194 ÷ (10 × 99) = −29 ÷ 165, which is −0.1758, and the p-value is 0.627, using the t distribution.[1] Enter the ten pairs to see the same results. The small negative value, and the large p-value, show that there is no real link between these two variables.
The significance test
The page gives the test statistic t = r × √((n − 2) ÷ (1 − r²)), which is approximately distributed as Student's t with n − 2 degrees of freedom under the null hypothesis of no correlation.[1] For the example, t = −0.505 with 8 degrees of freedom. The calculator gives the two-tailed p-value. The page also mentions a permutation test and a test using Fisher's transformation, and it notes that a small coefficient can be significant in a large sample without being meaningful.[1] Judge both the size of ρ and the p-value.
When to use Spearman rather than Pearson
Pearson's correlation measures straight-line association and is easily distorted by outliers. Spearman's works on ranks, so an extreme value counts only as the highest rank. It is the better choice for ordinal data, such as survey ratings, for skewed data, and for relationships that rise steadily but not along a straight line. For the pairs (1, 1), (2, 4), (3, 9) and (4, 16), which follow a curve, Spearman's ρ is exactly 1, while Pearson's coefficient is a little less than 1.
How strong is strong
The page notes that there is no agreed scale for the strength of a correlation, and that the cut-offs between weak and strong depend on the field.[1] For this reason the calculator does not attach a label. As a rough guide, many people read values near 0 as no link, values above 0.5 or below −0.5 as a clear one, and values near ±1 as a very strong one, but this depends on what you are measuring.
Entering your data
Put one pair on each line, with the x value first and the y value second, and a space, a tab or a comma between them. You can paste two columns from a spreadsheet. The values may be any numbers, such as scores, ranks or measurements. If you already have ranks, enter them directly, and the calculator will treat them as values. At least three pairs are needed, and up to 5,000 are accepted.
An example with ties
For the pairs (1, 1), (2, 2), (2, 3), (4, 4) and (5, 6), the two values of 2 share the ranks 2 and 3, so each gets 2.5. The calculator then finds the Pearson correlation of the ranks, which is 0.975, and tells you that ties were present. Using the shortcut formula on the tied ranks would give a slightly different, and wrong, answer, which is why the calculator does not show the sum of squared differences when ties are present.
Common mistakes
- Calling it a straight-line measure. It measures a monotonic trend.
- Using the shortcut with ties. Use the Pearson correlation of the ranks.
- Reading correlation as cause. A link does not show a cause.
- Trusting the p-value for a tiny sample. Use exact tables below 10 pairs.
What next
Use this often? Add Spearman's R to your Home screen.
Frequently asked questions
What is Spearman's rank correlation calculator?
A tool that finds how well the relationship between two variables is a rising or falling trend, from the ranks of the values.
What is the formula for Spearman's ρ?
ρ = 1 − 6Σd² ÷ (n(n² − 1)) when there are no ties, where d is the difference between the ranks of each pair.
How are ties handled?
Tied values get the average of their ranks, and ρ is found as the Pearson correlation of the ranks.
What is the difference between Spearman and Pearson?
Pearson measures straight-line association. Spearman measures a monotonic trend and is less affected by outliers.
How is the p-value found?
From t = r × √((n − 2) ÷ (1 − r²)) with n − 2 degrees of freedom.
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.