Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

The Kruskal-Wallis test is a nonparametric method for comparing three or more independent groups when a one-way ANOVA is not appropriate. It is especially useful when the response variable is ordinal, strongly skewed, or affected by outliers. This cheat sheet helps students identify when to use the test, compute the test statistic, and interpret results correctly.

It also connects the test to post hoc comparisons after a significant result.

The core idea is to rank all observations together, then compare the average ranks across groups. If the groups come from similar distributions, their rank averages should be close. The main statistic is H=12N(N+1)i=1kRi2ni3(N+1)H = \frac{12}{N(N+1)}\sum_{i=1}^{k}\frac{R_i^2}{n_i} - 3(N+1), with a tie correction when needed.

Under the null hypothesis and typical large-sample conditions, HH is compared to a chi-square distribution with df=k1df = k - 1.

Key Facts

  • Use the Kruskal-Wallis test to compare k3k \ge 3 independent groups when the response is ordinal or a continuous variable that does not meet ANOVA assumptions.
  • The null hypothesis is H0H_0: all groups have the same distribution, often interpreted as equal population medians when group distributions have similar shapes.
  • The alternative hypothesis is HaH_a: at least one group tends to have larger or smaller values than at least one other group.
  • Rank all NN observations from smallest to largest across all groups, assigning average ranks to tied values.
  • For group ii, let nin_i be the group size and RiR_i be the sum of ranks in that group.
  • The Kruskal-Wallis statistic is H=12N(N+1)i=1kRi2ni3(N+1)H = \frac{12}{N(N+1)}\sum_{i=1}^{k}\frac{R_i^2}{n_i} - 3(N+1).
  • When ties occur, use the corrected statistic Hc=H1(tj3tj)N3NH_c = \frac{H}{1 - \frac{\sum(t_j^3 - t_j)}{N^3 - N}}, where tjt_j is the size of tie group jj.
  • For large enough samples, compare HH or HcH_c to χk12\chi^2_{k-1} and reject H0H_0 when the pp-value is less than α\alpha.

Vocabulary

Kruskal-Wallis test
A nonparametric hypothesis test used to compare three or more independent groups using ranks instead of raw data values.
Rank sum
The rank sum RiR_i is the total of all ranks assigned to observations in group ii.
Degrees of freedom
For the Kruskal-Wallis test, the degrees of freedom are df=k1df = k - 1, where kk is the number of groups.
Tie correction
A tie correction adjusts the HH statistic when equal data values create tied ranks.
Post hoc comparison
A post hoc comparison tests which specific group pairs differ after the overall Kruskal-Wallis test is significant.
Nonparametric test
A nonparametric test makes fewer assumptions about the population distribution than a parametric test such as ANOVA.

Common Mistakes to Avoid

  • Using Kruskal-Wallis for paired or repeated-measures data is wrong because the test assumes independent groups. Use a related-samples method such as the Friedman test when the same subjects are measured repeatedly.
  • Interpreting a significant result as proof that all group medians are different is wrong because the test only shows that at least one group differs in distribution or location.
  • Forgetting to rank all observations together is wrong because ranks must be assigned across the full combined sample, not separately within each group.
  • Ignoring ties can give an inaccurate test statistic because tied values reduce the variability of ranks. Apply the tie-corrected statistic HcH_c when ties are present.
  • Running many pairwise tests without adjustment is wrong because it inflates the Type I error rate. Use a correction such as Bonferroni, Holm, or Dunn's test with adjusted pp-values.

Practice Questions

  1. 1 Three independent groups have n1=5n_1 = 5, n2=5n_2 = 5, n3=5n_3 = 5, and rank sums R1=24R_1 = 24, R2=39R_2 = 39, R3=57R_3 = 57. Compute H=12N(N+1)i=1kRi2ni3(N+1)H = \frac{12}{N(N+1)}\sum_{i=1}^{k}\frac{R_i^2}{n_i} - 3(N+1).
  2. 2 A Kruskal-Wallis test compares k=4k = 4 independent groups and gives H=9.80H = 9.80. What are the degrees of freedom, and how would you use χdf2\chi^2_{df} to find or approximate the pp-value?
  3. 3 A data set has N=12N = 12 observations with one tie group of size t1=3t_1 = 3 and another tie group of size t2=2t_2 = 2. Compute the tie correction denominator factor 1(tj3tj)N3N1 - \frac{\sum(t_j^3 - t_j)}{N^3 - N}.
  4. 4 A researcher compares exam scores from three different classes and finds a significant Kruskal-Wallis result. Explain why this result does not by itself identify which classes differ.