Why Compare Groups by Their Ranks?
When a study compares a quantitative outcome across several independent groups, a one-way analysis based on the original measurements is not always the chosen approach. The Kruskal–Wallis test instead pools the observations, ranks them, and measures how the rank totals are distributed across the groups. It is a rank-based procedure for comparing \(k\) independent populations, where \(k\) is at least 2.
For example, a researcher might compare the completion times of participants assigned independently to several different training programs. The numerical times are pooled and ranked from smallest to largest; the test statistic summarizes whether some programs tend to receive higher or lower ranks than others. The ranking uses the relative ordering of observations, not their original distances apart.
Hypotheses: Equality of Population Distributions
The general Kruskal–Wallis null hypothesis states that all \(k\) populations have the same distribution. The alternative is that at least one population distribution differs. This is an omnibus alternative: it does not specify which groups differ or the direction of any difference.
Here \(F_j\) denotes the distribution function for population \(j\). A common interpretation is that the groups differ in location, but that interpretation needs an additional condition: the population distributions should have the same shape and spread, differing only in location. Without that condition, a difference in distribution could reflect a difference in spread or shape as well as location. Therefore, the general alternative is not simply “the medians are different.”
The samples should be independent random samples, or should arise from a design that makes the group observations independent. The response must be measurable at least on an ordinal scale so that pooling and ranking are meaningful. The test is not appropriate for paired or repeated measurements treated as though they came from independent groups; those designs require methods that account for the pairing.
Defining the H Statistic
Once each observation has a pooled rank, the statistic compares each group’s average rank with the average of all pooled ranks. For ranks 1 through \(N\), the overall average rank is \((N+1)/2\). A group with a relatively high average rank contributes to a larger \(H\), as does a group with a relatively low average rank.
This definition tells you what to calculate from the group sizes and rank sums. It does not, by itself, provide a critical value or a p-value. Those require a reference distribution and conditions for using it, which are separate from constructing the statistic.
Why the Formula Measures Rank Separation
The formula can be understood by expressing the group rank sums as group average ranks. The average rank in group \(j\) is \(R_j/n_j\). The statistic is a scaled measure of how far those group averages are from the overall average rank.
To see the connection, start with the weighted sum of squared differences between each group’s average rank and the overall average rank. Since the group weights are \(n_j\), this quantity is
Expand the square. The pooled ranks always sum to \(N(N+1)/2\), including when ties are assigned average ranks. Therefore, \(\sum_jR_j=N(N+1)/2\), and the expansion becomes
Multiplying this result by \(12/[N(N+1)]\) gives exactly the stated formula for \(H\). Thus, \(H\) is a scaled measure of the weighted separation of the groups’ average ranks. If all group average ranks equal the overall average, the differences are zero and \(H=0\). Greater separation produces a larger value.
Calculating H From Rank Sums
Worked Example: Three Independent Training Groups
A hypothetical study independently assigns three groups of participants to different training programs. Their completion times, measured in minutes, have no ties. After pooling all nine observations and ranking them, the rank lists are: Program A, \(1,2,6\); Program B, \(3,7,8\); and Program C, \(4,5,9\). Calculate the Kruskal–Wallis statistic. Do not make a significance decision.
Method. Find each sample size and rank sum, check that the rank sums account for all pooled ranks, then substitute into the H formula.
Each group has \(n_j=3\), so \(N=3+3+3=9\). The rank sums are
The required pooled-rank total is \(9(10)/2=45\). The calculated sums total \(9+18+18=45\), so the rank-sum check passes.
Substitute \(N=9\), the three sample sizes, and the rank sums:
Therefore, \(H=2.4\). The group average ranks are \(9/3=3\), \(18/3=6\), and \(18/3=6\), compared with the overall average rank \((9+1)/2=5\). Their differences from 5 are consistent with a positive statistic. This example calculates the statistic only; it does not establish whether the observed value is statistically significant.
Check and mistake avoided. The rank sums add to 45, and the group sizes add to 9. A common mistake is to subtract \(N+1\) instead of \(3(N+1)\); here the required subtraction is \(3(10)=30\).
Worked Example: Unequal Sample Sizes and a Rank-Sum Check
A hypothetical analyst compares a measurement across three independent groups. After pooling and ranking 10 observations without ties, the rank lists are Group 1: \(1,4,7,8\); Group 2: \(2,5,6\); and Group 3: \(3,9,10\). Calculate \(H\), showing how the sample sizes enter the formula.
Method. Use the group-specific sample sizes in the denominators \(R_j^2/n_j\); do not assume equal group sizes.
The sample sizes are \(n_1=4\), \(n_2=3\), and \(n_3=3\), giving \(N=10\). The rank sums are
The ranks 1 through 10 must sum to \(10(11)/2=55\), and \(20+13+22=55\). The rank sums are consistent with the pooled ranks.
Now substitute each group’s own sample size:
Thus, \(H\approx1.6545\). The final value is rounded to four decimal places. The unequal sizes matter: using a common denominator for all three groups would not implement the formula.
Check and mistake avoided. Both checks pass: the sample sizes sum to 10 and the rank sums to 55. A tempting but incorrect response is to assign the third group the unused rank sum \(17\); the actual third rank list sums to \(22\). The rank total check catches that error before calculation.
Worked Example: Average Ranks for a Tie
Three independent groups produce the following hypothetical observations: Group A has \(1,2\), Group B has \(3,4\), and Group C has \(5,5,6,7\). Calculate the uncorrected H statistic using average ranks for the tied observations.
Method. Rank all eight observations in pooled order. The two observations equal to 5 occupy ranks 5 and 6, so each receives their average rank, \((5+6)/2=5.5\).
The group rank sums and sizes are therefore
Here \(N=2+2+4=8\), and the pooled rank sum is \(3+7+26=36=8(9)/2\). Substitution gives
The uncorrected statistic is \(H=6\). This is the statistic calculated from average ranks; a separate tie correction may be used when adjusting the statistic for ties. That adjustment is not part of this calculation.
Check and mistake avoided. The tied observations receive ranks 5.5 and 5.5, whose combined rank contribution is 11, the same as ranks 5 and 6. Assigning both tied observations rank 5, for example, would incorrectly reduce the total rank sum.
Reading the Statistic and Avoiding Misinterpretation
The H statistic summarizes how different the groups’ rank sums are from what would be expected if their average ranks were alike. A value of zero occurs when the group average ranks all equal the overall average rank. A larger value indicates greater rank separation, but the size of \(H\) alone does not determine a conclusion: a test decision requires a reference distribution or other calibration appropriate to the sampling conditions.
It is also important to distinguish the question tested from the summary used. The hypotheses concern population distributions. If the distributions have similar shapes and spreads, a location or median interpretation may be reasonable. If those shapes and spreads differ, a difference in rank patterns need not be a median difference.
The null says all population distributions are identical; the alternative says at least one differs.
Rank all observations together. Give tied observations their average pooled rank.
For each group, record \(n_j\) and add its pooled ranks to obtain \(R_j\).
Verify \(\sum n_j=N\) and \(\sum R_j=N(N+1)/2\), then substitute into the H formula.
Check Your Understanding
For each calculation, use the uncorrected H formula and show the rank-sum check before substituting.
- Three independent groups each have size 2. Their pooled rank sums are 5, 7, and 9. Find \(N\), check the total rank sum, and calculate \(H\). (Answer: \(N=6\), rank-sum total \(21\), \(H=1.1429\).)
- Three groups have sizes \(3,2,3\) and rank sums \(9,7,20\). Check the pooled rank total and calculate \(H\). (Answer: \(N=8\), rank-sum total \(36\), \(H=3.8056\).)
- Three groups each have size 3 and rank sums \(10,15,20\). Calculate \(H\) and state whether the hypotheses alone identify which group differs if the alternative is supported. (Answer: \(N=9\), rank-sum total \(45\), \(H=2.2222\); no, the omnibus alternative does not identify a particular group.)
- For group sizes \(2,2,4\), the pooled ranks in the groups are \((1,2)\), \((3,4)\), and \((5.5,5.5,7,8)\). Find the rank sums and calculate the uncorrected statistic. (Answer: rank sums \(3,7,26\), total \(36\), \(H=6\).)
- All six observations in three groups have the same value, with group sizes \(2,3,1\). Assign average ranks, find the rank sums, and calculate the uncorrected statistic. (Answer: each rank is \(3.5\); rank sums \(7,10.5,3.5\); \(H=0\).)