BCompare groups · Guide test 051
Nemenyi test
Compares average ranks simultaneously; independent group and blocked design versions use different formulations.
Do it in CodeSplash
In the app, set it up in Analyze with one of these methods:
- Friedman test (repeated measures, ranks) — Do three or more conditions measured on the same subjects differ in location?
- Pairwise comparisons (Tukey, Games–Howell, Dunnett, Dunn, Steel–Dwass …) — Which groups differ from which?
In Friedman test (repeated measures, ranks), choose Pairwise test = Nemenyi (studentized range, single step). In Kruskal–Wallis test, choose Pairwise test = Nemenyi. In Pairwise comparisons (Tukey, Games–Howell, Dunnett, Dunn, Steel–Dwass …), choose Comparison = Nemenyi.
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Nemenyi test
Group i has true mean (i − 1) × spread.
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how q varies across samples when H₀ is true, the studentized range q(4, ∞).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .028).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The whole family
| Pair | Difference in mean ranks | p | p adj. |
|---|---|---|---|
| .200 | .575 | ||
| .092 | .333 | ||
| .006 | .028 | ||
| .688 | .978 | ||
| .136 | .442 | ||
| .276 | .696 |
6 pairs; adjusted by studentized range, ∞ df. The highlighted row is the one in the reference pane (the most extreme by default).
The formula
With your numbers
- tie-corrected variance of a rank
- studentized range with infinite df
The verdict
q = 3.92, p = .028, ΔR̄ = −14.50
p ≤ α = .050: reject H₀
Effect size: Group 1 − Group 4 (difference in mean ranks) ΔR̄ = −14.500
Tukey's idea on mean ranks: the studentized range with infinite df controls the family by itself. This page is the independent-groups version after Kruskal–Wallis. For repeated measures, the Friedman test has its own Nemenyi comparisons on mean ranks within blocks (Pairwise test: Nemenyi).
- Statistic
- 3.922
- p-value
- 0.0284
Nemenyi test on Group 1: n = 10; Group 2: n = 10; Group 3: n = 10; Group 4: n = 10: q = 3.92, p = .028, ΔR̄ = −14.50. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0ij: equal group rank locations; all pairs are considered.
Assumptions
Independent observations and independent groups; ordinal or quantitative measurements. The permutation null is identical group distributions. A location or median interpretation additionally needs comparable distribution shapes.
Formula
Parameters and notation
For independent groups use global ranks and SR²=N(N+1)/12 with tie adjustment. In a complete block version, Var(R̄i−R̄j)=k(k+1)/(6b).
Structure of the method
Compare pairwise average-rank differences with a studentized-range reference, but choose the correct rank construction first. The independent-group version uses ranks pooled over all observations; the Friedman version uses within-block ranks and a block-based variance. These are related named procedures with genuinely different sampling structures and denominators.
Estimated and nuisance parameters
Estimate average ranks and the tie-adjusted rank scale relevant to the selected design. Group sizes matter for independent samples, whereas independent block count governs the complete-block variance. The number of treatment groups sets the simultaneous range dimension. No common variance of the original measurement scale is fitted.
Settings and design choices
Prespecify independent versus blocked design, all-pairs family, alpha, reference distribution option, and tie treatment. The baseline code calls kwAllPairsNemenyiTest and therefore demonstrates independent groups, while classifier-on-common-datasets examples require the blocked version. Matching names alone is insufficient for matching methods across implementations.
Fitting and adaptation
Recompute ranks according to the actual design whenever observations change. In a blocked application, keep complete matched treatment vectors together during resampling and use a suitable incomplete-block approach if necessary. For new independent groups, recalculate the global rank scale and simultaneous family rather than extending old p-values mechanically.
Sensitivity and robustness
Few blocks, highly discrete outcomes, and large numbers of treatments can make asymptotic range approximations rough. Shared benchmark datasets must represent meaningful independent blocks. Nonsignificant differences are not equivalence, and average ranks can conceal large application-specific effect differences; retain original-scale summaries where available.
How to use and calibrate
Use the studentized range distribution with k groups and asymptotic infinite degrees of freedom; specify the independent group or Friedman block version.
Example application
Compare classifier ranks across datasets using the block version.
Interpretation and pitfalls
Watch out
Independent and blocked Nemenyi tests have different denominators. The original catalog groups them as one named family.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
- Rewritten in the review: example application.
Example applicationsearch.r-project.org
The former example application was blocked while the code demonstrates independent groups.
Corrected text
For the supplied independent-group code, compare average pooled ranks across independent treatment groups. To compare classifier ranks across the same independent datasets, use the blocked Friedman Nemenyi version and its block-based denominator instead; the displayed kwAllPairsNemenyiTest calls do not implement that blocked example.
Python and R
Read the matrix of adjusted p-values. This is an independent-group example; Nemenyi also has a separate Friedman/block version. The first factor level is control for many-to-one procedures.
Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: PMCMRplus
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
d <- data.frame(value=c(rnorm(20),rnorm(20,.4),rnorm(20,.8)), group=factor(rep(c("A","B","C"),each=20)))
print(PMCMRplus::kwAllPairsNemenyiTest(value~group,data=d))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Not run — Syntax checked; runtime not verified in the final environment · needs PMCMRplus
set.seed(2026)
d <- data.frame(value=c(rnorm(20),rnorm(20,.4),rnorm(20,.8)), group=factor(rep(c("A","B","C"),each=20)))
print(PMCMRplus::kwAllPairsNemenyiTest(value~group,data=d))
Sources
- PMCMRplus — PMCMRplus · kwAllPairsNemenyiTestAuthor documentation/source reviewed: PMCMRplus 1.9.12.search.r-project.org
- PMCMRplus — PMCMRplus · frdAllPairsNemenyiTestAuthor documentation/source reviewed: PMCMRplus 1.9.12.search.r-project.org
- kwAllPairsNemenyiTestsearch.r-project.org
- frdAllPairsNemenyiTestsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Python launcher syntax checked; R backend runtime not verified · R: Syntax checked; runtime not verified in the final environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 051, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT051.