BCompare groups · Guide test 049
Dunn test
Compares selected groups’ average pooled ranks, typically with a multiple testing adjustment.
Do it in CodeSplash
In the app, set it up in Analyze with one of these methods:
- Kruskal–Wallis test — Do three or more independent groups differ in location (without assuming normality)?
- Pairwise comparisons (Tukey, Games–Howell, Dunnett, Dunn, Steel–Dwass …) — Which groups differ from which?
In Kruskal–Wallis test, choose Pairwise test = Dunn. In Pairwise comparisons (Tukey, Games–Howell, Dunnett, Dunn, Steel–Dwass …), choose Comparison = Dunn.
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 · Dunn 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 |z| varies across samples when H₀ is true, the Bonferroni bound on 6 pairs, |z|.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .033).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The whole family
| Pair | Difference in mean ranks | p | p adj. |
|---|---|---|---|
| .200 | 1.000 | ||
| .092 | .554 | ||
| .006 | .033 | ||
| .688 | 1.000 | ||
| .136 | .814 | ||
| .276 | 1.000 |
6 pairs; adjusted by Bonferroni. The highlighted row is the one in the reference pane (the most extreme by default).
The formula
With your numbers
- mean rank of group i in the joint ranking
- sizes of tied groups
The verdict
|z| = 2.77, p = .033, ΔR̄ = −14.50
p ≤ α = .050: reject H₀
Effect size: Group 1 − Group 4 (difference in mean ranks) ΔR̄ = −14.500
The usual follow-up to Kruskal–Wallis: joint ranks, normal z per pair, then a p adjustment (Bonferroni here).
- Statistic
- 2.773
- p-value
- 0.0333
Dunn test on Group 1: n = 10; Group 2: n = 10; Group 3: n = 10; Group 4: n = 10: |z| = 2.77, p = .033, ΔR̄ = −14.50. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0ij: two groups have equal rank location under the common distribution null.
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
Ri are ranks pooled across all groups; SR²=N(N+1)/12 without ties.
Structure of the method
Rank all groups jointly, compute pairwise differences in group average ranks, and standardize them using the global rank variance with tie adjustment. Normal-tail probabilities are then adjusted over the selected comparison family. This two-stage score-and-adjust structure differs from separately re-ranking every pair for independent Mann–Whitney tests.
Estimated and nuisance parameters
Estimate global pooled rank variance, group rank means, and tie multiplicities. Group sizes determine each contrast's variance. The rank scale depends on all included groups, so a pair's statistic can change when another group is added even before multiplicity adjustment. No common raw-data variance is estimated.
Settings and design choices
Prespecify pairwise or many-to-one family, normal versus justified permutation calibration, alpha, and p-value adjustment. Holm is a common choice with broad dependence validity given valid marginal tails. An omnibus Kruskal–Wallis gate can be part of a protocol but does not substitute for defining the follow-up family.
Fitting and adaptation
Recompute global ranks and all contrasts after any inclusion change. If a group is removed for a defensible design reason, the old pooled-rank contrasts are not the new Dunn analysis. For blocked data, use a blocked rank-comparison method instead of applying independent-group Dunn contrasts to repeated rows.
Sensitivity and robustness
Small groups and heavy ties can weaken the normal approximation. Unequal shape differences complicate a simple median interpretation. A significant adjusted rank contrast describes relative ordering under the stated model, not a difference in original measurement units. Report group distributions or an interpretable effect estimate alongside adjusted p-values.
How to use and calibrate
Use normal tail probabilities then a stated multiplicity adjustment, often Holm or Bonferroni.
Example application
Follow a Kruskal–Wallis comparison with adjusted rank contrasts.
Interpretation and pitfalls
Watch out
Dunn uses global ranks; separate Mann–Whitney tests re-rank each pair and are different.
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.
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::kwAllPairsDunnTest(value~group,data=d,p.adjust.method="holm"))
"""
# 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::kwAllPairsDunnTest(value~group,data=d,p.adjust.method="holm"))
Sources
- PMCMRplus — PMCMRplus · kwAllPairsDunnTestAuthor documentation/source reviewed: PMCMRplus 1.9.12.search.r-project.org
- kwAllPairsDunnTestsearch.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 049, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT049.