Friedman test

Intermediate

What you need first. Nothing else on this path comes first. This page is part of Statistical inference.

In statistical inference, the Friedman test is a rank test of whether treatments differ when each treatment is observed once inside each block. It ranks the treatments inside each block and asks whether the rank totals could have arisen if, within every block, every ordering were equally likely. The usual reference distribution is chi-squared. For a small table the exact probability is the proportion of within-block permutations that produce a statistic at least as large, and that proportion need not equal the chi-squared tail.

Friedman test

Friedman test
Fact Value
Topic Statistical inference
Listed on Statistical inference

Motivating example

Six judges score three products. The scores are a convenience; only the order inside each judge is used. Five judges put the products in the same order. The fifth does not. An additive block analysis of these six judges and three products uses the interaction mean square as its error, on (6−1)(3−1)=10(6-1)(3-1) = 10 degrees of freedom, and it assumes normal errors and additivity. Ranking within judges uses only the within-block orderings. On these six judges the statistic is 77, the exact probability under random ranking is 25/86425/864, and the chi-squared approximation on 22 degrees of freedom is 0.03020.0302. Both reject at 5%5\%. Changing the sixth judge’s order drops the statistic to 44 and the chi-squared test no longer rejects.

Ranks within blocks

Arrange the observations as XijX_{ij}, with blocks i=1,…,bi = 1, \ldots, b and treatments j=1,…,kj = 1, \ldots, k, and with one observation in each cell. Inside block ii, replace the kk values by their ranks R(Xij)R(X_{ij}), using rank 11 for the smallest. Tied values inside a block share the average of the ranks they occupy. The treatment rank total is Rj=∑i=1bR(Xij).R_j = \sum_{i=1}^{b} R(X_{ij}). If every ordering inside a block is equally likely and the blocks are independent, each RjR_j estimates the same mean rank b(k+1)/2b(k+1)/2. The Friedman statistic without ties is T1=12bk(k+1)∑j=1k(Rj−b(k+1)2)2=12bk(k+1)∑j=1kRj2−3b(k+1).T_1 = \frac{12}{bk(k+1)} \sum_{j=1}^{k} \Bigl(R_j - \frac{b(k+1)}{2}\Bigr)^2 = \frac{12}{bk(k+1)} \sum_{j=1}^{k} R_j^2 - 3b(k+1). The second form uses only the rank totals. Large T1T_1 is evidence that the treatments do not have the same effect inside the blocks. Friedman writes nn for the number of rows, which are the blocks, and pp for the number of columns, which are the treatments. Those are bb and kk here, and his integer formula in the column rank totals is T1T_1.[1] [2]

When ties occur, the null variance of the ranks is no longer that of a random permutation of 1,…,k1, \ldots, k. The untied statistic divides ∑j(Rj−b(k+1)/2)2\sum_j \bigl(R_j - b(k+1)/2\bigr)^2 by bk(k+1)/12bk(k+1)/12. The tie-corrected statistic replaces that denominator by (A1−C1)/(k−1)(A_1 - C_1)/(k-1), T1=∑j=1k(Rj−b(k+1)/2)2(A1−C1)/(k−1),T_1 = \frac{\sum_{j=1}^{k} \bigl(R_j - b(k+1)/2\bigr)^2}{(A_1 - C_1)/(k-1)}, where A1A_1 is the sum of the squares of every within-block rank and C1=bk(k+1)2/4C_1 = bk(k+1)^2/4. With no ties, A1−C1=bk(k+1)(k−1)/12A_1 - C_1 = bk(k+1)(k-1)/12, so (A1−C1)/(k−1)(A_1 - C_1)/(k-1) returns to bk(k+1)/12bk(k+1)/12 and the two formulae agree.[2]

Friedman showed that if the number of rows and the number of columns are not too small, T1T_1 is approximately chi-squared on k−1k-1 degrees of freedom when the ranking is random. A second function of the same rank totals, T2=(b−1) T1b(k−1)−T1,T_2 = \frac{(b-1)\, T_1}{b(k-1) - T_1}, is the two-way analysis-of-variance FF statistic computed on the ranks, and it is referred to FF on (k−1, (b−1)(k−1))(k-1,\, (b-1)(k-1)) degrees of freedom. The chi-squared approximation to T1T_1 can be poor, and the T2T_2 approximation is typically preferred.[2] The two statistics are monotone functions of each other, so they order samples in the same way. They do not have the same pp-value. So long as the number of rows and the number of columns are not too small, Friedman’s χr2\chi_r^2, which is T1T_1, tends to a chi-squared law on p−1p-1 degrees of freedom.[1]

Two treatments, ties, and the exact permutation count

