Launch StatClinic →
Statistical Tests

How to Perform the Kruskal–Wallis Test in Clinical Research

📖 13 min read 🗓 July 2026 ✓ Updated July 2026
S
StatClinic Editorial Team Statistical content for medical researchers and clinicians
Comparing three or more independent groups is one of the most common tasks in clinical research — three surgical techniques, three drug doses, three disease severity categories — but one-way ANOVA only handles it validly when your outcome is normally distributed. When it isn't, the Kruskal-Wallis test is the non-parametric method built exactly for this situation. This guide is a complete, standalone walkthrough: what the test actually does, when it applies, a full worked clinical example, and exactly how to run, interpret, and report it using StatClinic — no other reading required first.
Key Takeaways
  • 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 differsDunn'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.

In Plain Terms

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:

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 DesignExample
Comparing 3+ treatment armsRecovery time across three surgical techniques
Comparing 3+ disease severity groupsA biomarker level across mild, moderate, and severe disease categories
Comparing 3+ dose groupsSymptom 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

FeatureOne-Way ANOVAKruskal-Wallis Test
Data typeContinuous, normally distributedContinuous or ordinal, no normality required
What is comparedGroup meansGroup mean ranks (approximates a median comparison)
Sensitivity to outliersHighLow — ranking limits their influence
Test statisticFH (approximately chi-square distributed)
Post hoc testTukey's HSD / BonferroniDunn's test
Take-Home Points When normality genuinely holds, one-way ANOVA has more statistical power. When it doesn't, the Kruskal-Wallis test is the more valid choice — match the test to what your data can actually support, rather than defaulting to one or the other out of habit.

Assumptions and Rank-Based Analysis

1

Three or more independent groups

Different, unrelated subjects contribute to each group.

2

At least ordinal measurement

The outcome must be capable of being ranked — a meaningful order, not just unordered categories.

3

Independence of observations

Both within and between groups — one subject's value shouldn't influence another's.

4

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.

5

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 IDSurgical TechniqueRecovery Time (days)
001Open16
002Laparoscopic9
003Robotic-assisted7
.........

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 TechniquenMedian Recovery (days)IQR
Open151412–18
Laparoscopic1597–11
Robotic-assisted1586–10
What This Pattern Suggests

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

1

Enter your data in long format

One row per patient, with a Surgical Technique column (three categories) and a Recovery Time column.

2

Confirm your study design

Tell StatClinic these are three or more independent groups — this routes the analysis to the correct family of tests.

3

Let StatClinic check normality automatically

StatClinic runs Shapiro-Wilk within each group and flags when one-way ANOVA's assumption isn't met.

4

Accept the recommended test

StatClinic recommends the Kruskal-Wallis test once normality is flagged as violated, or you can select it directly.

5

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.

6

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.

OutputWhat It Tells You
H statisticA 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-valueThe 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.

Dunn's Post Hoc Results (Example)

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.

Caution Running several separate Mann-Whitney U tests instead of Dunn's test is a common shortcut that skips the multiple-comparison correction entirely, inflating the overall false-positive rate across the set of comparisons.

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.

Sample Methods Text

"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)."

Sample Results Text

"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.

✓ Fix: Run one Kruskal-Wallis test first, and only follow up with Dunn's test if the omnibus result is significant.

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.

✓ Fix: Report medians and interquartile ranges (IQR) to match what the test itself evaluated.

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.

✓ Fix: Use the Friedman test for repeated or related measurements across three or more conditions.

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.

✓ Fix: Always apply and report a correction (Bonferroni or Benjamini-Hochberg) for the post hoc comparisons.

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.

✓ Fix: Test normality within each group first — use one-way ANOVA if it genuinely holds.

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.

✓ Fix: A significant omnibus result only means at least one group differs — always follow up with Dunn's test to identify which pairs.
❌ Incorrect

"Recovery time differed between the surgical groups (p < .001), so every technique differs significantly from every other technique."

✅ Correct

"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

What is the null hypothesis of the Kruskal-Wallis test? +
The null hypothesis is that all groups come from populations with the same distribution, commonly interpreted as testing whether the groups share the same median. The alternative is that at least one group's distribution differs — the test doesn't identify which group differs on its own.
Can the Kruskal-Wallis test be used for ordinal data? +
Yes. It only requires that the outcome can be meaningfully ranked, making it suitable for ordinal outcomes like symptom severity scales as well as continuous outcomes that violate normality. It's not suitable for unordered nominal categories.
What sample size do I need per group for the Kruskal-Wallis test? +
A common rule of thumb is at least 5 observations per group for the chi-square approximation to hold reasonably well, though 15 or more per group is preferred for adequate power. A formal sample size calculation based on your expected effect size is more reliable than any fixed rule.
What is the difference between Kruskal-Wallis and the Mann-Whitney U test? +
Mann-Whitney compares exactly two independent groups. Kruskal-Wallis extends the same logic to three or more groups in a single omnibus test. Run on only two groups, Kruskal-Wallis produces a result mathematically equivalent to Mann-Whitney.
Does the Kruskal-Wallis test compare medians? +
In practice, yes, and this is how it's typically reported — accurate when groups have similarly shaped distributions. Strictly, it tests whether groups share the same distribution overall, so if shapes differ substantially, a significant result could partly reflect that rather than location alone.
What post hoc test should I use after Kruskal-Wallis? +
Dunn's test, since it uses the same pooled ranking as the omnibus test and applies a proper multiple-comparison correction (commonly Bonferroni or Benjamini-Hochberg). Running separate Mann-Whitney tests instead skips this correction.
What effect size should I report for the Kruskal-Wallis test? +
Epsilon-squared or eta-squared based on H (η²H) are most common. Using Cohen's adapted benchmarks, around 0.01 is small, 0.06 medium, and 0.14 or above large — conventions, not fixed clinical cutoffs.
Can the Kruskal-Wallis test be used for repeated measures? +
No. Kruskal-Wallis assumes independent groups. For three or more related measurements on the same subjects, use the Friedman test, which accounts for the within-subject correlation that Kruskal-Wallis does not model.
What happens if the group distributions have different shapes? +
The test remains valid as a general test of whether groups share the same distribution, but the clean "difference in medians" interpretation becomes less precise. Visually comparing distributions with boxplots alongside the test result helps confirm the right interpretation.
How do I report the Kruskal-Wallis test in APA format? +
A typical report includes H, degrees of freedom, p-value, and effect size, written as: H(2) = 28.4, p < .001, η²H = 0.63 — paired with the median and IQR for each group in the surrounding sentence.

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 →