Friedman Test Calculator

Within-subject ranks, exact p-values and Kendall's W.

  • Exact p-value
  • Ties corrected
  • Kendall's W
A small rounded clay table with three soft clay columns of different heights standing in several rows, joined by soft clay arches, and a few loose rounded beads.

The guide

The Friedman test ranks inside each subject, and ties change the answer

Ranking within each row strips out the differences between subjects, and counting every arrangement of those ranks gives an exact p-value where the chi-square rule is shaky.

  • 10.1379 tie-corrected Q for the eight-subject table, against 9.1875 without
  • 0.0034 exact p for that table, against 0.0063 from the chi-square curve
  • 209,952 arrangements of the observed ranks counted for the exact p
  • 0.6336 Kendall's W for the same table
Read the full guide Fold the guide 7 min · 13 sources

Eight people each try three versions of a task, and every version gets a score. Some people score high on everything and some score low on everything. That spread between people is noise for your question, which is whether the versions differ. A test that ranks inside each person’s row throws that noise away before it starts. The Friedman test does exactly this. It is a non-parametric test named for Milton Friedman, and it is the rank-based relative of the repeated measures analysis of variance.

What the test asks

A repeated measures analysis of variance works on the scores themselves and leans on assumptions about how they are distributed. Friedman’s 1937 paper had a title that said as much: it proposed using ranks to avoid the assumption of normality that the analysis of variance carries with it. The test keeps the design, in which every subject is measured under every condition, and replaces the scores by their order.

Think of wine judges. Several judges each rate the same wines, and the question is whether any wine is ranked consistently higher or lower than the others. Each judge is a row, called a block, and each wine is a column. Only the order inside a block matters. The size of the gaps does not.

Ranks and ties

Take the table the page opens with. Eight subjects are measured under conditions A, B and C: 7 9 8, then 6 6 9, then 5 8 7, then 8 10 10, then 4 7 6, then 9 9 12, then 6 8 7, then 5 7 9. Rank each row from 1 to 3. In the first row A has the lowest score and takes rank 1, C takes rank 2, and B takes rank 3.

When two values tie, they share the mean of the ranks they span. In the second row the two sixes would take ranks 1 and 2 between them, so each gets 1.5, and the nine gets rank 3. Add up each column and the rank sums are 9 for condition A and 19.5 for each of B and C.

Every row hands out 1 + 2 + 3 = 6 points, so eight rows hand out 48. If the conditions made no difference, each column would hold about 16. Condition A holds 9, well below that. The statistic Q measures how far the rank sums sit from that even split. In one common form it is 12 divided by n k (k + 1), times the sum of the squared rank sums, minus 3 n (k + 1), where n is the number of rows and k the number of columns. Here that is 147/16, which is 9.1875. Q is 0 when every column has the same rank sum, and it grows as one condition keeps winning.

That form assumes no ties. The Wikipedia page notes that Q needs adjusting when values tie, and the NIST Dataplot reference gives a version for ties. The corrected statistic can be written as Q divided by a factor C, where C is 1 minus the sum of (t cubed minus t) over every group of equal values inside a row, divided by n k (k squared minus 1). Here t is the size of each group.

In the example, three rows each hold one pair of equal values, and each pair adds 2 cubed minus 2, which is 6. The sum is 18. The factor C is 1 minus 18/192, which is 29/32, and the corrected Q is 147/16 divided by 29/32, which is 294/29, or 10.1379. Exact fractions, of the kind Python’s fractions module handles, give the same figures without rounding.

The correction is not cosmetic. The chi-square p-value for plain Q is 0.0101, while the corrected value gives 0.0063. A change of that size can move a result across a threshold you chose in advance.

Ranking the whole table at once is the other common slip, and it is far worse. If all 24 scores are ranked together instead of row by row, the same formula returns 3952.1875, a number with no meaning for these data, because the ranks no longer add up to 6 in each row.

Counting every arrangement

The chi-square figure is an approximation. An exact answer comes from asking how many ways the observed ranks could have fallen if the conditions made no difference. Inside a row the ranks can sit in the columns in any order, and under that assumption each arrangement is equally likely, which is the logic of a permutation test.

Row 1 has 6 arrangements. Row 2 has 3, because the ranks 1.5, 1.5 and 3 can be laid out in only three distinct ways. Across the eight rows that gives 6 x 3 x 6 x 3 x 6 x 3 x 6 x 6, or 209,952 arrangements of the observed ranks.

