Guides / kruskal wallis test
The Kruskal-Wallis test: a complete guide
Kruskal-Wallis is the rank-based alternative to one-way ANOVA, used when the outcome is ordinal or the distribution will not support a parametric test. This guide covers when it applies, works the statistic out by hand, explains the post-hoc procedure that a significant result requires, and sets out what your result is actually entitled to claim.
The Kruskal-Wallis test is a non-parametric test comparing three or more independent groups. It pools all observations, ranks them together, and tests whether the rank sums differ more than chance would produce. It is the rank-based equivalent of one-way ANOVA and is used when the outcome is ordinal or when the distribution is too skewed for a parametric test.
Definition
What the Kruskal-Wallis test does
Kruskal-Wallis pools every observation from all groups, ranks them from lowest to highest, and asks whether the ranks are distributed evenly across the groups. If one group's observations cluster at the high end of the ranking, its rank sum will be larger than chance alone would produce.
The test statistic is H, and it is approximately chi-square distributed with k − 1 degrees of freedom, where k is the number of groups. Like chi-square and F, it cannot be negative and only large values reject the null.
The word “non-parametric” causes some confusion here, because it is often heard as “assumption-free”. It is not. What it means is that the test does not assume the data follow a particular named distribution — there is no normality requirement, no parameter such as a mean or standard deviation being estimated. Independence is still required absolutely, and the shape condition still governs what your conclusion may claim. Rank-based tests trade distributional assumptions for a small loss of power and a slightly weaker conclusion, not for freedom from assumptions altogether.
Kruskal-Wallis is essentially a one-way ANOVA performed on the ranks rather than the raw values. That framing explains its properties: it inherits ANOVA's structure, including the fact that a significant result tells you a difference exists somewhere without saying where.
Choosing
When to use it instead of ANOVA
| Situation | Test |
|---|---|
| Continuous outcome, roughly normal, adequate n | One-way ANOVA |
| Ordinal outcome | Kruskal-Wallis |
| Heavily skewed continuous outcome | Kruskal-Wallis |
| Small groups where normality cannot be judged | Kruskal-Wallis |
| Outliers you cannot justify removing | Kruskal-Wallis |
| Unequal variances, otherwise normal | Welch’s ANOVA |
| Repeated measures on the same participants | Friedman test |
| Only two groups | Mann-Whitney U |
Note the sixth row. If your problem is unequal variances rather than non-normality, Welch's ANOVA is usually the better answer than switching to ranks, because it keeps the interpretation in the original units and costs less power. Kruskal-Wallis is the tool for the measurement level and the shape of the distribution, not a general-purpose fix for anything that fails a diagnostic test.
Running both an ANOVA and a Kruskal-Wallis and reporting whichever reaches significance invalidates the p-value. Decide on the basis of the outcome's measurement level and distribution, state the decision in your methods section, and hold to it.
Answer four questions about your measurement level, number of groups and whether the data are paired, and be taken to the test that fits.
Use the test chooserAssumptions
Assumptions, including the one about shape
| Assumption | What it requires |
|---|---|
| Independence | Each participant contributes one observation to one group |
| Ordinal or continuous outcome | The values can be meaningfully ranked |
| Two or more groups | With three or more, or use Mann-Whitney |
| Similar distribution shape | Only if you want to claim a difference in medians |
The final row is the same caveat that applies to Mann-Whitney, and it is skipped just as often. Strictly, Kruskal-Wallis tests whether the groups differ in the distribution of ranks — whether observations from one group tend to exceed those from another. It reduces to a statement about medians only when the distributions share a similar shape and spread.
Plot the distributions first. If they look similar in shape, “median scores differed significantly between groups” is defensible. If one is skewed and another is not, write “scores differed significantly between groups” and give medians and interquartile ranges so the reader can see the pattern themselves.
Note also what is not assumed: normality is not required, and neither is equality of variance in the sense ANOVA requires it. What matters is that observations are independent and rankable.
Worked example
Worked example: calculating H by hand
Fifteen participants are split across three conditions and rated on a task measure. Pooled and ranked across all 15, the ranks fall as follows.
| Group | Ranks | nₖ | Rank sum Rₖ | Rₖ²/nₖ |
|---|---|---|---|---|
| A | 1, 2, 4, 6, 9 | 5 | 22 | 96.8 |
| B | 3, 7, 8, 11, 13 | 5 | 42 | 352.8 |
| C | 5, 10, 12, 14, 15 | 5 | 56 | 627.2 |
| Total | 15 | 120 | 1076.8 |
Step 1 — check the rank total
The ranks must sum to N(N+1)/2 = 15 × 16 / 2 = 120. Here 22 + 42 + 56 = 120.
Step 2 — apply the formula
H = [12 / (N(N+1))] × Σ(Rₖ²/nₖ) − 3(N+1)
= [12 / (15 × 16)] × 1076.8 − (3 × 16)
= 0.05 × 1076.8 − 48 = 53.84 − 48 = 5.84
Step 3 — the decision
df = k − 1 = 2. The critical chi-square value at α = .05 with 2 degrees of freedom is 5.99. Our H = 5.84 falls just short, giving p = .054.
The pattern here is orderly — group C outranks B, which outranks A — and the test still does not reach significance. Five participants per group provides very little power. The correct conclusion is that this sample provides insufficient evidence of a difference, not that the groups are alike.
What the near-miss would need to reach significance
It is worth seeing how sensitive this is to sample size. The pattern of ranks above is close to a perfect separation of the three groups, and it produces H = 5.84 against a critical value of 5.99. Had the same ordering held with seven participants per group rather than five, H would rise well past the threshold, because H scales with N while the critical value depends only on the number of groups. Nothing about the effect would have changed — only the evidence available to detect it.
This is the practical argument for running a power analysis before collecting data rather than explaining a null result afterwards. A study that stops at five per group is very likely to produce exactly this outcome: an orderly pattern, a large effect size, and a p-value just the wrong side of the threshold.
Ties
Where observations tie, each receives the average of the ranks they would have occupied, and H must then be divided by a tie correction factor. Ties inflate the correction and therefore increase H slightly. Software applies this automatically; the hand formula above does not, so with substantial tying — common in Likert data — the hand result will be marginally conservative.
Follow-up
Post-hoc: finding which groups differ
A significant H means at least one group differs from at least one other, and nothing more specific. As with ANOVA, stopping there leaves the analysis incomplete.
| Procedure | What it does | Note |
|---|---|---|
| Dunn's test | Pairwise rank comparisons with a multiplicity correction | The standard choice |
| Pairwise Mann-Whitney with Bonferroni | Separate tests, corrected | Acceptable but more conservative |
| Conover-Iman | More powerful than Dunn after a significant H | Only valid if H was significant |
A point that catches people out: it is possible for the omnibus test to be significant while no pairwise comparison survives correction, and for the reverse to happen too. The first case usually means the differences are spread thinly across several groups rather than concentrated in one pair. The second means the omnibus test lacked power relative to a specific focused comparison. Neither is an error — they are different questions — but both need reporting honestly rather than quietly presenting whichever result is more convenient.
Dunn's test is preferred because it uses the ranks from the original pooled ranking rather than re-ranking each pair, which keeps it consistent with the omnibus test. Running separate Mann-Whitney tests re-ranks within each pair, so the comparisons no longer align exactly with the test that licensed them.
Three groups give three pairwise comparisons, four groups give six. Without correction the false positive rate climbs exactly as it does after ANOVA. Dunn's test applies the correction for you; if you use pairwise Mann-Whitney tests instead, apply Bonferroni or Holm yourself and say which.
Related tests
Friedman, and the rest of the family
Kruskal-Wallis sits in a family of rank-based tests, each matched to a specific design. Picking the wrong member is common, and the error is usually about independence rather than about measurement level.
| Design | Parametric test | Rank-based equivalent |
|---|---|---|
| Two independent groups | Independent t-test | Mann-Whitney U |
| Three or more independent groups | One-way ANOVA | Kruskal-Wallis |
| Two paired measurements | Paired t-test | Wilcoxon signed-rank |
| Three or more paired measurements | Repeated measures ANOVA | Friedman |
| Association between two variables | Pearson’s r | Spearman’s rho |
There is also a question of what to do when groups are very unequal in size, which arises often with naturally occurring groups such as departments or wards. Kruskal-Wallis handles unequal group sizes without difficulty — the formula divides each squared rank sum by its own group size, which is exactly the adjustment needed. What it cannot do is compensate for a group so small that its rank sum carries almost no information. With one group of 40 and another of 4, the test remains valid but the comparison involving the small group is effectively uninformative, and it is worth saying so rather than reporting all pairwise results as though they were equally well established.
Why Friedman is not interchangeable
If the same participants are measured under all three conditions, their scores are correlated: a person who scores highly in one condition tends to score highly in the others. Kruskal-Wallis assumes every observation is independent, so applying it to repeated measures treats 15 observations from 5 people as though they came from 15 different people. The result is a test with the wrong degrees of freedom, and one that discards the pairing which was the design's main source of power.
Friedman handles this by ranking within each participant rather than across the whole sample. Each person's three scores are ranked 1 to 3, and the test asks whether particular conditions consistently attract the higher ranks. That within-subject ranking is what preserves the pairing.
Count the rows in your dataset against the number of people. If each person appears once, the groups are independent and Kruskal-Wallis applies. If each person appears several times, you need Friedman — regardless of how the spreadsheet happens to be laid out.
Following up a Friedman test
The same logic applies as for Kruskal-Wallis: a significant result identifies that some condition differs without saying which. Follow it with pairwise Wilcoxon signed-rank tests, corrected for the number of comparisons, or with Conover's post-hoc procedure.
Effect size
Effect size
A p-value says nothing about magnitude, and two effect sizes are commonly reported for Kruskal-Wallis.
| Measure | Formula | Range |
|---|---|---|
| Epsilon squared | ε² = H / ((N² − 1)/(N + 1)) | 0 to 1 |
| Eta squared (H-based) | η² = (H − k + 1) / (N − k) | 0 to 1 |
For our example: ε² = 5.84 / ((225 − 1)/16) = 5.84 / 14 = 0.417, and η² = (5.84 − 2) / 12 = 0.320. Both suggest a large effect — which sits oddly beside a non-significant p-value, and illustrates the point that with five per group the study lacked the power to establish an effect it may well have detected.
Note that both formulas can return a small negative value when H is very small — smaller than would be expected by chance alone. Report such a result as zero rather than as a negative effect size, since a negative proportion of variance explained has no meaning.
| ε² | Conventional label |
|---|---|
| 0.01 | Small |
| 0.08 | Medium |
| 0.26 | Large |
One further caution about interpreting a large effect size alongside a non-significant test, as in the worked example above. It is tempting to describe such a result as “approaching significance” or as a trend. Neither phrase is defensible: the test either rejected the null at your stated threshold or it did not. What you can legitimately say is that the point estimate suggests a substantial difference which this sample was too small to establish, and that the study was underpowered. That framing is accurate, useful to whoever designs the follow-up, and does not smuggle in a conclusion the data cannot support.
Having chosen a rank-based test because the data are ordinal or skewed, reporting group means alongside it contradicts the reasoning. Give the median and interquartile range for each group.
Pitfalls
Six mistakes that cost marks
1. Claiming a difference in medians without checking shape
Valid only when the distributions have similar shapes. Otherwise the claim is that one group tends to score higher.
2. Stopping at a significant H
Run Dunn's test. Without it you cannot say which groups differ, and the analysis is unfinished.
3. Running pairwise Mann-Whitney tests without correction
Three comparisons at α = .05 gives about a 14% chance of a false positive.
4. Using it on repeated measures
Kruskal-Wallis needs independent groups. For the same participants measured three or more times, use the Friedman test.
5. Reporting means
Report medians and interquartile ranges, consistent with the test.
6. Choosing it as a general fix for failed assumptions
If the problem is unequal variances rather than non-normality, Welch's ANOVA usually serves better.
Reporting
Reporting Kruskal-Wallis in APA style
| Situation | How to write it |
|---|---|
| Significant | H(2) = 11.42, p = .003, ε² = .34 |
| Not significant | H(2) = 5.84, p = .054, ε² = .42 |
| Sometimes written as | χ²(2) = 11.42, p = .003 — both forms are accepted |
| Descriptives | Mdn = 24 (IQR 15–31) per group |
| Post-hoc | Dunn's test with Bonferroni correction indicated C > A (p = .004) |
“As task ratings were ordinal, a Kruskal-Wallis test was used. Ratings differed significantly across the three conditions, H(2) = 11.42, p = .003, ε² = .34. Dunn's post-hoc tests with Bonferroni correction indicated that condition C (Mdn = 7, IQR 6–8) was rated significantly higher than condition A (Mdn = 4, IQR 3–5), p = .004.”
Send your dataset and design. A named statistician confirms the test suits the measurement level, handles the tie correction, runs the post-hoc comparisons and returns APA tables.
See SPSS data analysisAnswers
Frequently asked questions
When should I use the Kruskal-Wallis test?
When comparing three or more independent groups on an outcome that is ordinal, heavily skewed, or measured in samples too small to assess normality. It is the rank-based equivalent of one-way ANOVA. For two groups use Mann-Whitney; for repeated measures use Friedman.
Does Kruskal-Wallis compare medians?
Only when the groups have similarly shaped distributions. Strictly it tests whether observations in one group tend to exceed those in another. If the shapes differ, report it as a difference in scores rather than in medians, and give medians with interquartile ranges so readers can judge.
What is the difference between Kruskal-Wallis and ANOVA?
ANOVA compares means and assumes roughly normal residuals with comparable variances. Kruskal-Wallis compares rank distributions and makes no distributional assumption. ANOVA is more powerful when its assumptions hold; Kruskal-Wallis is more trustworthy when they do not, particularly with ordinal data or outliers.
What post-hoc test follows a significant Kruskal-Wallis?
Dunn's test is the standard choice, because it uses the original pooled ranking and applies a multiplicity correction. Pairwise Mann-Whitney tests with a Bonferroni or Holm correction are acceptable but more conservative, and they re-rank within each pair so they do not align exactly with the omnibus test.
What effect size should I report?
Epsilon squared or the H-based eta squared, both ranging from 0 to 1. For epsilon squared, roughly .01 is small, .08 medium and .26 large. An effect size is essential because the p-value alone conveys nothing about how large the differences between groups are.
How does Kruskal-Wallis handle tied values?
Tied observations each receive the average of the ranks they would have occupied, and the H statistic is then divided by a tie correction factor. Software applies this automatically. The simple hand formula omits it, so with heavy tying — common in Likert data — a hand calculation is slightly conservative.
Can I use Kruskal-Wallis with only two groups?
You can, and it gives an equivalent result to the Mann-Whitney U test, but Mann-Whitney is the conventional choice for two groups and reports a statistic readers expect. Use Kruskal-Wallis when there are three or more.
Send the data. Get a fixed quote.
Attach your dataset or just describe the project. A named statistician replies with a price and a deadline, usually within one working day.