The short answer
Choose the target of inference before testing assumptions.
Use one-way ANOVA when
The group means are the scientific target
Independent observations, an additive mean model and reasonably behaved residuals make the F test a direct test of equal population means. If variances differ, Welch's ANOVA addresses that problem without discarding magnitudes.
Use Kruskal–Wallis when
Ordering is meaningful and ranks answer the question
Kruskal–Wallis pools and ranks the observations, then asks whether the groups have the same distribution. A simple location or median interpretation needs similarly shaped distributions that differ mainly by a shift.
Keep the data fixed to expose the different questions
R's complete PlantGrowth dataset contains ten dried
plant weights in each of three independent groups. The same 30
observations appear in both analyses; only the inferential model
changes.
| Row | Control | Treatment 1 | Treatment 2 |
|---|---|---|---|
| 1 | 4.17 | 4.81 | 6.31 |
| 2 | 5.58 | 4.17 | 5.12 |
| 3 | 5.18 | 4.41 | 5.54 |
| 4 | 6.11 | 3.59 | 5.50 |
| 5 | 4.50 | 5.87 | 5.37 |
| 6 | 4.61 | 3.83 | 5.29 |
| 7 | 5.17 | 6.03 | 4.92 |
| 8 | 4.53 | 4.89 | 6.15 |
| 9 | 5.33 | 4.32 | 5.80 |
| 10 | 5.14 | 4.69 | 5.26 |
ANOVA tests equality of the three means
The group means are 5.032, 4.661 and 5.526. Ordinary one-way ANOVA partitions variation between and within groups and gives F(2, 27) = 4.846, P = 0.01591. Its η² is 0.264 and ω² is 0.204. The global result rejects equality of all three population means; it does not say that every pair differs.
In this balanced dataset the residual normality diagnostic gives P = 0.400 and the Brown–Forsythe variance diagnostic gives P = 0.341. Neither proves the assumptions, but neither supplies a reason to replace the pre-specified mean comparison here.
Kruskal–Wallis tests the pooled ranks
Pooling all 30 observations produces rank sums of 147.5, 103.5 and 214.0, or mean ranks of 14.75, 10.35 and 21.40. The tie-corrected result is H(2) = 7.988, P = 0.01842, using the chi-square approximation. Epsilon-squared is 0.275.
| Group | Median | Mean rank | Rank sum |
|---|---|---|---|
| Control | 5.155 | 14.75 | 147.5 |
| Treatment 1 | 4.550 | 10.35 | 103.5 |
| Treatment 2 | 5.435 | 21.40 | 214.0 |
Here both global tests cross 0.05, but that agreement is not interchangeable proof. ANOVA reacts to mean separation relative to within-group variation; Kruskal–Wallis reacts to how observations from each group occupy the pooled ranking.
Why “Kruskal–Wallis compares medians” needs a condition
The formal null is that the group distribution functions are identical. If the distributions have similar shapes and spreads, a difference is naturally described as a location shift and medians are useful summaries. If shapes or spreads differ, a rejection can reflect those differences too; three displayed sample medians do not redefine the test.
A global P value is not the pairwise answer
After the Kruskal–Wallis result, Dunn's all-pairs comparisons give adjusted P values of 0.7911 (control vs treatment 1), 0.2735 (control vs treatment 2) and 0.01500 (treatment 1 vs treatment 2). The analogous ANOVA workflow uses a mean-comparison family such as Tukey or Dunnett. Choose that family from the study question and report its estimand—not just the smallest adjusted P value.
Two honest reporting templates
Mean model: “Dried plant weight differed among groups by ordinary one-way ANOVA, F(2, 27) = 4.846, P = 0.01591, η² = 0.264. Tukey-adjusted pairwise estimates and simultaneous confidence intervals were used for follow-up.”
Rank model: “Distributions differed among groups by a tie-corrected Kruskal–Wallis test, H(2) = 7.988, P = 0.01842, ε² = 0.275. Dunn-adjusted rank comparisons were used for follow-up.” Add a median-shift interpretation only when the distribution shapes make it defensible.
What Plotwright verifies—and what it cannot
The executable suite sends the displayed observations through both production engines. It pins the published ANOVA benchmark and the Kruskal–Wallis H statistic, rank sums, effect size and Dunn-adjusted outputs shown here. The editable examples recompute rather than storing these results as text.
PlantGrowth has sparse experimental metadata. Numerical reproduction cannot recover the original experimental unit, establish independence, validate a biological mechanism or choose the scientific estimand.
Sources and reproducibility
- R datasets documentation: PlantGrowth—all 30 values and the one-factor ANOVA example.
- R stats documentation: kruskal.test—the rank-sum test, returned quantities and canonical worked example.
- NIST/SEMATECH: Kruskal–Wallis—the identical-distributions null, assumptions and rank formula.
- NIST/SEMATECH: model assumptions—normal-model assumptions, robustness and graphical checks.
- Plotwright statistical validation—published expected values, tolerances and evidence boundaries.