Now count how many spread the rank sums apart at least as far as yours do. Your sum of squared rank sums is 9 squared plus 19.5 squared plus 19.5 squared, which is 841.5. The count is 720 arrangements, and 720 / 209,952 is 0.0034. That is the exact p-value, conditional on the tie pattern your rows actually have. It is about half the chi-square value of 0.0063.

Nobody lists 209,952 tables by hand, and the numbers grow fast. The count is built row by row, keeping for each set of column sums the number of ways to reach it. Those counts outgrow ordinary floating-point numbers quickly, so they are held as BigInt whole numbers. The work runs in a background thread, as the Web Workers interface allows, so the page stays responsive while it counts.

When the table is too large for that, a random sample can stand in. A permutation test can draw random arrangements instead of listing them all, and many implementations count the observed table as one of the arrangements, so the p-value is never exactly zero. The result is an estimate with sampling error, and it should be labelled as one.

How far to trust the chi-square curve

The chi-square distribution arises when independent standard normal values are squared and summed. For the Friedman statistic it is used with k - 1 degrees of freedom, and the tail beyond Q is a regularised incomplete gamma function, which is defined in the NIST Digital Library of Mathematical Functions. Computed directly, it agrees with 80-digit decimal arithmetic to about 15 digits.

The curve is a limit, though, and small tables are far from it. The Wikipedia page says the approximation is used when n or k is large, meaning more than 15 rows or more than 4 columns, and that for small tables it is poor and specially prepared tables should be used instead. SciPy’s manual is stricter: it calls the p-value reliable only for more than 10 rows and more than 6 repeated samples.

Two careful sources disagree on the rule, yet both put the eight-row example on the unsafe side, and that is what 0.0063 against 0.0034 shows. Research on a related problem points the same way. Eisinga and colleagues, studying pairwise comparisons of Friedman rank sums, report that large-sample approximations are inaccurate in the tail, which is the part that matters for p-values, and that the chi-squared approximation does worse than exact computation overall.

What W says, and what the test leaves out

Kendall’s W is the Friedman statistic rescaled to run from 0 to 1. A W of 0 means the rows show no overall trend toward agreement, and a W of 1 means every row ranks the conditions in the same order. For the example, W is Q_c / (n (k - 1)), which is 10.1379 / 16, or 0.6336. The Wikipedia page on W gives a rank-sum form that handles ties, and the algebra shows it is the same number.

W has a plain reading too. For rows without ties, the average Spearman correlation between every pair of rows equals (n W - 1) / (n - 1). Take six subjects with no ties and a W of 0.6944. The average agreement between two subjects’ rankings is then 19/30, or 0.6333.

Two columns turn the test into something familiar. With only two conditions, the Friedman test is the sign test with a two-sided alternative. Seven subjects, five of whom score higher under B than under A and two lower, give Q = 9/7, or 1.2857, which is the square of the sign-test z of 3 over the square root of 7. The exact two-column p-value is 58/128, or 0.4531.

What the test leaves out matters. It needs complete rows, so a missing cell means the whole subject must be set aside. It says that some condition differs, never which one, and picking out pairs takes a separate post-hoc procedure. It ignores how large the differences are in the original units, because ranks discard the gaps. And a small W can still come with a tiny p-value when there are many subjects: agreement can be weak and yet reliably present. For a small table, read the exact figure. For a large one, the chi-square figure is fair, and whichever you quote, say which one it was.

Sources

Every source consulted for this guide. Links checked November 11, 2026.

  1. Friedman test Wikipedia
  2. Kendall's W Wikipedia
  3. Sign test Wikipedia
  4. Permutation test Wikipedia
  5. Chi-squared distribution Wikipedia
  6. FRIEDMAN TEST NIST Dataplot Reference Manual
  7. 1.3.6.6.6. Chi-Square Distribution NIST/SEMATECH e-Handbook of Statistical Methods
  8. Definitions and Basic Properties (DLMF 8.2) NIST Digital Library of Mathematical Functions
  9. scipy.stats.friedmanchisquare SciPy manual
  10. Exact p-values for pairwise comparison of Friedman rank sums, with application to comparing classifiers BMC Bioinformatics, Eisinga, Heskes, Pelzer and Te Grotenhuis
  11. fractions - Rational numbers Python Software Foundation
  12. BigInt MDN Web Docs
  13. Web Workers API MDN Web Docs