With two treatments, Friedman’s ranking was already identified with the binomial sign count in 1945, and the Friedman test is equivalent to the sign test.[3] [2] For k=2k = 2 there are no ties only if, in every block, one treatment is strictly above the other. Let SS be the number of blocks in which treatment 11 receives rank 22. Then R1=b+SR_1 = b + S and R2=3b−R1R_2 = 3b - R_1, because each block contributes ranks adding to 33 and there are bb blocks. The null mean of each rank total is 3b/23b/2. Substitution into the untied formula gives T1=4b(S−b2)2.T_1 = \frac{4}{b}\Bigl(S - \frac{b}{2}\Bigr)^2. The sign test on the same bb blocks has null mean b/2b/2 and null variance b/4b/4 for the count SS. The square of its standardised value is 4(S−b/2)2/b4(S - b/2)^2/b, the same number as T1T_1. So, with no ties, the Friedman statistic is exactly the squared normal approximation to the sign test, not a new ranking. The signed-rank test is the different procedure that would also use the sizes of the within-block differences.

The exact null for an untied table does not need the chi-squared curve. The blocks are mutually independent: the results in one block do not affect the results in the others.[2] If in addition there is no treatment difference, the k!k! orderings inside a block are equally likely, and there are (k!)b(k!)^b rank tables. The exact pp-value is the proportion of those tables whose T1T_1 is at least as large as observed. For k=3k = 3 and b=6b = 6 that collection has 66=466566^6 = 46656 tables, small enough to count. The chi-squared probability is the approximation to this count. Which of the two is being reported should be said explicitly. friedman.test reports the chi-squared form.[4]

The additive analysis of one observation per cell fits a block effect and a treatment effect and uses the interaction mean square as the error. That residual has (b−1)(k−1)(b-1)(k-1) degrees of freedom, 1010 for six blocks and three treatments, which is the denominator degrees of freedom of T2T_2. The FF comparison assumes normal errors and additivity, because the interaction mean square is being used as the error variance. Friedman’s procedure does not form that residual. It ranks within blocks, and the null is that every ordering inside a block is equally likely.[1] The Friedman test is a nonparametric test for a randomized complete block design.[2]

Blocks, the statistic to quote, and the R function

The design is a complete block design with one observation on each treatment in each block: judges, patients, or batches, with every treatment appearing once inside each. Blocks are there so that a systematic difference between judges is removed before the treatments are compared. Ranking within the block is what removes it.[5]

Quote T1T_1 together with its reference. For a table as small as six blocks and three treatments, the exact permutation probability 25/86425/864 and the chi-squared probability 0.03020.0302 can both be given; if only one is given, it has to be the one that was computed. friedman.test accepts a data matrix, or a formula of the form y ~ treatment | block. The value it returns is Friedman’s chi-squared statistic, together with the degrees of freedom of the approximate chi-squared distribution.[4]

The data only need to be rankable. A judge who can order three products but cannot score them has already supplied the ranks the test uses. A procedure that used the numerical gaps inside a judge would be assuming more than an order.[2] [1]

Six judges and three products

The scores, with products AA, BB and CC in that order, are (5,8,6),  (4,7,5),  (6,9,7),(3,6,4),  (7,5,8),  (4,8,6).\begin{align*} &(5, 8, 6),\; (4, 7, 5),\; (6, 9, 7),\\ &(3, 6, 4),\; (7, 5, 8),\; (4, 8, 6). \end{align*} Higher is better. Ranking within each judge, the smallest score in the row receiving rank 11, gives the ranks (1,3,2),  (1,3,2),  (1,3,2),(1,3,2),  (2,1,3),  (1,3,2).\begin{align*} &(1, 3, 2),\; (1, 3, 2),\; (1, 3, 2),\\ &(1, 3, 2),\; (2, 1, 3),\; (1, 3, 2). \end{align*} No row contains a tie. The rank totals are RA=7R_A = 7, RB=16R_B = 16 and RC=13R_C = 13. They add to 6×(1+2+3)=366 \times (1+2+3) = 36, as they must. The null mean of each total is 6×4/2=126 \times 4/2 = 12. Then T1=16[(7−12)2+(16−12)2+(13−12)2]=25+16+16=7.T_1 = \frac{1}{6}\bigl[(7-12)^2 + (16-12)^2 + (13-12)^2\bigr] = \frac{25+16+1}{6} = 7. The integer form gives the same value: 12/(6⋅3⋅4)×(72+162+132)−3⋅6⋅4=474/6−72=712/(6 \cdot 3 \cdot 4) \times (7^2+16^2+13^2) - 3 \cdot 6 \cdot 4 = 474/6 - 72 = 7.

The chi-squared approximation on k−1=2k-1 = 2 degrees of freedom assigns probability 0.03020.0302 to the region T1≥7T_1 \ge 7. The upper 5%5\% point of that chi-squared law is 5.9915.991, so the approximate test rejects. The exact count is available here because 66=466566^6 = 46656 is finite. Of those tables, 13501350 have a statistic of 77 or more, and 1350/46656=25/864≈0.02891350/46656 = 25/864 \approx 0.0289. The approximation and the exact probability are close, and they agree on rejection at 5%5\%. They are not the same number. The FF form is T2=(6−1)⋅7/(6⋅2−7)=7T_2 = (6-1) \cdot 7 / (6 \cdot 2 - 7) = 7 on (2,10)(2, 10) degrees of freedom, with upper-tail probability 0.01260.0126. Reporting “p=0.030p = 0.030” without saying which reference produced it mixes T1T_1 with T2T_2. friedman.test returns Friedman’s chi-squared equal to 77 on 22 degrees of freedom, the T1T_1 probability 0.03020.0302.[4] [2]

The assumptions used for the exact count are that the six judges are independent and that, if the products were equivalent, each judge’s three ranks would be a random permutation. The scores are only the device that produced the ranks. Any strictly increasing transformation of a judge’s three scores would have left that judge’s ranks, and therefore T1T_1, unchanged.

Change the sixth judge’s scores from (4,8,6)(4, 8, 6) to (5,4,6)(5, 4, 6). That row’s ranks change from (1,3,2)(1, 3, 2) to (2,1,3)(2, 1, 3). The rank totals become 88, 1414 and 1414, and T1=(−4)2+22+226=246=4.T_1 = \frac{(-4)^2 + 2^2 + 2^2}{6} = \frac{24}{6} = 4. Now 4<5.9914 < 5.991, so the chi-squared test at 5%5\% does not reject. One judge’s order was enough to move the statistic across the approximate critical value. The exact probability for T1≥4T_1 \ge 4 is a larger fraction of the 4665646656 tables than 25/86425/864; the point of the change is the statistic a reader can recompute by hand, which falls from 77 to 44.

If the global test rejects, the rank totals can be compared in pairs. Treatments ii and jj are declared different when ∣Rj−Ri∣>t1−α/2, (b−1)(k−1)2(bA1−∑jRj2)(b−1)(k−1),|R_j - R_i| > t_{1-\alpha/2,\, (b-1)(k-1)} \sqrt{\frac{2\bigl(b A_1 - \sum_j R_j^2\bigr)}{(b-1)(k-1)}}, with A1A_1 the sum of all squared within-block ranks. Here there are no ties, so A1=6(1+4+9)=84A_1 = 6(1+4+9) = 84, and bA1−∑Rj2=504−474=30b A_1 - \sum R_j^2 = 504 - 474 = 30. The 0.9750.975 quantile of tt on 1010 degrees of freedom is 2.2282.228, and the threshold is 2.228×6≈5.462.228 \times \sqrt{6} \approx 5.46. The absolute gaps are ∣16−7∣=9|16-7| = 9, ∣13−7∣=6|13-7| = 6 and ∣16−13∣=3|16-13| = 3. At α=0.05\alpha = 0.05 this rule separates AA from BB and AA from CC, and it does not separate BB from CC. The rule is a follow-up to a rejected global test, not a set of three fresh 5%5\% tests with a guaranteed family-wise error.[2]

Your turn. Four blocks and three treatments have rank totals 55, 88 and 1111. Compute T1T_1, and say whether the chi-squared 5%5\% test on 22 degrees of freedom rejects. The critical value is 5.9915.991.

The null mean of each total is 4×2=84 \times 2 = 8. The deviations are −3-3, 00 and 33, and the sum of squares is 9+0+9=189+0+9 = 18. Then T1=12/(4⋅3⋅4)×18=4.5T_1 = 12/(4 \cdot 3 \cdot 4) \times 18 = 4.5. Since 4.5<5.9914.5 < 5.991, the approximate 5%5\% test does not reject.

What the chi-squared tail is approximating

The exact 25/86425/864 uses independent blocks and, inside each block, a uniform random ordering under the null. If the judges confer, or if several judges score the same session, the 4665646656 tables are no longer equally likely and the count is not the null probability. The chi-squared statement has a further limit of its own: it is an approximation for tables that are not too small, and Friedman’s derivation presents it as a tendency of the statistic, not as an identity. On this example the approximation is off by about 0.00130.0013 in the tail probability. That is small beside 0.050.05. It is large enough that “the pp-value is 0.03020.0302” should not be rewritten as “exactly 13501350 of the 4665646656 tables”.[1]

The pairwise threshold above is a further approximation, a tt quantile times an estimated standard error of a difference of rank totals. It is not the exact permutation test of that pair. Separating AA from BB at a gap of 99, against a threshold of 5.465.46, is stable to a small change in the quantile. A gap sitting on the threshold would not be.

