The Kruskal-Wallis H test compares three or more independent groups using ranks. It is the nonparametric counterpart of one-way ANOVA. Paste your groups and you get the H statistic with tie correction, the p-value, the ε² effect size, mean ranks for each group and Dunn’s post-hoc test with Holm or Bonferroni adjustment.
When to use the Kruskal-Wallis test
- Three or more independent groups.
- An ordinal outcome, or a numeric outcome that is skewed or contains outliers.
- Small groups where the normality assumption of ANOVA is doubtful.
For normally distributed data, the one-way ANOVA is more powerful. With only two groups, use the Mann-Whitney U test.
Formula
H = [ 12 ÷ (N(N + 1)) ] × Σ (Rᵢ² ÷ nᵢ) − 3(N + 1), divided by 1 − Σ(t³ − t) ÷ (N³ − N)
Rᵢ is the sum of ranks in group i and t is the size of each group of tied values. H is compared with a chi-square distribution with k − 1 degrees of freedom.
Dunn’s post-hoc test
A significant H tells you that at least one group differs, not which ones. Dunn’s test compares the mean ranks of every pair of groups using z statistics. Its p-values are adjusted for multiple comparisons. Holm’s method is the default because it controls the error rate while being more powerful than Bonferroni.
Effect size
ε² = H ÷ (N − 1) estimates the proportion of variability in ranks explained by group membership. It is read like η²: about .01 small, .06 medium, .14 large.
Frequently asked questions
Is the Kruskal-Wallis test a test of medians?
Only if the group distributions have the same shape. In general it tests whether values in one group tend to be higher than in another. Report the medians and mean ranks together.
How small can the groups be?
The chi-square approximation works well with five or more observations per group. With smaller groups, treat p-values close to .05 with caution.