- The Kruskal-Wallis test compares three or more independent (unrelated) groups — it is the non-parametric extension of the Mann-Whitney U test and the non-parametric alternative to one-way ANOVA.
- Use it when your outcome is continuous but not normally distributed, or when it's ordinal rather than truly continuous.
- The test ranks all observations across every group combined, then compares the mean rank in each group — a large H statistic means the ranks are unevenly distributed across groups.
- A significant result only tells you at least one group differs — Dunn's post hoc test, with a multiple-comparison correction, is needed to find out which ones.
- Always report medians and IQRs for each group alongside the p-value and an effect size — never the p-value alone.
What Is the Kruskal-Wallis Test?
The Kruskal-Wallis test is a non-parametric statistical test that compares three or more independent groups to determine whether they differ on a continuous or ordinal outcome. It was developed by William Kruskal and W. Allen Wallis in 1952 as a rank-based counterpart to one-way ANOVA, for situations where ANOVA's normality assumption doesn't hold.
Mechanically, the test pools every observation from every group into a single combined list, ranks them all from smallest to largest (with tied values receiving the average of the ranks they'd otherwise occupy), and then calculates the average rank within each group. If the groups genuinely don't differ, their average ranks should be similar; a large spread between the groups' average ranks — more than expected by chance — produces the test's H statistic and, from it, a p-value.
Instead of asking "do the group means differ?" (one-way ANOVA's question), the Kruskal-Wallis test asks "if I rank every patient from lowest to highest regardless of group, do some groups end up with consistently higher or lower ranks than others?" — a question that doesn't require the outcome to be normally distributed.
When Should You Use the Kruskal-Wallis Test?
The Kruskal-Wallis test is the correct choice when your study meets these conditions:
- You are comparing three or more independent groups — different, unrelated subjects in each group.
- Your outcome is continuous but not normally distributed within the groups, confirmed with a Shapiro-Wilk test or suspected from skew, outliers, or a small sample.
- Your outcome is ordinal rather than continuous — a severity grade, a Likert-type score, or a similar ranked measurement.
If your groups' outcome data are approximately normally distributed, one-way ANOVA remains the more statistically powerful choice — the Kruskal-Wallis test is a fallback for when that assumption fails, not an automatically "safer" default to reach for regardless of your data.
Suitable Data Types and Independent-Group Designs
The Kruskal-Wallis test fits a specific structure: three or more groups made up of different, unrelated subjects, each contributing one outcome value.
| Study Design | Example |
|---|---|
| Comparing 3+ treatment arms | Recovery time across three surgical techniques |
| Comparing 3+ disease severity groups | A biomarker level across mild, moderate, and severe disease categories |
| Comparing 3+ dose groups | Symptom improvement across low, medium, and high drug doses |
It is not appropriate for comparing exactly two groups (use the Mann-Whitney U test, which gives a mathematically equivalent result to a two-group Kruskal-Wallis anyway), and not appropriate for repeated or related measurements on the same subjects across three or more conditions (use the Friedman test instead).
Kruskal-Wallis vs One-Way ANOVA
| Feature | One-Way ANOVA | Kruskal-Wallis Test |
|---|---|---|
| Data type | Continuous, normally distributed | Continuous or ordinal, no normality required |
| What is compared | Group means | Group mean ranks (approximates a median comparison) |
| Sensitivity to outliers | High | Low — ranking limits their influence |
| Test statistic | F | H (approximately chi-square distributed) |
| Post hoc test | Tukey's HSD / Bonferroni | Dunn's test |
Assumptions and Rank-Based Analysis
Three or more independent groups
Different, unrelated subjects contribute to each group.
At least ordinal measurement
The outcome must be capable of being ranked — a meaningful order, not just unordered categories.
Independence of observations
Both within and between groups — one subject's value shouldn't influence another's.
Similarly shaped distributions (for a clean median interpretation)
Needed for the result to be cleanly described as "a difference in medians" — the omnibus test itself remains valid more broadly even when this doesn't fully hold.
Adequate sample size per group
A common rule of thumb is at least 5 observations per group for the chi-square approximation to hold reasonably well.
Notice what's absent: there is no requirement that the raw outcome values follow a normal distribution — this is the entire reason the test exists as an alternative to one-way ANOVA. The mechanism that makes this possible is rank-based analysis: by converting every raw value into a rank before comparing groups, the test becomes insensitive to the actual shape of the underlying distribution and far less influenced by extreme outliers than a mean-based test would be.
How to Prepare Data for Three or More Groups
Kruskal-Wallis requires long format: one row per subject, with one column identifying the group (three or more categories) and one column for the outcome.
| Patient ID | Surgical Technique | Recovery Time (days) |
|---|---|---|
| 001 | Open | 16 |
| 002 | Laparoscopic | 9 |
| 003 | Robotic-assisted | 7 |
| ... | ... | ... |
Confirm the group variable is entered as a consistent categorical label (not accidentally coded as a number that software might treat as continuous), and that every subject appears exactly once, since the test assumes independent groups.
A Realistic Medical Example
A surgical research team compares recovery time (in days until return to normal activity) after hernia repair using three techniques: open repair, laparoscopic repair, and robotic-assisted repair, with 15 patients in each group (45 patients total). Recovery time is right-skewed — most patients recover within a fairly narrow window, but a handful take much longer — and a Shapiro-Wilk test confirms non-normality in each group (all p < .05), ruling out one-way ANOVA.
| Surgical Technique | n | Median Recovery (days) | IQR |
|---|---|---|---|
| Open | 15 | 14 | 12–18 |
| Laparoscopic | 15 | 9 | 7–11 |
| Robotic-assisted | 15 | 8 | 6–10 |
Open repair shows a clearly longer, more spread-out recovery than the other two techniques, while laparoscopic and robotic-assisted look fairly similar to each other — exactly the kind of pattern the Kruskal-Wallis test, followed by Dunn's post hoc comparisons, will formally confirm.
Step-by-Step Analysis Using StatClinic
Enter your data in long format
One row per patient, with a Surgical Technique column (three categories) and a Recovery Time column.
Confirm your study design
Tell StatClinic these are three or more independent groups — this routes the analysis to the correct family of tests.
Let StatClinic check normality automatically
StatClinic runs Shapiro-Wilk within each group and flags when one-way ANOVA's assumption isn't met.
Accept the recommended test
StatClinic recommends the Kruskal-Wallis test once normality is flagged as violated, or you can select it directly.
Review the full output
You'll get the H statistic, degrees of freedom, p-value, medians and IQRs for every group, and the effect size.
Run Dunn's post hoc automatically
If the omnibus result is significant, StatClinic runs Dunn's test with a multiple-comparison correction and generates ready-to-use Methods and Results text.
You can also run the calculation directly with the Kruskal-Wallis Test Calculator once your group data are ready.
Interpreting the H Statistic, Degrees of Freedom, P Value, Medians, IQRs, and Effect Size
For the hernia repair example, StatClinic's output might read: H(2) = 28.4, p < .001, η²H = 0.63.
| Output | What It Tells You |
|---|---|
| H statistic | A summary of how unevenly ranks are distributed across groups — larger values indicate a bigger difference; approximately chi-square distributed |
| Degrees of freedom (df) | Number of groups minus 1 — here, 3 groups − 1 = 2 |
| P-value | The probability of seeing this much rank imbalance (or more) if all groups truly had the same distribution |
| Medians & IQRs (each group) | The actual clinical quantities of interest — always report these alongside the p-value, never instead of it |
| Effect size (η²H) | Magnitude of the group difference independent of sample size; roughly 0.01 small, 0.06 medium, 0.14+ large |
Put together: the p-value confirms the differences across the three surgical groups are very unlikely to be due to chance; the medians (14 vs 9 vs 8 days) show open repair has a clearly longer typical recovery; and η²H = 0.63 confirms this is a large effect, not just a statistically detectable one in a large sample. What the omnibus result does not tell you is which specific pairs of groups differ — that requires the post hoc step below.
Dunn's Post Hoc Comparisons and Multiple-Testing Correction
A significant Kruskal-Wallis result means at least one group differs from the others — it does not identify which pair or pairs. Dunn's test is the standard follow-up: it uses the same pooled ranking from the omnibus test to compare every pair of groups, and — critically — applies a correction for the fact that multiple comparisons are being tested from the same dataset.
With three groups, there are 3 possible pairwise comparisons (open vs laparoscopic, open vs robotic, laparoscopic vs robotic); with four groups there would be 6, following k(k−1)/2. The most common correction is Bonferroni (dividing the significance threshold by the number of comparisons), though the less conservative Benjamini-Hochberg procedure is also widely used and accepted.
Open vs Laparoscopic: p < .001 (significant). Open vs Robotic-assisted: p < .001 (significant). Laparoscopic vs Robotic-assisted: p = .42 (not significant). This confirms open repair recovers significantly more slowly than either minimally invasive technique, while laparoscopic and robotic-assisted approaches don't differ meaningfully from each other.
How to Report the Methods and Results
A complete report states the test used, why it was chosen, the descriptive statistics for every group, and the full inferential result including any post hoc comparisons.
"Recovery time (days) was compared across three surgical techniques (open, laparoscopic, and robotic-assisted repair) using the Kruskal-Wallis test, as Shapiro-Wilk testing indicated recovery time was not normally distributed within each group (all p < .05)."
"Recovery time differed significantly across the three surgical groups, H(2) = 28.4, p < .001, η²H = 0.63. Median recovery time was longest for open repair (14 days, IQR 12–18), followed by laparoscopic (9 days, IQR 7–11) and robotic-assisted repair (8 days, IQR 6–10). Dunn's post hoc comparisons with Bonferroni correction showed that open repair had significantly longer recovery than both laparoscopic (p < .001) and robotic-assisted (p < .001) techniques, with no significant difference between the two minimally invasive approaches (p = .42)."
Common Mistakes
Mistake 1: Running Multiple Mann-Whitney Tests Instead of One Kruskal-Wallis
Comparing every pair of groups separately with Mann-Whitney U tests instead of a single omnibus Kruskal-Wallis test, inflating the overall false-positive rate.
Mistake 2: Reporting Means and SDs With a Rank-Based Test
Presenting group means and standard deviations alongside a test that is actually based on ranks, creating an internal inconsistency.
Mistake 3: Using Kruskal-Wallis for Repeated Measurements
Applying Kruskal-Wallis to three or more related measurements taken from the same subjects rather than independent groups.
Mistake 4: Skipping the Multiple-Comparison Correction in Post Hoc Testing
Reporting uncorrected pairwise p-values from Dunn's test, overstating how confident the specific pairwise conclusions actually are.
Mistake 5: Defaulting to Kruskal-Wallis Without Checking Normality First
Choosing the non-parametric test out of caution without ever testing whether one-way ANOVA's assumption actually failed, losing statistical power unnecessarily.
Mistake 6: Treating a Significant Omnibus Result as Telling You Which Groups Differ
Concluding "all three groups differ from each other" directly from a significant Kruskal-Wallis result, without running the necessary post hoc comparisons.
"Recovery time differed between the surgical groups (p < .001), so every technique differs significantly from every other technique."
"H(2) = 28.4, p < .001; Dunn's post hoc comparisons showed open repair differed significantly from both other techniques, but laparoscopic and robotic-assisted did not differ from each other (p = .42)."
Frequently Asked Questions
Related Articles
Once your Kruskal-Wallis test is run, these guides take you through the surrounding decisions:
Ready to Run Your Kruskal-Wallis Test?
Let StatClinic's AI Statistical Assistant confirm the right test, run your analysis, and write your results sentence. Free, no registration required.
Try StatClinic Free →