The Kruskal-Wallis test is the non-parametric counterpart of one-way ANOVA. It compares three or more independent groups without assuming the data are normally distributed, which makes it the default choice for skewed measurements, data with outliers, and ordinal scores. Like the Mann-Whitney U test, which it generalizes, it works on ranks rather than raw values. This guide shows what H means, walks through a hand calculation, and explains what to do after a significant result.
The question it answers
Do all the groups come from the same distribution, or does at least one group tend to have systematically higher or lower values?
Like ANOVA, Kruskal-Wallis is an "omnibus" test: a significant result tells you that the groups are not all alike, but not which ones differ. And as with Mann-Whitney, calling it a "comparison of medians" is only accurate if all the groups have distributions of a similar shape and spread.
How the H statistic is built
- Pool all N observations from the k groups and rank them from 1 (smallest) to N (largest). Ties get the average of their ranks.
- Add up the ranks within each group (R1, R2, …).
- If the groups were truly alike, every group's average rank would be close to the overall average rank, (N + 1) / 2. H measures how far the group average ranks spread out from that centre:
H = [12 / (N(N + 1))] × Σ (Ri² / ni) − 3(N + 1)
Under the null hypothesis, H approximately follows a chi-square distribution with k − 1 degrees of freedom, which is where the p-value comes from. When there are tied values, H is divided by a small correction factor so the p-value stays accurate; StatFlo applies this correction automatically.
A worked example
Three diets, four animals each, final weight gain in grams:
| Diet | Values (g) | Ranks | Rank sum |
|---|---|---|---|
| A | 12, 15, 17, 21 | 1, 2, 3, 5 | 11 |
| B | 19, 23, 25, 30 | 4, 6, 7, 9 | 26 |
| C | 27, 33, 36, 40 | 8, 10, 11, 12 | 41 |
Check: the ranks 1 to 12 add up to 78, and 11 + 26 + 41 = 78. Now plug in, with N = 12 and n = 4 in each group:
- Σ Ri² / ni = (11² + 26² + 41²) / 4 = (121 + 676 + 1681) / 4 = 619.5
- H = 12 / (12 × 13) × 619.5 − 3 × 13 = 47.65 − 39 = 8.65
- Degrees of freedom = 3 − 1 = 2, giving p = 0.013
So at least one diet produces systematically different weight gain. Looking at the rank sums, the order is clearly A < B < C, but the test itself does not tell us whether A and B differ from each other. That needs a follow-up.
A caution about small samples: the chi-square approximation is rough when groups have fewer than about five observations. For tiny studies like this one, an exact or permutation p-value is more accurate; the approximation is used here to show the mechanics.
After a significant result: Dunn's test
The standard follow-up is Dunn's test, which compares each pair of groups using the same pooled ranks from the Kruskal-Wallis analysis, combined with a correction for multiple comparisons (Bonferroni or Holm). Running separate Mann-Whitney tests on every pair is a common shortcut; it re-ranks the data for each pair, but with a Holm or Bonferroni correction it is still a defensible approach. What you must not do is run uncorrected pairwise tests: with three groups that already raises the chance of at least one false positive to about 14%. Our guide to post-hoc tests explains the corrections with worked numbers.
Kruskal-Wallis or ANOVA?
| Your data | Recommended |
|---|---|
| Roughly symmetric in each group, similar spread | One-way ANOVA (slightly more power, and the mean is meaningful) |
| Clearly skewed, or long tails | Kruskal-Wallis |
| Outliers that are real data, not errors | Kruskal-Wallis |
| Ordinal scale (scores, ratings) | Kruskal-Wallis |
| Very different spreads between groups | Neither is ideal; consider Welch's ANOVA, and describe the distributions carefully |
| Same subjects measured under each condition | Neither: use the Friedman test or repeated-measures ANOVA |
The best way to decide is to look first. Draw a box or violin plot with the individual points: if the boxes are lopsided or there are points far beyond the whiskers, choose Kruskal-Wallis. See parametric vs non-parametric tests for the longer discussion.
Effect size
A simple and widely used effect size is epsilon-squared: ε² = H / (N − 1). In the example, 8.65 / 11 = 0.79, meaning group membership accounts for a large share of the variation in ranks. Rough benchmarks, borrowed by squaring the usual correlation benchmarks of 0.1, 0.3 and 0.5, treat about 0.01 as small, 0.09 as medium and 0.25 or more as large, but in your own field, comparing with published studies is more meaningful than any universal cut-off.
How to report it
"Weight gain differed between diets (Kruskal-Wallis H(2) = 8.65, p = 0.013, ε² = 0.79). Medians were 16 g (diet A), 24 g (diet B) and 34.5 g (diet C)."
Add the post-hoc comparisons in a following sentence or a table, stating which correction you used.
Running it in StatFlo
- Put each group in its own column, group names in the first row.
- Upload, select at least three columns, and choose a Box Plot or Violin Plot.
- Choose Kruskal-Wallis test and click Generate. The results report H, the degrees of freedom, the p-value, the ε² effect size and each group's median and IQR, followed by Dunn's post-hoc comparisons (Holm-adjusted). Turn on Significance on graph to show the significant pairs as asterisk brackets.