What the Kruskal–Wallis test does

The Kruskal–Wallis test compares three or more independent groups without assuming normal data. It ranks all values together and checks whether the groups’ average ranks differ more than chance would allow. It is the nonparametric alternative to one-way ANOVA and the extension of the Mann–Whitney U test to more than two groups.

When to use it

Worked example

The example data are pain-relief ratings (0–10) from three treatments with 7 patients each. The mean ranks are 10.50, 17.43 and 5.07, and the test gives H(2) = 14.21, p < .001, so the treatments differ. The effect size ε² = .71 is very large. Dunn’s post-hoc tests with Holm correction show that only groups 2 and 3 differ significantly (adjusted p = .0005); group 1 does not differ significantly from either (p = .070 and .099). A significant overall test does not mean every pair differs.

How the calculation works

  1. Rank all observations together; ties share the average rank.
  2. H measures how far each group’s mean rank is from the overall mean rank, weighted by group size, and is corrected for ties.
  3. The p-value comes from the chi-square distribution with k − 1 degrees of freedom. Results match SciPy’s kruskal and R’s kruskal.test.
  4. Dunn’s test compares each pair of mean ranks with a z statistic that uses the pooled ranking and a tie correction; Holm or Bonferroni adjustment controls the family-wise error rate. Results match the scikit-posthocs package.

Effect size

ε² (epsilon squared) = H / (n − 1) estimates the proportion of variation in ranks explained by group membership. Rough guides: about .01 is small, .08 medium and .26 or more large.

Frequently asked questions

When should I use Kruskal-Wallis instead of ANOVA?

When the outcome is ordinal or clearly non-normal with small groups, or there are strong outliers. With roughly normal data and similar variances, one-way ANOVA is slightly more powerful.

Does Kruskal-Wallis compare medians?

Strictly it compares the distributions of ranks. It can be read as a comparison of medians only when all groups have distributions of a similar shape.

Which post-hoc test follows a Kruskal-Wallis test?

Dunn's test is the standard choice. It compares the mean ranks of each pair of groups, and the p-values should be adjusted for multiple comparisons, for example with the Holm method.

How do I report a Kruskal-Wallis result?

Give H with its degrees of freedom, the p-value and an effect size, for example H(2) = 14.21, p < .001, epsilon squared = .71, followed by the post-hoc comparisons.