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.

Understanding Kruskal-Wallis Test Reference

A valid analysis begins with the study design. Each observation must come from only one group, and one person or item must not influence another observation. For example, scores from three separate classes can be independent if no student appears twice.

Scores measured from the same students before, during, and after a course are not independent. Those repeated measurements need a different method, such as the Friedman test.

Random sampling or random assignment still matters. A rank based test can handle unusual data shapes, but it cannot repair a biased sample or a poorly controlled experiment.

The interpretation depends on the shapes of the group distributions. When groups have roughly similar spread and shape, a difference in ranks is often described as a difference in typical value or median. If one group is much more spread out, has a long tail, or has two clusters, the result may reflect those broader distribution differences instead.

This is an important limit. A significant result does not automatically prove that one group has a higher median. Students should inspect dot plots, box plots, or histograms before making a claim about medians.

Ranks reduce the effect of extreme values because only order matters. A very large value receives the highest rank, but its exact distance above the next value does not affect the calculation. Ties need care because equal values should receive equal treatment.

Their ranks are averaged, then the correction adjusts for the loss of rank variation caused by many ties. This issue is common with rating scales such as one to five satisfaction scores.

Software usually applies the correction automatically, but students should know that a large number of ties can make the usual large sample approximation less reliable. For small samples, an exact or permutation based p value can be more appropriate when available.

A significant overall result only says that the full set of groups is unlikely to have produced such rank differences by chance under the no difference model. It does not identify the groups responsible. Follow up pairwise rank comparisons can locate the differences.

These comparisons need a multiple testing adjustment, such as Bonferroni or Holm, because testing many pairs raises the chance of a false positive. In a report, include group sizes, a summary of each group, the test statistic, degrees of freedom, p value, and the post hoc method.

Reporting an effect size, such as epsilon squared, helps show whether the difference is practically important rather than merely statistically detectable. A tiny effect can have a small p value when the sample is large.