Blocks, the sign test, and ranks without blocks

Blocks in analysis of variance are the groups inside which the treatments are ranked. Two-factor analysis of variance is the normal-theory analysis of the same rectangular table. With one observation per cell the additive form uses the interaction mean square as its error, on (b−1)(k−1)(b-1)(k-1) degrees of freedom, and it assumes normal errors and additivity. Friedman uses only the within-block orderings. Repeated measures are the case in which the block is a person and the treatments are occasions or conditions on that person. The sign test is the Friedman statistic when k=2k = 2 and there are no ties. The Kruskal–Wallis test is the rank comparison for samples that are not arranged in blocks.

Check yourself

1. Every judge assigns ranks (1,3,2)(1, 3, 2) to products AA, BB and CC. There are six judges. What are the rank totals and T1T_1?

The totals are 66, 1818 and 1212. They deviate from 1212 by −6-6, 66 and 00. The sum of squares is 36+36+0=7236+36+0 = 72, and T1=72/6=12T_1 = 72/6 = 12.

2. Two treatments are compared in six blocks, and treatment 11 is ranked higher in every block. What is T1T_1?

Here b=6b = 6 and S=6S = 6, so T1=4(6−3)2/6=6T_1 = 4(6 - 3)^2/6 = 6. The sign count is six positives out of six, and the square of its standardised null value is the same 66.

3. Inside one block the two better products tie, and the third is strictly worse. Which ranks are assigned?

The worst product receives rank 11. The two tied products share the average of ranks 22 and 33, which is 2.52.5. The within-block ranks are 11, 2.52.5 and 2.52.5, in the appropriate order.

Ranks instead of a normal residual, 1937

Milton Friedman set out the method of ranks in 1937 for tables with two or more criteria of classification, precisely so that the analysis would not inherit the normality assumption of the analysis of variance. Each row is ranked, and a statistic χr2\chi_r^2 is formed from the column mean ranks. When the rows and columns are not too few, that statistic is referred to the chi-squared distribution on one fewer degrees of freedom than the number of columns. The integer formula in the rank totals is the expression used in the worked example. In that formula nn is the number of rows and pp is the number of columns, which are bb and kk on this page. The paper’s point is the null: if the column factor has no effect, the ranks in a row are a random ranking, and no distribution is assumed for the original measurements.[1]

The same reduction, for two columns, is the sign test.[3] The FF form on the ranks, the tie correction, and the pairwise comparison of rank totals are the later computational account of the same ranking.[2]

See also

Line chart · Apriori algorithm · Asymptotic analysis · Average treatment effect · Base rate · Bayesian inference · Bayesian model · Bayesian probability

Glossary and index

References

  1. ^ a b c d e f a. (pp. 676, 678–679) b. (pp. 678–679) c. (p. 675) d. (p. 675) e. (pp. 676, 679) f. (pp. 675–676, 678–679) Friedman, Milton (1937). The Use of Ranks to Avoid the Assumption of Normality Implicit in the Analysis of Variance. Journal of the American Statistical Association, 32(200), 675-701. https://doi.org/10.1080/01621459.1937.10503522
  2. ^ a b c d e f g h i j a. (the rank totals and T1T_1) b. (the tie correction) c. (T2T_2 and the two critical regions) d. (k=2k = 2) e. (assumptions) f. (Description) g. (assumptions) h. (T1T_1 and T2T_2) i. (multiple comparisons) j. (ties, T2T_2, and k=2k = 2) NIST (2023). NIST Dataplot: Friedman Test. National Institute of Standards and Technology. https://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/friedman.htm
  3. ^ a b a. (pp. 80–81) b. (pp. 80–81) Wilcoxon, F. (1945). Individual Comparisons by Ranking Methods. Biometrics Bulletin, 1(6), 80–83. https://doi.org/10.2307/3001968
  4. ^ a b c a. (Value) b. (Usage, Arguments and Value) c. (Value) R Core Team (2026). Friedman Rank Sum Test (R-devel documentation for friedman.test). R Foundation for Statistical Computing. https://stat.ethz.ch/R-manual/R-devel/library/stats/html/friedman.test.html
  5. ^ (p. 447) Dodge, Yadolah (2008). The Concise Encyclopedia of Statistics. Springer. https://doi.org/10.1007/978-0-387-32833-1
Cite this page
Plain text
StatWiki (2026). "Friedman test." StatWiki. Last updated 2 December 2026. https://www.statwiki.io/articles/friedman-test.html
BibTeX
@misc{statwiki_friedman_test,
  author = {{StatWiki}},
  title = {{Friedman test}},
  year = {2026},
  url = {https://www.statwiki.io/articles/friedman-test.html},
  urldate = {2026-12-02},
  note = {StatWiki, last updated 2 December 2026}
}