Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
The Friedman test is the rank-based test for whether three or more related conditions differ, and the usual post-hoc procedures after a significant result are the Nemenyi test (all pairs), the Bonferroni-Dunn test (each condition against one control) and pairwise Wilcoxon signed-rank tests with a Bonferroni correction. A significant Friedman test says at least one condition differs; only a post-hoc procedure says which.
That follow-up question is where most write-ups of this test stop short: they explain the test statistic and leave the reader to guess at a post-hoc procedure, or worse, run pairwise comparisons with no correction at all. This guide covers when the test is the right tool, how to calculate it by hand with a worked example, how ties and small samples change the calculation, three post-hoc routes, Kendall’s W, reporting, and the R and Python calls. The data table after the body lists critical values for k = 2 to 10 conditions.
What the Friedman test actually does
The Friedman test (Friedman, 1937) is the nonparametric alternative to a one-way repeated-measures ANOVA. It applies to a within-subject design: the same set of subjects (or matched blocks) is measured under three or more related conditions, and you want to know whether the conditions differ. Instead of working with the raw scores, the test ranks each subject’s scores across the conditions, separately for every subject, then checks whether the resulting rank sums for each condition differ more than chance alone would produce.
That within-subject ranking is the whole mechanism. If every condition were equivalent, each subject’s ranks would be randomly assigned among 1 through k, and every condition’s rank sum, averaged across subjects, would converge on the same value. The Friedman statistic measures how far the observed rank sums deviate from that null expectation.
When to reach for it instead of repeated-measures ANOVA
Use the Friedman test when your design is within-subject (each unit contributes a score to every condition) and at least one of the following holds:
- The dependent variable is ordinal rather than interval/ratio (e.g., a rating scale), so a mean is not a meaningful summary.
- The differences between conditions are not normally distributed, and your sample is too small for the central limit theorem to rescue a repeated-measures ANOVA.
- Mauchly’s test flags a sphericity violation severe enough that even a Greenhouse-Geisser or Huynh-Feldt correction feels like a patch on a model that was never appropriate for the data in the first place.
- The data contain outliers that would distort condition means but not condition ranks.
The trade-off is power. Demšar (2006) notes that the Friedman test is less powerful than repeated-measures ANOVA when the ANOVA assumptions are actually met, which is why the parametric test remains the default when its assumptions hold. Demšar also cites Friedman’s own 1940 comparison of the two methods on 56 problems, in which they mostly agreed.
Two boundary cases matter. With exactly two related conditions, don’t use Friedman: the Wilcoxon signed-rank test is the correct two-condition tool. And if your design compares independent groups rather than repeated measures on the same subjects, you want the Kruskal-Wallis test, Friedman’s between-subjects counterpart, not this one.
The test statistic, step by step
With N subjects and k related conditions, rank each subject’s k scores from 1 (lowest) to k (highest), tied scores sharing the average rank. Sum the ranks for each condition across all subjects to get Rj for condition j. The Friedman statistic, in its form for data without ties, is:
χ2F = [12 / (Nk(k+1))] × ΣRj2 − 3N(k+1)
Under the null hypothesis of no difference between conditions, χ2F approximately follows a chi-square distribution with k − 1 degrees of freedom. Demšar (2006) reports that Iman and Davenport (1980) showed this statistic to be undesirably conservative and derived a better one, distributed as F:
F = [(N − 1) × χ2F] / [N(k − 1) − χ2F], with df1 = k − 1, df2 = (k − 1)(N − 1)
Use whichever your software reports, but know the two can disagree at borderline p-values.
Worked example
Eight lab technicians each ran the same assay under three protocol versions (A, B, C), and completion time in minutes was recorded for each technician under each protocol: a within-subject design with N = 8 and k = 3. This is an illustrative dataset, not a reported study.
| Technician | Protocol A (min) | Protocol B (min) | Protocol C (min) | Ranks (A, B, C) |
|---|---|---|---|---|
| 1 | 42 | 38 | 45 | 2, 1, 3 |
| 2 | 37 | 34 | 39 | 2, 1, 3 |
| 3 | 50 | 48 | 53 | 2, 1, 3 |
| 4 | 29 | 31 | 33 | 1, 2, 3 |
| 5 | 44 | 40 | 46 | 2, 1, 3 |
| 6 | 35 | 33 | 38 | 2, 1, 3 |
| 7 | 41 | 44 | 47 | 1, 2, 3 |
| 8 | 33 | 30 | 36 | 2, 1, 3 |
| Rank sum Rj | 14 | 10 | 24 | — |
With N = 8, k = 3, and rank sums 14, 10, and 24: ΣRj2 = 142 + 102 + 242 = 872. Substituting into the formula above:
χ2F = [12 / (8 × 3 × 4)] × 872 − (3 × 8 × 4) = 109 − 96 = 13.0, df = 2
A chi-square distribution with 2 degrees of freedom has the closed-form survival function e−x/2, so the chi-square approximation gives p = e−13/2 ≈ 0.0015. The Iman-Davenport statistic gives F(2, 14) = (7 × 13) / (16 − 13) = 30.3. Both point the same way, and the Friedman test rejects the null of no difference among the three protocols. Because this design has N = 8 and k = 3, it is small enough that the exact tables described in the next section are the formally correct reference, and the chi-square p-value should be read as an approximation. Rejecting the omnibus null only says some protocol differs from some other protocol, not which pair.
Ties and small samples
Two practical details change what your software reports.
How ties are handled
Tied scores within one subject share the average of the ranks they would have occupied (two scores tied for ranks 1 and 2 each get 1.5). The no-ties formula above then no longer applies exactly. SciPy’s friedmanchisquare documentation states that the statistic is computed correcting for ties, so a result from software can differ slightly from a hand calculation with the plain formula when a subject has repeated values.
When the chi-square approximation is valid
Demšar (2006) states that the chi-square approximation of the Friedman statistic is valid when N and k are big enough, giving as a rule of thumb N > 10 and k > 5, and that for smaller numbers of subjects or conditions exact critical values should be used instead. The SciPy documentation gives a similar caution: the p-value is reliable only for more than 10 subjects and more than 6 repeated samples. For a small design such as the eight-technician example, report that the p-value is approximate, or take it from exact tables or an exact-test implementation.
Missing data
The test needs a complete block: every subject must have a score under every condition. In R’s friedman.test, blocks that contain a missing value are removed before the test is computed, so one missing score costs you that whole subject. If you expect missingness, count the complete blocks before you rely on the N in your power reasoning.
A significant result is the start, not the finish
Exactly as with a significant one-way ANOVA or a significant Kruskal-Wallis test, a significant Friedman χ2F is an omnibus result: it tells you the k conditions are not all equal somewhere, and nothing about where. Reporting a significant Friedman test alone, with no follow-up comparison, is incomplete, and running uncorrected pairwise tests instead inflates the family-wise Type I error rate: with k = 3 conditions there are k(k−1)/2 = 3 pairwise comparisons, and with k = 6 there are 15, each carrying its own chance of a false positive if left uncorrected. Three procedures handle this correctly, depending on which comparisons you need.
Post-hoc option 1: the Nemenyi test (all pairs)
The Nemenyi test (Nemenyi, 1963) is the standard all-pairs post-hoc for a significant Friedman result. It compares every pair of conditions’ average ranks against a single critical difference (CD):
CD = qα × √[k(k+1) / (6N)]
where qα is a critical value based on the studentized range distribution divided by √2, tabulated by the number of conditions being compared (Demšar, 2006, Table 5; the data table after this body reproduces it for k = 2 to 10). Two conditions are declared significantly different if their average-rank difference is at least the CD. This is a single threshold applied to every pair at once, which keeps the family-wise error rate controlled without a separate correction step, but the Nemenyi test is conservative and can fail to detect pairwise differences that a targeted comparison would catch. After a parametric ANOVA, the equivalent follow-up that covers any linear contrast rather than only pairs is the Scheffé test for complex contrasts.
Continuing the worked example: average ranks were A = 1.75, B = 1.25, C = 3.00 (each rank sum divided by N = 8). With k = 3 conditions, q0.05 = 2.343, giving CD = 2.343 × √(12/48) = 2.343 × 0.5 ≈ 1.17. Comparing each pair’s average-rank difference to that threshold: A vs. B differs by 0.50 (below CD, not significant), A vs. C differs by 1.25 (above CD, significant), and B vs. C differs by 1.75 (above CD, significant). Protocol C is significantly slower than both A and B; A and B are not distinguishable from each other at this sample size.
Post-hoc option 2: comparing every condition with one control (Bonferroni-Dunn)
When one condition is a natural baseline (a control protocol, a reference algorithm, a placebo-like condition) and the question is whether each other condition differs from it, all-pairs testing spends power on comparisons you do not need. Demšar (2006) describes the Bonferroni-Dunn test for this case. The test statistic for comparing condition i with condition j is
z = (Ri − Rj) / √[k(k+1) / (6N)]
where Ri and Rj are average ranks. The Bonferroni correction divides alpha by the number of comparisons actually made, which here is k − 1 rather than k(k−1)/2. The critical difference has the same form as Nemenyi’s, but with the critical value taken at alpha/(k − 1): for k = 3 at α = 0.05 that value is 2.241, against 2.343 for Nemenyi. The gap widens as k grows, which is why the data table after this body lists the two side by side. Demšar notes that this makes the test more powerful than Nemenyi when you only compare against a control.
In the worked example, take Protocol A as the control. CD = 2.241 × 0.5 ≈ 1.12. A vs. C differs by 1.25, which exceeds 1.12, so C differs significantly from the control; A vs. B differs by 0.50, which does not. The conclusion matches the Nemenyi result here, but the threshold is lower because only two comparisons are being paid for instead of three.
A published illustration of the same idea appears in Demšar (2006) with k = 4 and N = 14: the Nemenyi critical difference is 2.569 × √(20/84) ≈ 1.25 at α = 0.05, and no pair of the four differs at that level, while at α = 0.10 the critical difference falls to 1.12.
Post-hoc option 3: pairwise Wilcoxon signed-rank tests with a Bonferroni correction
The alternative is to run a Wilcoxon signed-rank test on each pair of conditions separately, then apply a Bonferroni correction to control the family-wise error rate across however many pairs you ran. With k conditions there are k(k−1)/2 comparisons, so the per-comparison significance threshold becomes alpha / [k(k−1)/2]: for the three-protocol example, that is 0.05 / 3 ≈ 0.0167, not the usual 0.05.
This route lets you restrict the correction to the comparisons you actually planned: if you test only each treatment against a control, the denominator is k − 1, not k(k−1)/2. It is also convenient because base R provides pairwise.wilcox.test(), which takes a p-value adjustment method. Note that this approach runs separate two-sample ranking for each pair, whereas Nemenyi and Bonferroni-Dunn reuse the ranks from the single Friedman ranking, so the methods can disagree at borderline p-values.
Conover’s all-pairs test
Some packages offer Conover’s test as a further all-pairs procedure for Friedman designs. In R, the PMCMRplus package implements it as frdAllPairsConoverTest, citing Conover (1999), and its default p-value adjustment is a single-step procedure based on the studentized range distribution. If you use it, name the function and the adjustment method in your report so the analysis can be reproduced.
Which one to use
Neither procedure is universally correct; the choice depends on what you are asking:
| Question | Procedure | Comparisons to correct for |
|---|---|---|
| Which of all k conditions differ from each other? | Nemenyi (or Conover all-pairs) | k(k−1)/2 |
| Does each condition differ from one named control? | Bonferroni-Dunn | k − 1 |
| Only a planned subset of pairs matters | Wilcoxon signed-rank with Bonferroni | The number of pairs you planned |
- Use Nemenyi when you want every possible pairwise comparison and a single, simple threshold, as when reporting a full comparison matrix of several algorithms or conditions.
- Use Bonferroni-Dunn or Wilcoxon with Bonferroni when you have specific, planned comparisons in mind, because a smaller correction denominator preserves more power.
- Decide the comparison set before you look at the data. Choosing the pairs after seeing which ones look different undoes the correction.
Effect size: report Kendall’s W alongside the test statistic
A significant Friedman result does not indicate how large the effect is, only that it is unlikely to be chance. Kendall’s coefficient of concordance (Kendall’s W) is the standard companion effect size, computed directly from the same statistic:
W = χ2F / [N(k − 1)]
W ranges from 0 (no agreement in ranking across subjects) to 1 (every subject ranked the conditions identically). The rstatix R package, whose friedman_effsize function computes it, cites Cohen’s guidelines for interpreting W: 0.1 to below 0.3 is a small effect, 0.3 to below 0.5 moderate, and 0.5 or above large. Treat these as rough orientation, not a substitute for reporting the actual value alongside your effect size. For the worked example, W = 13 / (8 × 2) = 0.81, a large effect on that scale, reflecting that the technicians ordered the three protocols very consistently.
How to report a Friedman test with post-hoc results
A complete report states the omnibus result, the post-hoc method and correction, and which specific pairs differed, not just “p < .05”:
A Friedman test indicated a significant difference in completion time across the three assay protocols, χ2F(2) = 13.00, p = .002, N = 8, Kendall’s W = .81. Post-hoc pairwise comparisons using the Nemenyi test (critical difference = 1.17 at α = .05) indicated that Protocol C required significantly more time than both Protocol A (average rank difference = 1.25) and Protocol B (average rank difference = 1.75); Protocols A and B did not differ significantly from each other (average rank difference = 0.50).
With a design this small, add that the p-value is the chi-square approximation. Demšar (2006) also recommends a graphical option for many conditions: a critical-difference diagram places the average ranks on one axis and joins with a bar every group of conditions whose differences are smaller than the CD. See how to report p-values for the general formatting conventions this follows, and always name the specific post-hoc procedure and correction used: “post-hoc tests were conducted” without naming which one is not reproducible.
Running it in R and Python
R’s friedman.test accepts either a numeric matrix whose rows are blocks (subjects) and columns are groups (conditions), or a formula of the form y ~ groups | blocks. Its reference is Hollander and Wolfe (1973).
y <- matrix(c(42,38,45, 37,34,39, 50,48,53, 29,31,33,
44,40,46, 35,33,38, 41,44,47, 33,30,36),
ncol = 3, byrow = TRUE,
dimnames = list(NULL, c("A", "B", "C")))
friedman.test(y)
library(PMCMRplus)
frdAllPairsNemenyiTest(y)
frdAllPairsNemenyiTest in PMCMRplus computes p-values from the studentized range distribution and also accepts the formula form. Its function name tells you which procedure was run, which is worth quoting in the methods section. For the effect size, rstatix::friedman_effsize returns Kendall’s W.
In Python, scipy.stats.friedmanchisquare takes one array per condition, each ordered by subject, and requires at least three samples:
from scipy.stats import friedmanchisquare
a = [42, 37, 50, 29, 44, 35, 41, 33]
b = [38, 34, 48, 31, 40, 33, 44, 30]
c = [45, 39, 53, 33, 46, 38, 47, 36]
stat, p = friedmanchisquare(a, b, c)
Remember that the SciPy p-value is the chi-square approximation, so the small-sample caution above applies to this example’s eight subjects.
Related checks before you commit to Friedman
- If your design has only two related conditions, use the Wilcoxon signed-rank test directly.
- If your groups are independent rather than repeated measures on the same subjects, use the Kruskal-Wallis test instead.
- If your dependent variable is binary and you have exactly two related conditions, McNemar’s test is the correct tool, not Friedman.
- Before defaulting to the nonparametric route, check normality and run Mauchly’s test for sphericity on the repeated-measures ANOVA. Friedman trades some statistical power for fewer assumptions, and it is the right trade only when those assumptions genuinely do not hold.
- If your repeated measures are collected on a Likert scale, Friedman (not repeated-measures ANOVA) is usually the appropriate omnibus test, for the same ordinal-data reason covered above.
Frequently asked questions
Is the Friedman test the same as a repeated-measures ANOVA?
No. Repeated-measures ANOVA analyzes the raw scores and assumes sphericity and (for small samples) normally distributed differences; the Friedman test analyzes only the within-subject ranks and makes no distributional assumption about the raw scores. Friedman is the nonparametric alternative used when repeated-measures ANOVA’s assumptions do not hold, and it has less power when those assumptions do hold.
What is the difference between the Friedman test and the Kruskal-Wallis test?
Both are rank-based omnibus tests for three or more conditions, but Friedman is for related samples (the same subjects measured under every condition) and Kruskal-Wallis is for independent samples (different subjects in each condition). Using the wrong one ignores the correlation structure in your data.
Do I need a post-hoc test if the Friedman test is not significant?
No. If the omnibus Friedman test does not reach significance, there is no statistical basis for a post-hoc comparison, and running one anyway (reporting whichever pair happens to look different) inflates the Type I error rate and defeats the purpose of running the omnibus test first.
The Friedman test is significant but the Nemenyi test finds no difference. Why?
The two tests answer different questions, and the Nemenyi test is the more conservative one. Demšar (2006) shows exactly this outcome: with k = 4 and N = 14 the Friedman test rejects the null, yet the Nemenyi critical difference of about 1.25 at α = 0.05 is not reached by any pair (it falls to 1.12 at α = 0.10). If the question is really about comparison with a control, the Bonferroni-Dunn test has a lower critical difference and may find differences that Nemenyi misses.
Should I use the Nemenyi test or Wilcoxon signed-rank tests with a Bonferroni correction?
Use Nemenyi for an exhaustive all-pairs comparison with one simple threshold; use Wilcoxon-Bonferroni (or Bonferroni-Dunn) when you have a smaller, planned set of comparisons, since correcting for fewer comparisons preserves more power.
How do I handle ties in a Friedman test?
Give tied scores within a subject the average of the ranks they span. Software such as SciPy then computes the statistic with a correction for ties, so its value can differ slightly from the no-ties hand formula.
Can I use the Friedman test with missing data?
Only complete blocks contribute. R’s friedman.test removes any block that has a missing value, so a subject missing one condition is dropped entirely.
What effect size should I report with a Friedman test?
Kendall’s coefficient of concordance (Kendall’s W), computed as χ2F divided by N(k − 1). It ranges from 0 to 1 and describes how consistently subjects ranked the conditions; Cohen’s benchmarks as cited by rstatix are 0.1 small, 0.3 moderate and 0.5 large.
How many subjects do I need for a Friedman test?
The chi-square approximation to the test statistic is considered valid when N > 10 and k > 5 as a rule of thumb (Demšar, 2006); SciPy states its p-value is reliable only for more than 10 subjects and more than 6 repeated samples. Below that, use exact critical values. For power, run an analysis for your specific N and k rather than relying on a rule of thumb.
Sources
- Demšar, J. (2006). Statistical comparisons of classifiers over multiple data sets. Journal of Machine Learning Research 7, 1–30: https://www.jmlr.org/papers/volume7/demsar06a/demsar06a.pdf
- SciPy documentation, scipy.stats.friedmanchisquare: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.friedmanchisquare.html
- R documentation, stats::friedman.test: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/friedman.test.html
- PMCMRplus, frdAllPairsNemenyiTest: https://search.r-project.org/CRAN/refmans/PMCMRplus/html/frdAllPairsNemenyiTest.html
- PMCMRplus, frdAllPairsConoverTest: https://search.r-project.org/CRAN/refmans/PMCMRplus/html/frdAllPairsConoverTest.html
- rstatix, friedman_effsize (Kendall’s W and Cohen’s benchmarks): https://rpkgs.datanovia.com/rstatix/reference/friedman_effsize.html
Data: Critical values for post-hoc comparisons after a Friedman test, by number of conditions
Nemenyi (all pairs) and Bonferroni-Dunn (each condition against one control) two-tailed critical values q for k = 2 to 10 conditions at alpha 0.05 and 0.10, with the number of comparisons each procedure must cover; critical values transcribed from Demsar (2006) Table 5, comparison counts computed as k(k-1)/2 and k-1.
Period covered: 2006.
| Conditions (k) | All-pairs comparisons (count) | Control comparisons (count) | Nemenyi q at alpha 0.05 | Nemenyi q at alpha 0.10 | Bonferroni-Dunn q at alpha 0.05 | Bonferroni-Dunn q at alpha 0.10 |
|---|---|---|---|---|---|---|
| k = 2 | 1 | 1 | 1.96 | 1.645 | 1.96 | 1.645 |
| k = 3 | 3 | 2 | 2.343 | 2.052 | 2.241 | 1.96 |
| k = 4 | 6 | 3 | 2.569 | 2.291 | 2.394 | 2.128 |
| k = 5 | 10 | 4 | 2.728 | 2.459 | 2.498 | 2.241 |
| k = 6 | 15 | 5 | 2.85 | 2.589 | 2.576 | 2.326 |
| k = 7 | 21 | 6 | 2.949 | 2.693 | 2.638 | 2.394 |
| k = 8 | 28 | 7 | 3.031 | 2.78 | 2.69 | 2.45 |
| k = 9 | 36 | 8 | 3.102 | 2.855 | 2.724 | 2.498 |
| k = 10 | 45 | 9 | 3.164 | 2.92 | 2.773 | 2.539 |
Sources
- Demsar (2006) Statistical comparisons of classifiers over multiple data sets, JMLR 7:1-30 (accessed 2026-11-21)
- PMCMRplus frdAllPairsNemenyiTest (accessed 2026-11-21)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







