Why Unequal Group Sizes Matter
The Kruskal–Wallis test compares the rank distributions of independent groups. Its calculation begins by ranking all observations together, but the groups do not necessarily contribute the same number of observations. Consequently, each group’s rank sum must be scaled by that group’s own size. Substituting a common denominator, or treating each rank sum as if it came from an equally sized group, changes the statistic.
This matters in practical data collection: for example, a hypothetical study might record different numbers of service times at three branches, or different numbers of claim-processing times under three procedures. Unequal group sizes are permitted; the calculation accounts for them directly.
The test is applied to independent samples whose observations can be ordered. Under the null hypothesis, the groups have the same distribution. For sufficiently large samples, the reference distribution of \(H\), or \(H_c\) when ties are corrected, is approximately chi-square with \(k-1\) degrees of freedom. The approximation can be poor with very small samples; in that setting, use an appropriate exact procedure if one is available. If all observations are tied, \(C=0\), so the tie-corrected statistic is undefined: the ranks contain no information for distinguishing the groups.
How the Unequal-Size Formula Works
The factor \(R_j^2/n_j\) can be written as \(n_j\bar R_j^2\). Thus a group’s contribution depends both on its mean rank and on how many observations produced that mean rank. A group with twice as many observations is not treated as though its rank sum came from the same sample size as a smaller group.
A useful justification comes from expressing the statistic in terms of deviations of group mean ranks from the pooled mean rank \((N+1)/2\). The sum of the pooled ranks is \(N(N+1)/2\), so
Multiplying this expression by \(12/[N(N+1)]\) gives exactly \(H\), because the final term becomes \(3(N+1)\). This shows why group size enters the calculation: the statistic aggregates squared departures of group mean ranks from the pooled mean, weighting each departure by the number of observations in that group.
Rank all observations together. For ties, assign each observation in a tied set the average of the ranks it occupies.
Compute its size \(n_j\), rank sum \(R_j\), and, if useful, mean rank \(R_j/n_j\).
Use \(R_j^2/n_j\) separately for every group, then apply the formula for \(H\).
When ties are present and \(C>0\), compute \(H_c=H/C\). Compare the statistic with the chi-square reference distribution only when its approximation is appropriate.
Worked Calculations
Worked Example: Unequal Groups With No Ties
Method: pool the observations, use each group’s own size in \(R_j^2/n_j\), and compare the resulting statistic with the chi-square approximation. A hypothetical operations study records response times (in minutes) for three independent procedures. The pooled ranks are: group A has ranks 1 and 4; group B has ranks 2, 5, and 8; group C has ranks 3, 6, 7, and 9. There are no ties. At significance level \(\alpha=0.05\), calculate the statistic and approximate p-value. The common mistake to avoid is dividing all squared rank sums by the same sample size.
The sizes are \(n_A=2\), \(n_B=3\), and \(n_C=4\), so \(N=2+3+4=9\). The rank sums are
Check the rank total: \(5+15+25=45\), which equals \(9(10)/2=45\), the sum of ranks from 1 to 9. Now use the separate group sizes:
There are \(k-1=2\) degrees of freedom. For a chi-square variable with 2 degrees of freedom, the upper-tail probability at 2.5 is \(e^{-2.5/2}\approx0.2865\). Thus the approximate p-value is 0.2865, which exceeds 0.05. This calculation does not provide evidence against the null hypothesis at the stated level. As a check, the statistic is nonnegative, and the rank sums add to the required pooled total.
Worked Example: Unequal Groups With Ties
Method: assign average ranks to ties, calculate \(H\) with the actual group sizes, then apply the tie correction. In a hypothetical study, group A has observations 11, 12, and 17; group B has 12, 13, and 18; group C has 14, 14, 19, and 19. Calculate the corrected statistic and its approximate p-value. The mistake to avoid is either ranking ties consecutively instead of averaging their ranks or omitting the correction.
There are \(N=3+3+4=10\) observations. In pooled order, the values and ranks are: 11 gets rank 1; the two 12s get average rank \((2+3)/2=2.5\); 13 gets rank 4; the two 14s get average rank \((5+6)/2=5.5\); 17 gets rank 7; 18 gets rank 8; and the two 19s get average rank \((9+10)/2=9.5\).
The group rank sums are
They sum to \(10.5+14.5+30=55\), equal to \(10(11)/2=55\). The uncorrected statistic is
There are three tied sets, each of size 2. Therefore \(\sum(t_\ell^3-t_\ell)=3(2^3-2)=18\), and
The corrected statistic is \(H_c=3.2/(54/55)=3.2593\), rounded to four decimal places. With 2 degrees of freedom, the approximate p-value is \(e^{-3.2593/2}\approx0.1959\). The tie correction increases the statistic here, as it does whenever \(0<C<1\) and \(H>0\). The ranks, group sizes, and tie-set sizes have all been checked against the ten observations.
Worked Example: Finding and Correcting a Common-Denominator Error
Method: use the group-specific denominators in the rank-sum formula and compare against the erroneous common-denominator calculation. A hypothetical quality audit has groups of sizes 2, 3, and 4, with pooled ranks allocated as follows: A has ranks 3 and 5; B has ranks 1, 6, and 8; C has ranks 2, 4, 7, and 9. There are no ties. Calculate \(H\). The mistake to avoid is using the average group size, 3, as the denominator for all three terms.
The rank sums are \(R_A=3+5=8\), \(R_B=1+6+8=15\), and \(R_C=2+4+7+9=22\). Their total is \(8+15+22=45\), as required for ranks 1 through 9. The correct computation is
Using 3 as a common denominator would instead produce
That value is incorrect: the three groups have sizes 2, 3, and 4, not 3, 3, and 3. With 2 degrees of freedom, the correct statistic has approximate p-value \(e^{-0.4/2}\approx0.8187\). The common-denominator result is not a harmless rounding difference; it alters the statistic because it weights the group rank sums incorrectly.
Checks That Prevent Unequal-Size Errors
Before drawing a conclusion, verify the arithmetic and the structure of the calculation. These checks are especially useful when the group sizes differ:
- Check the rank total. The group rank sums must add to \(N(N+1)/2\), including when ranks have been averaged for ties.
- Keep the denominators attached to their groups. The term for group \(j\) is \(R_j^2/n_j\), not \(R_j^2\) divided by a pooled, average, or largest group size.
- Check tie handling separately. Average ranks are assigned before forming rank sums. The tie correction uses the sizes of tied sets, not the group sample sizes.
- Check the correction factor. In general, \(0\leq C\leq1\). If every observation is tied, \(C=0\) and \(H_c\) is undefined; otherwise, a positive correction factor can be used.
- Use the right reference degrees of freedom. The chi-square approximation has \(k-1\) degrees of freedom, regardless of whether the groups have equal sizes.
The statistic is a global comparison of the groups’ ranks. A small p-value indicates evidence that the groups do not all have the same distribution under the test’s assumptions; it does not, by itself, identify which groups differ. Also, a rank-based result should not automatically be described as a difference in medians without additional assumptions about the group distributions.
Check Your Understanding
For each problem, use the group-specific denominators. Give statistics to four decimal places where needed.
- Two independent groups have sizes 2 and 4, with pooled rank sums 5 and 16. There are no ties. Calculate \(H\). (Answer: \(H=0.8571\))
- Three independent groups have sizes 2, 2, and 4, with rank sums 5, 9, and 22. There are no ties. Calculate \(H\). (Answer: \(H=2\))
- Eight observations form three groups. Group A has ranks 1, 2.5, and 4; group B has ranks 2.5 and 8; group C has ranks 5, 6.5, and 6.5. Calculate \(H\), the tie correction \(C\), and \(H_c\). (Answer: \(H=3.3125,\ C=41/42,\ H_c\approx3.3933\))
- Three groups have sizes 2, 3, and 5, with rank sums 7, 15, and 33. There are no ties. Calculate \(H\). (Answer: \(H\approx1.6145\))
- All observations in a pooled Kruskal–Wallis calculation have the same value. What is \(C\), and can \(H_c\) be calculated? (Answer: \(C=0\); \(H_c\) is undefined.)