The guide
Kendall's tau counts which pairs agree, and ties change what the count means
Tau compares every pair of items by order alone, and a p-value for it comes from counting orderings, as long as you decide honestly what to do with ties.
- 40 and 5 concordant and discordant pairs of ten items with five neighbour swaps
- 1717/1814400 exact two-sided p for those five swaps, about 0.00094632
- 0.819337 tau-b for the tied example, against tau-a of 0.755556
- 0.002358 p if the tie correction were left out, against the right 0.001717
Read the full guide Fold the guide
Two judges rank ten dishes. They mostly agree, but not entirely, and you want one number for how much. Kendall’s tau answers with a count rather than a formula for distances: take every pair of dishes and ask whether the two judges put them in the same order. There is no averaging of scores and no assumption about how the scores are spread, which is why the method suits ratings, ranks and any measurement where only the order can be trusted.
What a pair says
Choose two items, say dish 3 and dish 7. If the first judge prefers 3 and the second judge also prefers 3, the pair is concordant. If they disagree, it is discordant. With ten items there are 45 such pairs, and each one is either concordant, discordant or tied.
Tau is the surplus. Subtract the discordant pairs from the concordant ones and divide by the number of pairs. If nothing is tied, the result runs from minus one for exactly opposite orders to plus one for identical orders.
Notice what is missing. A pair says which item is bigger, never by how much. Swap a 5 for a 5000 in the second list and, as long as the order survives, no pair changes its verdict. The same property makes tau steady when a few values are wild, since a wild value can only change the pairs it belongs to, and each item belongs to just n minus 1 of them.
Distances do not count
That blindness is the point. Take six items where the second list reads 1, 2, 3, 4, 5, 1000. All fifteen pairs agree, so tau is exactly 1. The tool has this as the “same order, one huge gap” example.
Spearman’s rho is also built on ranks: it is the Pearson correlation of the rank values, which is why one huge outlier gets limited to its rank. Kendall’s tau and Spearman’s rho are both special cases of one general correlation coefficient, as Kendall showed in 1970.
Use tau when you want the count to be easy to read, or when your data are ordinal and distances between categories mean nothing. A tau of 0.78 on ten items says that in 40 of 45 pairs the lists agree and in 5 they do not, which is something you can check by hand.
Counting orderings for an exact p
Suppose the two lists were unrelated. Then the order of the second list, once the first is sorted, is a random permutation of the items. The number of discordant pairs is the number of inversions of that permutation, a link the Kendall page states directly and the inversion page describes as the number of crossings in the permutation’s arrow diagram.
That turns a p-value into a counting problem. How many of the n! orderings have at most the number of inversions you observed? Those counts are the Mahonian numbers. For four items they are 1, 3, 5, 6, 5, 3, 1, which add up to 24. Each row comes from the previous one by adding the next item, which can create anywhere from zero to k-1 new inversions, so the row for k items is the row for k-1 items spread out by k overlapping copies of itself. The encyclopedia entry gives the same triangle as the coefficients of a product of short polynomials.
Here is a worked case you can reproduce. Ten items, the second list 2, 1, 4, 3, 6, 5, 8, 7, 10, 9: five neighbour swaps, so 5 discordant pairs and 40 concordant ones. Tau-a is 35/45, which reduces to 7/9, or 0.777778.
Of the 3,628,800 orderings of ten items, only 1 + 9 + 44 + 155 + 440 + 1068 = 1717 have five inversions or fewer. Doubling for a two-sided test gives 1717/1814400, about 0.00094632. No approximation is involved, and the answer is a fraction you can check.
The numbers get large quickly. Twenty items have 2,432,902,008,176,640,000 orderings, far beyond the largest whole number an ordinary floating-point value holds exactly, so the page builds the rows with BigInt, the built-in type for whole numbers of any size. That is also why the exact method stops at 20 pairs here: it is a limit this page chose, not one the mathematics imposes.
Ties, and why tau-a misleads
Real data tie. Two dishes both get a score of 4, or two judges rate on a five-point scale. A tied pair is neither concordant nor discordant, so concordant plus discordant falls short of all pairs.
Dividing the surplus by all pairs, as tau-a does, then caps the answer below 1 even when every orderable pair agrees. Tau-a, Kendall’s original coefficient, is therefore a poor summary once ties appear. Tau-b divides instead by the square root of the product of the pairs that are not tied in the first list and the pairs that are not tied in the second.
The example the tool opens with has X as 1, 2, 2, 3, 4, 4, 4, 5, 6, 7 and Y as 1, 3, 2, 2, 4, 6, 5, 5, 7, 7. Of the 45 pairs, 36 are concordant, 2 are discordant and 7 are tied somewhere. The first list has 4 tied pairs and the second has 3. Tau-a is 34/45, or 0.755556, and tau-b is 34 over the square root of 41 times 42, or 0.819337.
Which is right? Neither is wrong, but they answer different questions. Tau-a asks about all pairs; tau-b asks about the pairs that could be ordered. When someone quotes a single tau with no label, ask which. The fair habit is to report the counts as well: how many pairs agreed, how many disagreed and how many were tied, so a reader can rebuild either coefficient.
The variance is where shortcuts hide
For larger samples, and whenever there are ties, the p-value comes from a normal curve. The statistic is the surplus itself divided by the square root of its variance under independence. With no ties that variance is n(n-1)(2n+5) over 18, which is 125 for ten items.
With ties the variance shrinks, and extra terms appear that depend on how the ties are grouped. In the tied example it is 117.6 rather than 125. The surplus is 34, so z is 3.1353 and the two-sided p is 0.001717. Leave the correction out and the same surplus gives 0.002358, more than a third larger, a difference that can decide whether a result clears a threshold. This is the mistake the page is built to avoid: the tied example shows both values side by side, and labels the corrected one as the one it uses.
The normal tail itself needs the complementary error function, defined as an integral of a bell-shaped curve. The page computes it from a series for small arguments and a continued fraction for large ones, and checks it against a reference implementation.
SciPy’s manual draws the same line: its exact method can only be used if no ties are present, and its default chooses a method for you. The page follows the same boundary, then tells you in words which method it used.
What this tool does not do
It does not give confidence intervals for tau, partial correlations or Spearman’s rho. It stops at 500 pairs, because a person pasting thousands of values is better served by a statistics package, and it shows every pair only for 20 or fewer.
It also cannot say why two lists agree, and with a handful of pairs even a perfect match is weak evidence: five pairs in exactly the same order still give a two-sided p of 1/60. A tau near one means that the orders match; it says nothing about cause, about whether a third variable drives both, or about whether the ordering would hold in another sample.
Counting every pair takes a fraction of a millisecond at 500 pairs, but the page still runs its work in a background worker, the browser feature for running a script on a separate thread so that the page stays responsive. Your numbers stay on your device, and every figure on the page can be recomputed from the counts it shows.
If a result looks surprising, open the pair table. Each row names two items and says concordant, discordant or tied. Add them up and you have the whole calculation, with nothing left to trust.
Sources
Every source consulted for this guide. Links checked November 10, 2026.
- Kendall rank correlation coefficient Wikipedia
- Kendall tau distance Wikipedia
- Inversion (discrete mathematics) Wikipedia
- Spearman's rank correlation coefficient Wikipedia
- Rank correlation Wikipedia
- A008302 Triangle of Mahonian numbers T(n,k) On-Line Encyclopedia of Integer Sequences
- scipy.stats.kendalltau SciPy manual
- BigInt MDN Web Docs
- Web Workers API MDN Web Docs
- Definitions (DLMF 7.2) NIST Digital Library of Mathematical Functions