What Is the Kruskal-Wallis Test?
William Kruskal and W. Allen Wallis published the test in the Journal of the American Statistical Association in 1952. They built on Frank Wilcoxon's rank-sum idea and extended it to more than two groups. The test ranks every observation from 1 (smallest) to N (largest) across all groups combined. If the group medians were truly equal, you would expect the ranks to be spread evenly across the groups. When they are not, the H statistic grows large, and the p-value falls below the significance threshold.
The H statistic follows approximately a chi-square (χ²) distribution with df = k − 1, where k is the number of groups. This approximation works well when each group has at least five observations. For smaller samples, exact critical values from special Kruskal-Wallis tables should be used. The full framework for parametric vs nonparametric tests is covered in the Statistics Fundamentals guide to hypothesis testing.
- Also called: Kruskal-Wallis H test, nonparametric one-way ANOVA, rank-based ANOVA
- What it tests: Whether at least one group has a different median from the others
- When to use it: Three or more independent groups, ordinal or continuous outcome, normality not met or unverifiable
- Test statistic: H, which approximates χ² with df = k − 1
- Decision rule: Reject H0 if H > χ2(α, df) or equivalently if p-value < α.
- Post hoc test: Dunn's test with Bonferroni correction for pairwise comparisons
- Parametric equivalent: One-Way ANOVA
Assumptions of the Kruskal-Wallis Test
The Kruskal-Wallis test has four assumptions. These are considerably less restrictive than those of one-way ANOVA, which is why researchers reach for it when ANOVA assumptions cannot be met.
Independence
Observations must be independent — both within each group and between groups. Each subject or data point belongs to exactly one group. Repeated measures or matched data violate this assumption; use the Friedman test instead.
Ordinal or Continuous Outcome
The dependent variable must be at minimum ordinal — it must be meaningful to say one value is "greater than" another. The test works with continuous measurements and with ranked or Likert-scale data. It cannot be used with purely nominal outcomes (e.g., categories without order).
Three or More Independent Groups
There must be one independent variable with at least three categories. For exactly two groups, use the Mann-Whitney U test, which is the two-group nonparametric equivalent.
Similar Distribution Shapes
For the Kruskal-Wallis test to compare medians specifically, the distribution shapes across groups should be similar (even if not normal). If the shapes differ markedly, the test compares mean ranks rather than medians, and the interpretation changes accordingly.
Unlike one-way ANOVA, the Kruskal-Wallis test does not assume normally distributed residuals or equal variances (homoscedasticity). This makes it appropriate for skewed data, ordinal scales, and small samples where normality cannot be verified. See normality tests for guidance on when to switch from ANOVA to Kruskal-Wallis.
The H Statistic Formula
The Kruskal-Wallis H statistic is calculated from the rank sums of each group. The formula has two parts: the base H formula and an optional tie-correction factor applied when tied ranks are present.
N = total number of observations across all groups
k = number of groups
nᵢ = sample size of group i
Rᵢ = sum of ranks for group i
Tie-Correction Factor
When two or more observations have the same value, they receive the same average rank (e.g., two values tied for ranks 4 and 5 both get rank 4.5). Ties slightly reduce the value of H. The tie-corrected H is:
t = number of observations in each tied group
C = correction factor (always ≤ 1)
In practice, ties are common in real data and the correction matters most when ties are numerous. Statistical software (R, SPSS, SAS, Python's SciPy) applies this correction automatically. When calculating by hand, apply it whenever you have three or more tied values in a group.
The 7-Step Procedure
Step 1: State H₀ and H₁. Step 2: Check the four assumptions. Step 3: Rank all observations (1 to N). Step 4: Sum the ranks per group (R₁, R₂, …). Step 5: Calculate H (and apply tie correction if needed). Step 6: Find the p-value from the χ² distribution with df = k − 1. Step 7: If p < α, run Dunn's post hoc test.
State the Hypotheses
H₀: The population medians of all groups are equal. H₁: At least one group has a different median. You do not specify which group differs — that is for the post hoc test to determine.
Verify the Assumptions
Confirm independence, ordinal/continuous data, three or more groups, and similar distribution shapes. If the data has repeated measures, switch to the Friedman test. Review the full statistical assumptions guide if needed.
Pool and Rank All Observations
Combine every observation from all groups into one list. Rank them 1 to N from smallest to largest. For tied values, assign the mean of the ranks they would have occupied. Keep track of which original group each rank belongs to.
Calculate Group Rank Sums
Add up the ranks assigned to each group separately. Call these R₁, R₂, … Rk. As a check: R₁ + R₂ + … + Rk must equal N(N+1)/2.
Compute the H Statistic
Apply the H formula using N, k, the group sizes nᵢ, and the rank sums Rᵢ. If ties exist, divide H by the correction factor C to get the adjusted H.
Find the p-value and Make a Decision
Compare H to the chi-square distribution with df = k − 1 using a chi-square table. If H exceeds the critical value, or if p < α (typically 0.05), reject H₀. If p ≥ α, fail to reject H₀.
Post Hoc Analysis — Dunn's Test
A significant Kruskal-Wallis result only tells you that at least one group differs. Run Dunn's test to determine exactly which pairs differ, with Bonferroni-corrected p-values for each comparison.
Kruskal-Wallis Test Examples — 8 Fully Solved
All eight examples below follow the same 7-step structure. Data is original and chosen to reflect realistic distributions researchers encounter in practice. Calculations are shown in full. Where an example produces a significant result, Dunn's post hoc analysis is included.
Example 1 — Teaching Methods and Exam Scores (Education)
Scenario: A college instructor tests three teaching methods — lecture only (Group A), lecture + discussion (Group B), and flipped classroom (Group C). Fifteen students are randomly assigned (5 per group). End-of-term exam scores (out of 100) are recorded. Normality tests on these small samples are inconclusive, so the Kruskal-Wallis test is used. α = 0.05.
| Student | Group A (Lecture) | Group B (Discussion) | Group C (Flipped) |
|---|---|---|---|
| 1 | 58 | 72 | 81 |
| 2 | 62 | 68 | 85 |
| 3 | 55 | 75 | 79 |
| 4 | 60 | 70 | 88 |
| 5 | 57 | 66 | 83 |
Hypotheses: H₀: Median exam scores are equal across all three teaching methods. H₁: At least one teaching method produces a different median exam score.
Assumptions: 15 independent students, one each per group, exam scores are continuous, three groups — all met. No repeated measures.
Rank all 15 observations (smallest to largest):
| Score | Group | Rank |
|---|---|---|
| 55 | A | 1 |
| 57 | A | 2 |
| 58 | A | 3 |
| 60 | A | 4 |
| 62 | A | 5 |
| 66 | B | 6 |
| 68 | B | 7 |
| 70 | B | 8 |
| 72 | B | 9 |
| 75 | B | 10 |
| 79 | C | 11 |
| 81 | C | 12 |
| 83 | C | 13 |
| 85 | C | 14 |
| 88 | C | 15 |
Group rank sums:
R_A = 1+2+3+4+5 = 15
R_B = 6+7+8+9+10 = 40
R_C = 11+12+13+14+15 = 65
Check: 15+40+65 = 120 = 15×16/2 ✓
Calculate H:
N = 15, n_A = n_B = n_C = 5
H = [12/(15×16)] × [(15²/5) + (40²/5) + (65²/5)] − 3×16
H = [12/240] × [45 + 320 + 845] − 48
H = 0.05 × 1210 − 48 = 60.5 − 48 = H = 12.5
No ties, so no correction needed.
p-value: df = k−1 = 2. From the chi-square table, χ²(0.05, 2) = 5.991. Since H = 12.5 > 5.991, we reject H₀. p ≈ 0.002.
Dunn's post hoc test: With Bonferroni correction (3 pairs, α_adjusted = 0.05/3 = 0.0167), all three pairwise comparisons are significant: A vs B (p ≈ 0.019*), A vs C (p < 0.001), B vs C (p ≈ 0.008). The flipped classroom significantly outperforms both other methods.
✅ Conclusion: H(2) = 12.5, p = 0.002. The teaching method has a statistically significant effect on exam scores. Post hoc analysis confirms all three methods differ from each other, with the flipped classroom producing the highest scores (Mdn = 83) and the lecture-only method the lowest (Mdn = 60).
Example 2 — Patient Recovery Times (Medicine)
Scenario: A clinical trial tests three treatments for a knee injury: physical therapy alone (T1), physical therapy + ice (T2), and physical therapy + ultrasound (T3). Twelve patients are randomly assigned (4 per group). Days to full recovery are recorded. The distribution is right-skewed (some patients recover much later), making ANOVA inappropriate. α = 0.05.
| Patient | T1 (PT only) | T2 (PT + Ice) | T3 (PT + US) |
|---|---|---|---|
| 1 | 21 | 14 | 9 |
| 2 | 28 | 18 | 12 |
| 3 | 35 | 16 | 10 |
| 4 | 42 | 20 | 15 |
Hypotheses: H₀: Median recovery time is equal across T1, T2, and T3. H₁: At least one treatment produces a different median recovery time.
Rank all 12 observations:
| Days | Group | Rank |
|---|---|---|
| 9 | T3 | 1 |
| 10 | T3 | 2 |
| 12 | T3 | 3 |
| 14 | T2 | 4 |
| 15 | T3 | 5 |
| 16 | T2 | 6 |
| 18 | T2 | 7 |
| 20 | T2 | 8 |
| 21 | T1 | 9 |
| 28 | T1 | 10 |
| 35 | T1 | 11 |
| 42 | T1 | 12 |
Group rank sums:
R_T1 = 9+10+11+12 = 42
R_T2 = 4+6+7+8 = 25
R_T3 = 1+2+3+5 = 11
Check: 42+25+11 = 78 = 12×13/2 ✓
Calculate H:
N = 12, n = 4 per group
H = [12/(12×13)] × [(42²/4) + (25²/4) + (11²/4)] − 3×13
H = [12/156] × [441 + 156.25 + 30.25] − 39
H = 0.0769 × 627.5 − 39 = 48.25 − 39 = H = 9.25
Decision: df = 2, χ²(0.05, 2) = 5.991. H = 9.25 > 5.991. p ≈ 0.010. Reject H₀.
✅ Conclusion: H(2) = 9.25, p = 0.010. The treatment type significantly affects recovery time. The ultrasound group recovered fastest (Mdn = 11 days), followed by the ice group (Mdn = 17 days), with physical therapy alone the slowest (Mdn = 31.5 days).
Example 3 — Customer Satisfaction Across Stores (Business)
Scenario: A retail chain surveys customer satisfaction on a 1–10 Likert scale across four store locations (A, B, C, D). Likert data is ordinal, so the Kruskal-Wallis test is used rather than ANOVA. Four customers rated each store (n = 4 per group, N = 16). α = 0.05.
| Customer | Store A | Store B | Store C | Store D |
|---|---|---|---|---|
| 1 | 5 | 7 | 9 | 4 |
| 2 | 6 | 8 | 8 | 3 |
| 3 | 5 | 7 | 10 | 5 |
| 4 | 6 | 9 | 9 | 4 |
Hypotheses: H₀: Median satisfaction is equal across all four stores. H₁: At least one store has a different median satisfaction rating.
Rank all 16 observations (with ties shown):
| Rating | Store | Rank (tied = avg) |
|---|---|---|
| 3 | D | 1 |
| 4 | D | 2.5 |
| 4 | D | 2.5 |
| 5 | A | 5 |
| 5 | A | 5 |
| 5 | D | 5 |
| 6 | A | 7.5 |
| 6 | A | 7.5 |
| 7 | B | 9.5 |
| 7 | B | 9.5 |
| 8 | B | 11.5 |
| 8 | C | 11.5 |
| 9 | B | 14 |
| 9 | C | 14 |
| 9 | C | 14 |
| 10 | C | 16 |
Group rank sums:
R_A = 5+5+7.5+7.5 = 25
R_B = 9.5+9.5+11.5+14 = 44.5
R_C = 11.5+14+14+16 = 55.5
R_D = 1+2.5+2.5+5 = 11
Check: 25+44.5+55.5+11 = 136 = 16×17/2 ✓
Calculate H (before tie correction):
H = [12/(16×17)] × [(25²/4)+(44.5²/4)+(55.5²/4)+(11²/4)] − 3×17
H = [12/272] × [156.25+495.0625+770.0625+30.25] − 51
H = 0.04412 × 1451.625 − 51 = 64.07 − 51 = H ≈ 13.07
Tie correction: Ties: (3 ties for 5; 2 ties for 4; 2 ties for 6; 2 ties for 7; 2 ties for 8; 3 ties for 9)
C = 1 − [Σ(t³−t)]/(N³−N) = 1 − [(27−3)+(8−2)+(8−2)+(8−2)+(8−2)+(27−3)]/(4096−16)
C = 1 − [24+6+6+6+6+24]/4080 = 1 − 72/4080 = 1 − 0.01765 = 0.9824
H_corrected = 13.07/0.9824 ≈ 13.31
Decision: df = 3, χ²(0.05, 3) = 7.815. H = 13.31 > 7.815. p ≈ 0.004. Reject H₀.
✅ Conclusion: H(3) = 13.31, p = 0.004. Customer satisfaction differs significantly across stores. Store C has the highest median satisfaction (9.0), Store D the lowest (4.0). Post hoc comparisons show C vs D and B vs D are the strongest contrasts.
Example 4 — Crop Yields with Four Fertilizers (Agriculture)
Scenario: An agronomist tests four fertilizer types (Control, Nitrogen-only, NPK blend, Organic) on wheat yield (kg per plot) across 5 plots each (N = 20). Yields are skewed due to two plots experiencing drought conditions in one group. α = 0.05.
| Plot | Control | N-only | NPK | Organic |
|---|---|---|---|---|
| 1 | 32 | 41 | 55 | 38 |
| 2 | 28 | 45 | 60 | 42 |
| 3 | 35 | 39 | 58 | 36 |
| 4 | 30 | 43 | 52 | 40 |
| 5 | 22 | 47 | 57 | 44 |
Ranks (pooled, 1–20):
Sorted values: 22(1), 28(2), 30(3), 32(4), 35(5), 36(6), 38(7), 39(8), 40(9), 41(10), 42(11), 43(12), 44(13), 45(14), 47(15), 52(16), 55(17), 57(18), 58(19), 60(20)
Group rank sums:
Control (22,28,30,32,35): R = 1+2+3+4+5 = 15
N-only (39,41,43,45,47): R = 8+10+12+14+15 = 59
NPK (52,55,57,58,60): R = 16+17+18+19+20 = 90
Organic (36,38,40,42,44): R = 6+7+9+11+13 = 46
Check: 15+59+90+46 = 210 = 20×21/2 ✓
Calculate H:
H = [12/(20×21)] × [(15²/5)+(59²/5)+(90²/5)+(46²/5)] − 3×21
H = [12/420] × [45+696.2+1620+423.2] − 63
H = 0.02857 × 2784.4 − 63 = 79.55 − 63 = H = 16.55
Decision: df = 3, χ²(0.05, 3) = 7.815. H = 16.55 > 7.815. p ≈ 0.001. Reject H₀.
✅ Conclusion: H(3) = 16.55, p = 0.001. Fertilizer type has a significant effect on wheat yield. The NPK blend produced the highest yields (Mdn = 57 kg), the control group the lowest (Mdn = 30 kg). Dunn's test confirms NPK differs from all other groups (p < 0.05 for all three comparisons after Bonferroni correction).
Example 5 — Employee Productivity by Department (Business/HR)
Scenario: An HR manager records the monthly tasks completed by employees in three departments (Sales, Operations, and R&D), with 5 employees in each department. Because the distributions across departments differ in skewness, the Kruskal-Wallis test is preferred over one-way ANOVA. Use a significance level of α = 0.05.
| Employee | Sales | Operations | R&D |
|---|---|---|---|
| 1 | 48 | 62 | 34 |
| 2 | 55 | 58 | 30 |
| 3 | 51 | 65 | 38 |
| 4 | 60 | 70 | 33 |
| 5 | 45 | 66 | 36 |
Rank all 15 values (sorted):
30(1), 33(2), 34(3), 36(4), 38(5), 45(6), 48(7), 51(8), 55(9), 58(10), 60(11), 62(12), 65(13), 66(14), 70(15)
Group rank sums:
Sales (48, 55, 51, 60, 45): Ranks 7, 9, 8, 11, 6 → RSales = 41
Operations (62, 58, 65, 70, 66): Ranks 12, 10, 13, 15, 14 → ROps = 64
R&D (34, 30, 38, 33, 36): Ranks 3, 1, 5, 2, 4 → RRD = 15
Check: 41 + 64 + 15 = 120 = 15 × 16 / 2 ✓
Calculate H:
H = [12/(15×16)] × [(41²/5)+(64²/5)+(15²/5)] − 3×16
H = [12/240] × [336.2+819.2+45] − 48
H = 0.05 × 1200.4 − 48 = 60.02 − 48 = H = 12.02
Decision: df = 2, χ²(0.05, 2) = 5.991. H = 12.02 > 5.991. p ≈ 0.002. Reject H₀.
✅ Conclusion: H(2) = 12.02, p = 0.002. Productivity differs significantly across departments. Operations has the highest median task completion (64 tasks), while R&D has the lowest (34 tasks). Post hoc analysis indicates that the largest difference is between Operations and R&D.
Example 6 — Hospital Waiting Times (Healthcare)
Scenario: A hospital quality team records patient waiting times (minutes) at three emergency department triage categories: minor injuries, moderate injuries, and severe injuries. Five patients in each category. The team suspects right-skewed waiting times (some very long waits). α = 0.05.
| Patient | Minor | Moderate | Severe |
|---|---|---|---|
| 1 | 92 | 45 | 8 |
| 2 | 110 | 52 | 5 |
| 3 | 85 | 60 | 12 |
| 4 | 130 | 48 | 6 |
| 5 | 95 | 55 | 10 |
Ranks (sorted from lowest to highest wait time):
5(1), 6(2), 8(3), 10(4), 12(5), 45(6), 48(7), 52(8), 55(9), 60(10), 85(11), 92(12), 95(13), 110(14), 130(15)
Group rank sums:
Severe: 1+2+3+4+5 = 15
Moderate: 6+7+8+9+10 = 40
Minor: 11+12+13+14+15 = 65
Check: 15+40+65 = 120 ✓
H = 12.5 (same rank structure as Example 1, confirming formula)
Decision: H = 12.5 > χ²(0.05, 2) = 5.991. p ≈ 0.002. Reject H₀.
✅ Conclusion: H(2) = 12.5, p = 0.002. Waiting time differs significantly by triage category. Severe cases are seen fastest (Mdn = 8 min) and minor cases wait longest (Mdn = 95 min), consistent with a correctly functioning triage system.
Example 7 — Stress Scores Across Three Professions (Psychology)
Scenario: A researcher measures occupational stress (Perceived Stress Scale, 0–40 score, higher = more stressed) in three professional groups: teachers (n=5), nurses (n=5), and software engineers (n=5). The PSS is an ordinal-leaning scale with a non-normal distribution in this sample. α = 0.05.
| Participant | Teachers | Nurses | Engineers |
|---|---|---|---|
| 1 | 28 | 35 | 18 |
| 2 | 24 | 32 | 22 |
| 3 | 30 | 38 | 15 |
| 4 | 26 | 30 | 20 |
| 5 | 27 | 36 | 19 |
Ranks (sorted):
15(1), 18(2), 19(3), 20(4), 22(5), 24(6), 26(7), 27(8), 28(9), 30(10.5), 30(10.5), 32(12), 35(13), 36(14), 38(15)
Note: Two scores of 30 — one from Teachers, one from Nurses — both get rank (10+11)/2 = 10.5
Group rank sums:
Teachers (28,24,30,26,27): Ranks 9,6,10.5,7,8 → R_T = 40.5
Nurses (35,32,38,30,36): Ranks 13,12,15,10.5,14 → R_N = 64.5
Engineers (18,22,15,20,19): Ranks 2,5,1,4,3 → R_E = 15
Check: 40.5+64.5+15 = 120 ✓
H (uncorrected):
H = [12/(15×16)] × [(40.5²/5)+(64.5²/5)+(15²/5)] − 3×16
H = 0.05 × [328.05+832.05+45] − 48 = 0.05×1205.1 − 48 = 60.255 − 48 = 12.255
Tie correction: One pair of ties (t=2): Σ(t³−t) = (8−2) = 6
C = 1 − 6/(3375−15) = 1 − 6/3360 = 0.9982
H_corrected = 12.255/0.9982 ≈ 12.277
Decision: H = 12.28 > χ²(0.05, 2) = 5.991. p ≈ 0.002. Reject H₀.
✅ Conclusion: H(2) = 12.28, p = 0.002. Occupational stress differs significantly across professions. Nurses report the highest median stress (Mdn = 35), engineers the lowest (Mdn = 19). Post hoc Dunn's test: Nurses vs Engineers (p < 0.001), Teachers vs Engineers (p = 0.007), Nurses vs Teachers (p = 0.031) — all significant after Bonferroni correction.
Example 8 — Marketing Campaign Conversion Rates (Business)
Scenario: A digital marketing team runs three email campaign types (Standard newsletter, Personalized offer, Flash sale) across 6 audience segments each. Conversion rates (%) per segment are recorded. The distribution is skewed, with a few very high-converting segments. α = 0.05.
| Segment | Newsletter | Personalized | Flash Sale |
|---|---|---|---|
| 1 | 1.2 | 3.8 | 5.1 |
| 2 | 2.1 | 4.2 | 6.3 |
| 3 | 1.8 | 3.5 | 4.9 |
| 4 | 2.5 | 4.8 | 7.2 |
| 5 | 1.5 | 3.1 | 5.8 |
| 6 | 2.0 | 4.0 | 6.0 |
Hypotheses: H₀: Median conversion rate is equal across the three campaign types. H₁: At least one campaign type produces a different median conversion rate.
Ranks (1–18 from lowest to highest conversion rate):
Newsletter values get ranks 1–6, Personalized get ranks 7–12, Flash Sale get ranks 13–18 (no overlaps between groups in this dataset)
Group rank sums:
R_Newsletter = 1+2+3+4+5+6 = 21
R_Personalized = 7+8+9+10+11+12 = 57
R_Flash = 13+14+15+16+17+18 = 93
Check: 21+57+93 = 171 = 18×19/2 ✓
Calculate H:
H = [12/(18×19)] × [(21²/6)+(57²/6)+(93²/6)] − 3×19
H = [12/342] × [73.5+541.5+1441.5] − 57
H = 0.03509 × 2056.5 − 57 = 72.17 − 57 = H = 15.17
Decision: df = 2, χ²(0.05, 2) = 5.991. H = 15.17 > 5.991. p < 0.001. Reject H₀.
✅ Conclusion: H(2) = 15.17, p < 0.001. Campaign type significantly affects conversion rates. Flash sale campaigns have the highest median conversion rate (Mdn = 5.95%), standard newsletters the lowest (Mdn = 1.95%). All pairwise post hoc comparisons are significant, confirming each campaign type is distinct in performance.
Dunn's Post Hoc Test — Step by Step
When the Kruskal-Wallis test returns a significant result, you know at least one group differs, but not which one. Dunn's test compares every pair of groups using the same ranks from the original test. This is more appropriate than running separate Mann-Whitney U tests for each pair, because Dunn's test accounts for the fact that multiple comparisons inflate the Type I error rate. The standard correction is the Bonferroni method.
Dunn's Test Procedure
For each pair of groups i and j, compute the z-statistic:
R̄ᵢ = mean rank of group i
R̄ⱼ = mean rank of group j
N = total observations
Compare |z_ij| against the standard normal critical value at the Bonferroni-adjusted significance level α' = α / m, where m = k(k−1)/2 is the total number of pairwise comparisons. For three groups, m = 3; for four groups, m = 6.
Applying Dunn's test to Example 1 (three teaching methods, N = 15, n = 5 per group):
| Pair | R̄ᵢ | R̄ⱼ | SE | |z| | p (raw) | p (Bonferroni) | Significant? |
|---|---|---|---|---|---|---|---|
| A vs B | 3.0 | 8.0 | 2.0 | 2.50 | 0.012 | 0.037 | Yes |
| A vs C | 3.0 | 13.0 | 2.0 | 5.00 | <0.001 | <0.001 | Yes |
| B vs C | 8.0 | 13.0 | 2.0 | 2.50 | 0.012 | 0.037 | Yes |
SE = √[(15×16/12) × (1/5 + 1/5)] = √[20 × 0.4] = √8 = 2.0. All three pairs are significant at α = 0.05 after Bonferroni correction (α' = 0.0167; critical |z| = 2.394). Because |z| values of 2.50 exceed 2.394 for A vs B and B vs C, those differences are just significant at the adjusted level.
Kruskal-Wallis vs Other Tests
Kruskal-Wallis vs One-Way ANOVA
| Feature | Kruskal-Wallis Test | One-Way ANOVA |
|---|---|---|
| Type | Nonparametric | Parametric |
| Data requirement | Ordinal or continuous | Continuous (interval/ratio) |
| Normality assumption | Not required | Required (residuals normal) |
| Equal variances | Not required | Required (homoscedasticity) |
| What it tests | Medians (rank distributions) | Means |
| Test statistic | H (approximates χ²) | F |
| Post hoc test | Dunn's test | Tukey HSD, Bonferroni, Scheffé |
| Statistical power | ~95% of ANOVA when normal | Maximum when normal |
| Minimum group size | As low as 1 (exact tables) | Typically n ≥ 20 per group |
| When to choose | Non-normal, ordinal, outliers, small n | Normal data, continuous, large n |
Kruskal-Wallis vs Mann-Whitney U vs Friedman
| Feature | Kruskal-Wallis | Mann-Whitney U | Friedman Test |
|---|---|---|---|
| Groups | 3 or more | Exactly 2 | 3 or more |
| Design | Independent samples | Independent samples | Related samples |
| Parametric equivalent | One-way ANOVA | Independent t-test | Repeated measures ANOVA |
| Test statistic | H | U | Q |
| Use when | 3+ independent groups, nonparametric | 2 independent groups, nonparametric | Same subjects measured multiple times |
For the two-group case, see the Mann-Whitney U test guide. For related samples across multiple conditions, the Friedman test is the nonparametric alternative to repeated measures ANOVA.
Real-Life Applications of the Kruskal-Wallis Test
Healthcare & Medicine
Comparing pain scores (NRS) across drug treatment groups; recovery times between surgical techniques; side effect severity ratings across dosage levels. Pain and severity scales are inherently ordinal.
Education Research
Comparing test scores across teaching methods with small class sizes; analyzing Likert-scale student engagement ratings across three course formats; evaluating performance across school types.
Psychology & Social Science
Comparing stress, depression, or anxiety scale scores across three diagnostic groups; rating scale responses on quality-of-life instruments; attitude surveys across demographic groups.
Agriculture
Crop yield comparisons across fertilizer treatments or irrigation methods when plot sizes are small and yield distributions are skewed. Yield data frequently contains extreme outliers due to weather variation.
Marketing & Business
Comparing customer satisfaction Likert scores across brands or service channels; conversion rates across three advertising formats; Net Promoter Score differences across regional offices.
Manufacturing & Quality
Comparing defect rates (counts, which are discrete) across three production lines; customer complaint severity ratings across factory shifts; inspection scores across supplier grades.
When to Use the Kruskal-Wallis Test
Decision Tree — Should You Use the Kruskal-Wallis Test?
The RANK Framework for the Kruskal-Wallis Test
The RANK framework is an original mnemonic for executing the Kruskal-Wallis test correctly, from data checking through to final reporting.
RANK — The 8-Step Kruskal-Wallis Framework
Common Mistakes with the Kruskal-Wallis Test
| Mistake | What Goes Wrong | Correct Approach |
|---|---|---|
| Running Kruskal-Wallis on paired data | Violates the independence assumption; inflated Type I error | Use the Friedman test for repeated measures or matched groups |
| Skipping the tie correction | H is underestimated, reducing power when many ties exist | Apply C = 1 − Σ(t³−t)/(N³−N) whenever three or more tied values appear |
| Running multiple Mann-Whitney U tests instead of Dunn's test | Multiplies the Type I error rate; α inflates beyond 0.05 with each additional test | Use Dunn's test with Bonferroni correction for all pairwise post hoc comparisons |
| Treating Kruskal-Wallis as always testing medians | When distribution shapes differ markedly, the test compares mean ranks, not medians | Verify similar distribution shapes; report the test as comparing rank distributions if shapes differ |
| Using it for nominal (unordered) data | Ranking nominal categories is meaningless; results are uninterpretable | Use the chi-square test of independence for unordered categorical outcomes |
| Not reporting effect size | The reader has no sense of practical significance | Report η²_H = (H − k + 1)/(N − k). Values of 0.01, 0.06, 0.14 are small, medium, large. |
| Using it when ANOVA is appropriate | Kruskal-Wallis loses ~5% efficiency compared to ANOVA when normality holds | When normality is confirmed (e.g., by Shapiro-Wilk test), prefer one-way ANOVA for its higher power |
Kruskal-Wallis Test Calculator
Enter your group data below — one value per line for each group. The calculator ranks all observations, computes the H statistic with tie correction, finds the p-value from the chi-square distribution, and makes a decision at your chosen α level.
Kruskal-Wallis H Statistic Calculator
Entity & Formula Glossary
| Term / Entity | Definition | In the Kruskal-Wallis Context |
|---|---|---|
| Kruskal-Wallis Test | Nonparametric one-way analysis of variance based on ranks | The primary test covered on this page |
| H Statistic | The Kruskal-Wallis test statistic; approximates χ² under H₀ | H = [12/(N(N+1))] × Σ[Rᵢ²/nᵢ] − 3(N+1) |
| Rank | Position of an observation when all values are sorted 1 to N | Tied values receive the mean of their occupied ranks |
| Median | Middle value of a sorted dataset; 50th percentile | The Kruskal-Wallis test compares medians (when shapes are similar) |
| Independent Samples | Each observation belongs to exactly one group with no pairing | Required assumption for the Kruskal-Wallis test |
| Nonparametric Test | A test that does not assume a specific population distribution | Kruskal-Wallis requires no normality assumption |
| One-Way ANOVA | Parametric test comparing means of 3+ independent groups | The parametric equivalent; use when normality holds |
| Dunn's Test | Post hoc pairwise comparison test using Kruskal-Wallis ranks | Run after a significant Kruskal-Wallis to identify differing pairs |
| Effect Size (η²_H) | Proportion of variance in ranks explained by group membership | η²_H = (H − k + 1)/(N − k) |
| p-value | Probability of observing H this large if H₀ were true | Compare to α to decide whether to reject H₀ |
| Null Hypothesis (H₀) | The default claim of no difference | H₀: All group medians are equal |
| Alternative Hypothesis (H₁) | The claim being tested | H₁: At least one group median differs |
| Tie Correction | Adjustment to H when multiple observations share the same value | C = 1 − Σ(t³−t)/(N³−N); H_adj = H/C |
| Chi-Square Distribution | The distribution H approximates under H₀ | df = k − 1 where k = number of groups |
| Bonferroni Correction | Divides α by the number of comparisons to control Type I error | α' = α/m where m = k(k−1)/2 comparisons |
| William Kruskal | American statistician (1919–2005), co-developer of the test | Published the test with W. Allen Wallis in 1952 |
| W. Allen Wallis | American economist and statistician (1912–1998) | Co-developer; also served as US Undersecretary of State for Economic Affairs |
How to Report Kruskal-Wallis Results
Statistical reporting standards ask for the test statistic, degrees of freedom, p-value, and a measure of effect size. Here is the APA 7th edition format, using Example 1's results:
APA 7th Edition Reporting Format
Template
A Kruskal-Wallis test was conducted to compare [outcome] among [k groups]. There was a statistically significant difference between the groups, H([df]) = [H], p = [p], η²_H = [value]. Post hoc pairwise comparisons using Dunn's test with Bonferroni correction indicated that [Group X] (Mdn = [value]) differed significantly from [Group Y] (Mdn = [value], p = [value]).
Example 1 Report
"A Kruskal-Wallis test was conducted to compare exam scores among three teaching methods (lecture only, discussion-based, and flipped classroom). There was a statistically significant difference between the groups, H(2) = 12.5, p = .002, η²_H = .875. Post hoc pairwise comparisons using Dunn's test with Bonferroni correction indicated that the flipped classroom (Mdn = 83) produced significantly higher scores than the discussion method (Mdn = 72, p = .037) and the lecture method (Mdn = 60, p < .001)."
Frequently Asked Questions
The Kruskal-Wallis test is a nonparametric statistical test that compares the medians of three or more independent groups. It is the rank-based equivalent of one-way ANOVA and does not require the data to be normally distributed. All observations from all groups are pooled and ranked together; the test statistic H measures whether the rank sums differ more than expected by chance. When H is large (and p < α), at least one group has a different median. The test was developed by William Kruskal and W. Allen Wallis and published in the Journal of the American Statistical Association in 1952.
Choose the Kruskal-Wallis test when at least one of these conditions is present: your outcome is ordinal (like Likert scale ratings); your continuous data is clearly non-normal (skewed, heavy tails, outliers); your sample size per group is too small to verify normality reliably (roughly n < 20); or a Shapiro-Wilk test or Q-Q plot shows normality is violated. When data is continuous and normally distributed, one-way ANOVA is preferred because it has slightly more statistical power. The difference in power is small — about 5% — when normality actually holds.
A significant result (p < α) means that at least one group has a statistically different median (or rank distribution) from at least one other group. It does not identify which groups differ — that requires a post hoc test such as Dunn's test. It also does not mean the difference is practically important; report effect size (η²_H) alongside the p-value so readers can judge the magnitude of the difference.
The H statistic has no fixed interpretation on its own — it must be compared to a critical value from the chi-square distribution with df = k − 1, where k is the number of groups. A larger H value means the rank sums deviate more from what equal medians would predict. If H > χ²(α, df), the result is significant and you reject H₀. Most researchers report H, degrees of freedom, and the p-value together rather than interpreting H in isolation.
Dunn's test is a post hoc pairwise comparison test used after a significant Kruskal-Wallis result to identify exactly which group pairs differ. It uses the same ranks from the original test and applies the Bonferroni correction (or other corrections such as Holm or Benjamini-Hochberg) to control the Type I error rate across multiple comparisons. Dunn's test is the standard post hoc choice for the Kruskal-Wallis test, available in R (via the dunn.test or FSA package), Python (via SciPy's posthoc_dunn), SPSS, and SAS.
Yes. The Kruskal-Wallis test handles unequal group sizes (unbalanced designs) without any modification. The formula uses the individual group sizes nᵢ explicitly. However, very small groups (n = 1 or 2) reduce power substantially, and extremely unequal sizes can affect the interpretation when distributions also differ in shape. For exact Kruskal-Wallis critical values with very small samples, use published nonparametric tables rather than the chi-square approximation.
Both are nonparametric tests for three or more groups, but they differ in design. The Kruskal-Wallis test is for independent samples — each subject appears in only one group. The Friedman test is for related samples — the same subjects (or matched subjects) are measured under each condition. Using Kruskal-Wallis on repeated-measures data violates the independence assumption and gives incorrect results; the Friedman test is the correct nonparametric alternative to repeated measures ANOVA. See the full comparison in the parametric vs nonparametric tests guide.
In R:
kruskal.test(score ~ group, data = df)
# Post hoc:
library(dunn.test)
dunn.test(df$score, df$group, method = "bonferroni")
In Python (SciPy):
from scipy import stats
H, p = stats.kruskal(group1, group2, group3)
# Post hoc (scikit-posthocs):
import scikit_posthocs as sp
sp.posthoc_dunn([group1, group2, group3], p_adjust='bonferroni')
The most widely reported effect size for the Kruskal-Wallis test is eta-squared (η²_H), calculated as η²_H = (H − k + 1) / (N − k). Using Cohen's (1988) guidelines adapted for this statistic: values around 0.01 indicate a small effect, 0.06 a medium effect, and 0.14 a large effect. Some researchers also report ε² (epsilon-squared) = (H − k + 1)/(N − k), which gives the same formula. Always report the effect size alongside H and p so readers can judge practical significance independently of sample size.
The chi-square approximation for the p-value works reasonably well when each group has at least 5 observations. With smaller groups, the chi-square p-value is not accurate; use exact Kruskal-Wallis critical value tables instead (published in most nonparametric statistics textbooks, including Conover's Practical Nonparametric Statistics). Some software offers exact p-values for small samples via Monte Carlo permutation. There is no strict minimum, but power will be very low with n < 3 per group regardless of method.
Sources and References
All formulas, examples, and procedures on this page are derived from primary statistical literature and leading educational institutions. The Kruskal-Wallis H formula and tie-correction factor are verified against the NIST Engineering Statistics Handbook and the original 1952 publication.
- Kruskal, W.H. and Wallis, W.A. (1952) — "Use of ranks in one-criterion variance analysis." Journal of the American Statistical Association, 47(260), 583–621. JSTOR
- NIST Engineering Statistics Handbook — Section 7.4.3: Kruskal-Wallis Test. National Institute of Standards and Technology. itl.nist.gov
- Penn State STAT 415 — Nonparametric Methods. Penn State Eberly College of Science. online.stat.psu.edu
- Conover, W.J. (1999) — Practical Nonparametric Statistics (3rd ed.). Wiley. Standard reference for Kruskal-Wallis exact tables and Dunn's test procedure.
- Dunn, O.J. (1964) — "Multiple comparisons using rank sums." Technometrics, 6(3), 241–252. Original source for the Dunn's test procedure.
- SciPy Documentation — scipy.stats.kruskal. Scientific Python. docs.scipy.org
- OpenStax Introductory Statistics — Chapter 13: Nonparametric Tests. Rice University. openstax.org