Skip to main content

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:

H=12N(N+1)[βˆ‘i=1k(Ξ£Ri)2ni]βˆ’3(N+1)H = \frac{12}{N(N+1)} \left[ \sum_{i=1}^{k} \frac{(\Sigma R_i)^2}{n_i} \right] - 3(N+1)

Where:

  • NN = total number of observations across all groups
  • nin_i = number of observations in group ii
  • Ξ£Ri\Sigma R_i = sum of ranks in group ii
  • kk = 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: T1,T2,...,TkT_1, T_2, ..., T_k.

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β‚€.

Direction of the Test

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)
3210
578
697
3811

Step 1: Rank All 12 Scores Together​

ScoreRankNotes
21Condition B
32.5Conditions A, A (tied β€” positions 2 & 3, mean = 2.5)
32.5
54Condition A
65Condition A
76.5Conditions B, C (tied β€” positions 6 & 7, mean = 6.5)
76.5
88.5Conditions B, C (tied β€” positions 8 & 9, mean = 8.5)
88.5
910Condition B
1011Condition C
1112Condition C

Step 2: Rank Sums Per Group​

Condition ARankCondition BRankCondition CRank
32.5211011
5476.588.5
6591076.5
32.588.51112
Ξ£T₁ = 14Ξ£Tβ‚‚ = 26Ξ£T₃ = 38

Step 3: Compute H​

H=1212(13)[1424+2624+3824]βˆ’3(13)H = \frac{12}{12(13)} \left[ \frac{14^2}{4} + \frac{26^2}{4} + \frac{38^2}{4} \right] - 3(13)

H=12156[49+169+361]βˆ’39H = \frac{12}{156} \left[ 49 + 169 + 361 \right] - 39

H=0.0769Γ—579βˆ’39=44.54βˆ’39=5.54H = 0.0769 \times 579 - 39 = 44.54 - 39 = \mathbf{5.54}

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 df=kβˆ’1df = k - 1.

HβˆΌΟ‡(kβˆ’1)2forΒ largeΒ samplesH \sim \chi^2_{(k-1)} \quad \text{for large samples}

Power Consideration

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, 27, 6, 5, 7, 3, 1, 6, 4, 4, 54, 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 ACounty BCounty C
Rank Sum (Ξ£R)67.0153.579.5
(Ξ£R)Β²4,48923,562.256,320.25
n8106
(Ξ£R)Β²/n561.1252,356.2251,053.375
Sum3,970.725

Step 3: Compute H​

H=1224(25)Γ—3970.725βˆ’3(25)H = \frac{12}{24(25)} \times 3970.725 - 3(25)

H=0.02Γ—3970.725βˆ’75=79.415βˆ’75=4.42H = 0.02 \times 3970.725 - 75 = 79.415 - 75 = \mathbf{4.42}

Step 4 & 5: Chi-Square Decision​

df=kβˆ’1=3βˆ’1=2df = k - 1 = 3 - 1 = 2

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​

  1. Analyse β†’ Non-Parametric Tests β†’ k Independent Samples
  2. Move the test variable (dependent variable, e.g., training need rating) to Test Variable List
  3. Move the grouping variable (e.g., county) to Grouping Variable
  4. Click Define Range β†’ enter minimum and maximum group codes β†’ Continue
  5. Under Test Type, ensure Kruskal-Wallis H is checked
  6. 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​

  1. What does the H statistic measure? In what direction is the Kruskal-Wallis test significant β€” when H is large or small?

  2. When should the chi-square distribution be used to evaluate H instead of Table H?

  3. In the noise-condition example above, what was the conclusion? Why was H = 5.54 not significant?

Level 2 β€” Application​

  1. 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?

  2. 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​

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

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

H=12N(N+1)⏟scalingΒ factorβˆ‘Ti2ni⏟weightedΒ rankΒ sumsβˆ’3(N+1)⏟correctionΒ termH = \underbrace{\frac{12}{N(N+1)}}_{\text{scaling factor}} \underbrace{\sum \frac{T_i^2}{n_i}}_{\text{weighted rank sums}} - \underbrace{3(N+1)}_{\text{correction term}}

Quick checks:

  • Always verify: T1+T2+...+Tk=N(N+1)/2T_1 + T_2 + ... + T_k = N(N+1)/2 (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 Ο‡2\chi^2 with df = k βˆ’ 1

πŸ“š External Resources​

Foundational Reading​

Tutorials​

Videos​

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: