Kruskal-Wallis H Test: Step-by-Step Procedure
The H Statistic: Formula and Logicβ
The Kruskal-Wallis test statistic H measures the degree to which rank sums differ across groups relative to what would be expected by chance:
Where:
- = total number of observations across all groups
- = number of observations in group
- = sum of ranks in group
- = number of groups
Intuition: If all groups were drawn from the same population, their rank sums should be roughly proportional to their sample sizes. When rank sums diverge substantially from this expectation, H becomes large β indicating real group differences.
3.5 Step-by-Step Procedureβ
The Five Stepsβ
STEP 1: Rank all observations together across all groups combined, from lowest (rank 1) to highest. For tied scores, assign the average of the ranks those values would have occupied.
STEP 2: Calculate the rank sum for each group: .
STEP 3: Compute the H statistic using the formula above.
STEP 4: Find the critical value (Table H for small samples; chi-square table for large samples).
STEP 5: Make a decision: reject Hβ if H β₯ critical value; otherwise accept Hβ.
Unlike the Mann-Whitney U test (where smaller observed values indicate significance), the Kruskal-Wallis test is in the same direction as ANOVA: larger H = more evidence against Hβ. Reject Hβ when H exceeds the critical value.
Worked Example 1: Noise Conditions and Task Errors (Small Sample)β
Research Questionβ
Twelve participants were randomly assigned to three noise conditions (n = 4 each). Errors on a test were recorded. Does noise level affect performance?
| Condition A (Low Noise) | Condition B (Average Noise) | Condition C (Loud Noise) |
|---|---|---|
| 3 | 2 | 10 |
| 5 | 7 | 8 |
| 6 | 9 | 7 |
| 3 | 8 | 11 |
Step 1: Rank All 12 Scores Togetherβ
| Score | Rank | Notes |
|---|---|---|
| 2 | 1 | Condition B |
| 3 | 2.5 | Conditions A, A (tied β positions 2 & 3, mean = 2.5) |
| 3 | 2.5 | |
| 5 | 4 | Condition A |
| 6 | 5 | Condition A |
| 7 | 6.5 | Conditions B, C (tied β positions 6 & 7, mean = 6.5) |
| 7 | 6.5 | |
| 8 | 8.5 | Conditions B, C (tied β positions 8 & 9, mean = 8.5) |
| 8 | 8.5 | |
| 9 | 10 | Condition B |
| 10 | 11 | Condition C |
| 11 | 12 | Condition C |
Step 2: Rank Sums Per Groupβ
| Condition A | Rank | Condition B | Rank | Condition C | Rank |
|---|---|---|---|---|---|
| 3 | 2.5 | 2 | 1 | 10 | 11 |
| 5 | 4 | 7 | 6.5 | 8 | 8.5 |
| 6 | 5 | 9 | 10 | 7 | 6.5 |
| 3 | 2.5 | 8 | 8.5 | 11 | 12 |
| Ξ£Tβ = 14 | Ξ£Tβ = 26 | Ξ£Tβ = 38 |
Step 3: Compute Hβ
Step 4 & 5: Decisionβ
From Table H (k = 3, n = 4, 4, 4), the critical value at Ξ± = .05 is 5.692.
Since H = 5.54 < 5.692, we fail to reject Hβ.
Conclusion: There is no statistically significant difference in error rates across the three noise conditions (Low, Average, Loud).
3.6 Large Sample Considerations: Chi-Square Approximationβ
When to use the chi-square table instead of Table H:
Table H (exact Kruskal-Wallis table) has limited coverage:
- Up to 8 samples when k = 3
- Up to 4 samples when k = 4
- Up to 3 samples when k = 5
As sample sizes and group numbers increase beyond these limits, the H statistic approximates a chi-square distribution with degrees of freedom .
For small samples, using the chi-square approximation slightly reduces test power (increases likelihood of retaining a false Hβ). When exact tables are available, always prefer them.
Worked Example 2: Court Coordinator Training Needs (Large Sample)β
Research Questionβ
A court administrator asked 24 court coordinators across three counties to rate their training needs (Likert scale 1β7, where 7 = critical need). Do the three counties differ in training need?
Data:
| County A (n = 8) | County B (n = 10) | County C (n = 6) |
|---|---|---|
| 3, 1, 3, 1, 5, 4, 4, 2 | 7, 6, 5, 7, 3, 1, 6, 4, 4, 5 | 4, 2, 5, 1, 6, 7 |
Step 1: Rank All 24 Scores (Handling Ties)β
Scores of 1 occupy positions 1, 2, 3, 4 β mean rank = 2.5
Scores of 2 occupy positions 5, 6 β mean rank = 5.5
Scores of 3 occupy positions 7, 8, 9 β mean rank = 8
Scores of 4 occupy positions 10, 11, 12, 13 β mean rank = 12
Scores of 5 occupy positions 14, 15, 16, 17 β mean rank = 16.5
Scores of 6 occupy positions 18, 19, 20 β mean rank = 20
Scores of 7 occupy positions 21, 22, 23 β mean rank = 23 (Note: only 3 in this data set)
Step 2: Group Rank Sumsβ
| County A | County B | County C | |
|---|---|---|---|
| Rank Sum (Ξ£R) | 67.0 | 153.5 | 79.5 |
| (Ξ£R)Β² | 4,489 | 23,562.25 | 6,320.25 |
| n | 8 | 10 | 6 |
| (Ξ£R)Β²/n | 561.125 | 2,356.225 | 1,053.375 |
| Sum | 3,970.725 |
Step 3: Compute Hβ
Step 4 & 5: Chi-Square Decisionβ
Critical chi-square value at Ξ± = .05, df = 2: ΟΒ² = 5.991
Since H = 4.42 < 5.991, we fail to reject Hβ.
Conclusion: There is no significant difference in training needs among court coordinators across the three counties.
Kruskal-Wallis in SPSSβ
Analyse β Non-Parametric Tests β Legacy Dialogs β k Independent Samples
Stepsβ
- Analyse β Non-Parametric Tests β k Independent Samples
- Move the test variable (dependent variable, e.g., training need rating) to Test Variable List
- Move the grouping variable (e.g., county) to Grouping Variable
- Click Define Range β enter minimum and maximum group codes β Continue
- Under Test Type, ensure Kruskal-Wallis H is checked
- Click OK
Reading SPSS Outputβ
- Mean Rank table: Shows the average rank for each group β higher mean ranks indicate higher values
- Test Statistics table: Reports H statistic, df, and asymptotic significance (p-value)
- If p < Ξ± (e.g., < .05): reject Hβ β at least two groups differ significantly
Self-Assessment Questionsβ
Level 1 β Recallβ
-
What does the H statistic measure? In what direction is the Kruskal-Wallis test significant β when H is large or small?
-
When should the chi-square distribution be used to evaluate H instead of Table H?
-
In the noise-condition example above, what was the conclusion? Why was H = 5.54 not significant?
Level 2 β Applicationβ
-
Three therapy groups (CBT, n = 5; Mindfulness, n = 6; Psychodynamic, n = 5) are compared on a wellbeing scale. The combined rank sums are Tβ = 42, Tβ = 75, Tβ = 48, N = 16. Compute H. Would you use Table H or chi-square for the critical value?
-
In the court coordinator example, if County B's rank sum increased to 170 and County A's decreased to 51 (total N unchanged), would you expect H to increase or decrease? Why?
Level 3 β Critical Thinkingβ
-
A significant Kruskal-Wallis result tells you that at least two groups differ. What post-hoc procedure would you recommend to identify which specific pairs differ? (Hint: research Dunn's test or pairwise Mann-Whitney with Bonferroni correction.)
-
Compare the computational steps for Kruskal-Wallis H and one-way ANOVA F. Identify the corresponding elements in each calculation β where does ranking replace raw-score arithmetic?
π§ Memory Aidβ
The H Formula: "Twelve by N-total, sum squared-rank-sums over n, subtract three-N"
Quick checks:
- Always verify: (sum of all ranks = this value)
- Example: N = 12 β sum of ranks should = 12 Γ 13 / 2 = 78 (check: 14 + 26 + 38 = 78 β)
Small vs. Large sample decision:
- Small (within Table H limits) β use Table H critical value
- Large (beyond Table H) β use with df = k β 1
π External Resourcesβ
Foundational Readingβ
- π Wikipedia: Kruskal-Wallis test β Full derivation and post-hoc testing
- π Wikipedia: Chi-squared distribution β Understanding the large-sample approximation
Tutorialsβ
- π Penn State STAT 415: Kruskal-Wallis β University-level tutorial with worked examples
- π Statistics How To: Kruskal-Wallis Post Hoc Tests β What to do after a significant result
- π SPSS Tutorials: Kruskal-Wallis β Screenshot-by-screenshot SPSS guide
Videosβ
- π₯ Kruskal-Wallis Test Hand Calculation β YouTube β Manual calculation walkthrough
- π₯ Kruskal-Wallis Test in SPSS β YouTube β Full output interpretation
Research Articlesβ
- π Kruskal, W. H., & Wallis, W. A. (1952). Use of ranks in one-criterion variance analysis. JASA, 47(260), 583β621. (Foundational paper)
- π Conover, W. J., & Iman, R. L. (1981). Rank transformations as a bridge between parametric and nonparametric statistics. The American Statistician, 35(3), 124β129.
- π Benavoli, A., Corani, G., & Mangili, F. (2016). Should we really use post-hoc tests based on mean-ranks? Journal of Machine Learning Research, 17(5), 1β10.
Source PDFs:
- π Block-4/Unit-3.pdf β Pages 38β43
- π MPC-006 Statistics in Psychology