Checking Spearman correlation when one list contains ties
Spearman correlation is the Pearson correlation of ranks, and tied values receive the average of the ranks they occupy. This guide shows why one tie keeps the coefficient just below one even when both lists rise together.
Ranks replace the raw values
Spearman correlation first turns each list into ranks, then computes the Pearson correlation of those ranks. The rank of a value is its position in sorted order. Ties get the average of the positions they occupy. For x = 1, 2, 2, 4 the sorted positions are 1, 2, 3 and 4, but the two 2s share positions 2 and 3, so each receives 2.5. The ranks are 1, 2.5, 2.5, 4. For y = 1, 2, 3, 4 there are no ties, and the ranks equal the values. The tool uses average ranks, which is the most common convention, though others exist. Some software ranks ties by order of appearance or by the lowest position in the tied group, and each rule yields a slightly different coefficient on the same data. Average ranking has one useful property: the ranks of a list of n values always add up to n(n + 1)/2, which is 10 for four values. Check that the sum is 10 for both lists here: 1 + 2.5 + 2.5 + 4 = 10, and 1 + 2 + 3 + 4 = 10.
The correlation of the ranks
The mean of both rank lists is 2.5. The x-rank deviations are -1.5, 0, 0 and 1.5, and the y-rank deviations are -1.5, -0.5, 0.5 and 1.5. The products add up to 2.25 + 0 + 0 + 2.25 = 4.5. The sum of squares for the x ranks is 4.5 and for the y ranks is 5. The coefficient is 4.5 divided by the square root of 4.5 × 5, which is 4.5 / 4.7434, about 0.948683. Pairing the tied ranks with distinct ranks cannot reach one, because the two lists are not exact linear functions of each other.
The tie-free control
With x = 1, 2, 3, 4 and y = 1, 2, 3, 4 both rank lists are 1, 2, 3, 4. The ranks match exactly, the Pearson correlation of identical lists is one, and Spearman gives 1. The only change from the tied case is that 2, 2 became 2, 3. That single edit moves the coefficient from 0.948683 to 1. The comparison isolates the effect of the tie: the order of the data is the same in both runs, but the tied pair cannot separate into distinct ranks, so the lists no longer match exactly.
Ties in both lists
Ties do not always lower the coefficient. If both lists tie in the same places, the ranks agree again. For x = 1, 2, 2, 4 and y = 1, 2, 2, 4 the rank lists are identical, and the coefficient is 1. When the ties fall in different places, the result drops. For x = 1, 1, 3, 4 and y = 1, 2, 3, 3, the x ranks are 1.5, 1.5, 3, 4 and the y ranks are 1, 2, 3.5, 3.5. The correlation of those ranks is 4 / 4.5, about 0.8889. A decreasing pattern works the same way: x = 4, 2, 2, 1 against y = 1, 2, 3, 4 gives about -0.948683.
The shortcut formula and its limit
A well-known formula gives rho = 1 - 6 × sum(d²) / (n × (n² - 1)), where d is the difference between paired ranks. It is exact only when there are no ties. For the tied example, the rank differences are 0, 0.5, -0.5 and 0, so the sum of d² is 0.5, and the formula gives 1 - 6 × 0.5 / (4 × 15) = 1 - 3/60 = 0.95. The correct coefficient with average ranks is 0.948683. The shortcut is close here, but it is an approximation under ties, and the tool uses the full rank-correlation computation. A mismatch in the third decimal is a sign that ties are present.
Keeping tied observations
It can be tempting to delete a row or to nudge a value so that the coefficient reaches one. Neither is justified by the arithmetic. The duplicate x value is part of the paired data, and removing it changes the question. If the x values were measured with coarse resolution, ties are expected, and the coefficient below one reflects the loss of information in the coarse scale. Keep the rows, report that ties were present, and note how many. The reader can then judge how far the result is held back by the tie.
What a rank correlation says
Spearman correlation summarizes how well the order of one list matches the order of the other. It is unchanged by any strictly increasing transformation of either list, so squaring positive values or taking logs gives the same coefficient. It does not measure how much y changes per unit of x, and it does not describe the shape of the relation beyond its direction. A value near one means the orders agree closely, not that one variable causes the other. The tie convention affects the number, so state it when reporting results.
Using the example as a test
The tied example is a handy check for your own implementation. A routine that assigns ranks 1, 2, 3, 4 to the tied list by breaking ties in order of appearance will get a different answer, because the pair 2, 3 against 2, 3 correlates perfectly. Computing the tied case by hand gives 0.948683, and a spreadsheet function that offers average ranking should match. If the numbers differ, check the ranking method first. The test lists are short, so the whole calculation fits on a line of paper, which makes it easy to debug. Run the tie-free list as a second test: it must return exactly 1, and any value like 0.9999 points to a ranking or rounding problem. The reversed list 4, 2, 2, 1 against 1, 2, 3, 4 gives about -0.948683, the mirror image of the first result, which checks the sign handling as well.
Pearson on the raw values for comparison
The Pearson correlation of the raw values 1, 2, 2, 4 and 1, 2, 3, 4 is a different number from the Spearman result, because it uses distances between values and not only their order. The raw means are 2.25 and 2.5, and the correlation comes out near 0.9234 for this pair, lower than the rank-based 0.9487. The two coefficients answer different questions. Pearson reflects how close the points lie to a straight line, while Spearman reflects how close the orderings are to each other. For monotone but curved data, such as y equal to x squared on positive x, Spearman is 1 and Pearson is below 1.
Reproduce the checks
One tied list
Open the Spearman Correlation Calculator and enter:
- X observations
1,2,2,4- Y observations
1,2,3,4
Expected output:
Rho
0.9486832980505138Average ranks retain both tied observations.
No tied ranks
Open the Spearman Correlation Calculator and enter:
- X observations
1,2,3,4- Y observations
1,2,3,4
Expected output:
Rho
1Both rank lists now match.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08