Waiting times are recorded for independent random samples of patients at three clinics. Such times are skewed, with a few very long waits, so a comparison built on a normal model for the group means is doubtful. A natural question is whether the three clinics have the same distribution of waiting times, and the Kruskal-Wallis test addresses it using only the order of the observations. This lesson builds the test statistic from pooled ranks, states the null hypothesis it actually tests, compares exact and chi-square p-values, handles ties, and separates the omnibus conclusion from claims about particular pairs of groups.
Key terms
Pooled ranks
Definition Suppose independent groups have sizes , and let . Pool all observations, sort them, and give them the ranks from the smallest to the largest. Observations with equal values receive the average of the ranks they would otherwise occupy, called their midrank. The rank sum of group is the sum of the pooled ranks of its observations, and its mean rank is . With or without ties the ranks add up to , so the overall mean rank is
In plain words Ranking all the observations together puts every group on one common ladder, and the mean ranks show which groups sit mostly low and which mostly high. Ranks keep only the order of the values. A strictly increasing change of scale, such as taking logarithms of positive values, leaves every rank unchanged, and an extreme value never gets a rank above , however far out it lies.
Example Take the constructed samples , and . All nine values are distinct, so their pooled ranks are to and here coincide with the values. The rank sums are , and , which add to . The mean ranks are , and , around the overall mean rank . If the value were replaced by , every rank would stay the same.
Kruskal-Wallis test
Definition The Kruskal-Wallis test compares independent groups through their pooled ranks. Its statistic is
Because the ranks always add up to , the same number can be written as
So , with exactly when all groups have the same mean rank. Large values are evidence against the null hypothesis that the population distributions are identical. The p-value is the probability under that null hypothesis of a value of at least as large as the observed one, computed exactly by permutation or approximately from a chi-square distribution, and with ties the statistic is divided by the tie correction factor described below. The test requires independent observations, within groups and between groups, and a response whose values can be ordered. For the statistic is the square of the standardized Wilcoxon rank-sum statistic, so the test extends the two-sided Mann-Whitney test to more than two groups.
In plain words Rank everything together and ask whether some groups collect mostly small ranks and others mostly large ones. The statistic measures how far the group mean ranks spread around the middle rank. Ranks reduce the pull of extreme values and need no normal model. They do not repair dependent observations, a biased selection of units or measurements that mean different things in different groups. Repeated measurements on the same units call for a method for related samples, such as the Friedman test.
Example For the constructed samples, and every , so
The mean-rank form gives the same value, since . This is the largest value the statistic can take for three groups of three without ties, because the three groups occupy three separate blocks of ranks.
Identical-distribution null hypothesis
Definition Let be the population distribution of the response in group . The usual null hypothesis of the Kruskal-Wallis test is
and the alternative is that the are not all equal. If the groups are independent random samples, then under all observations are independent draws from one distribution, so they are exchangeable. Given the pooled set of observed values, every allocation of the observed units to groups of the fixed sizes is then equally likely, and there are
such allocations. The exact permutation p-value is the fraction of them whose statistic is at least the observed value. In a randomized experiment the same reference follows from the random assignment itself, under the null hypothesis that each unit would give the same response in whichever group it was placed. The statistic reacts mainly to differences in mean ranks, that is, to some groups tending to give larger values than others. Distributions that differ only in spread around a common center of symmetry give every group the same expected mean rank, and the test is not designed to detect such differences.
In plain words The null hypothesis says that group membership makes no difference at all to the distribution of the response. Then the group labels are arbitrary tags, and shuffling them among the observed values produces data just as plausible as the real ones. A statement about medians needs more. Under a location-shift model, for one continuous distribution , the groups share shape and spread and differ only by shifts, so says the shifts are equal and a rejection is evidence that the medians are not all equal. Without such a model, a rejection says the distributions are not all identical, and the difference may involve location, spread or shape.
Example For the constructed samples there are
allocations of the nine values to the labeled groups , and , each of size three. Only six reach a statistic of at least , namely those that give the blocks , and to the three groups in one of the orders. The exact p-value is
Chi-square approximation
Definition Suppose the groups are independent samples from one continuous distribution. As every grows with fixed, the distribution of approaches the chi-square distribution . The approximate p-value for an observed value is , with replaced by the tie-corrected value when there are ties. This is a large-sample result. A common rule of thumb asks for at least five observations in every group. With smaller groups or heavy ties, an exact permutation p-value is preferred, or a Monte Carlo p-value computed from many random allocations of the labels.
In plain words The chi-square curve is a smooth stand-in for the exact permutation distribution. Without ties the exact null distribution of has mean , the same as , but with tiny groups the statistic takes comparatively few distinct values, for three groups of three without ties, and its tail can be far from the tail of the curve, in either direction.
Example With the reference is , whose upper tail is for . For the constructed samples the approximate p-value is , more than seven times the exact value . Within the same design the error also runs the other way. The exact probability of a statistic of at least is , while the curve gives . Cutoffs differ as well. The exact null distribution for three groups of three without ties gives , while the chi-square cutoff for is about .
Tie correction
Definition A tie occurs when two or more observations share a value, and tied observations receive midranks. Midranks vary less than the untied ranks , which shrinks the statistic relative to its null scale. Suppose the values that occur more than once form tie blocks of sizes . The tie correction factor is
and the corrected statistic is . With no ties . The corrected statistic equals times the between-group sum of squares of the ranks divided by their total sum of squares, which is the general definition of the Kruskal-Wallis statistic. When the observations are not all equal, , so the correction never lowers the statistic. When all observations are equal, and the corrected statistic is undefined, since the data contain no ordering information at all.
In plain words Tied observations share their ranks, because putting one ahead of the other would invent information. Sharing makes the ranks less spread out, and dividing by restores the scale the chi-square approximation expects. The factor depends only on the pooled values, so it is the same for every allocation and does not change an exact p-value. The exact distribution itself, however, must be recomputed from the tied ranks.
Example Change group to and keep and . The two observations equal to share ranks and , so each receives . The rank sums are still , and , so as before. There is one tie block of size , and
The corrected statistic is , with chi-square p-value . Recomputing all allocations with the tied ranks again finds six at least as extreme, so the exact p-value stays . The count stays at six because both tied observations fall in the same block of three, and a tie that straddles two blocks can change it.
Omnibus test
Definition An omnibus test tests one null hypothesis about all the groups at once, here , against the alternative that the distributions are not all identical. A rejection is a statement about the whole set of groups. It does not say which groups differ, how many differ or in which direction. Questions about particular groups are answered by post-hoc comparisons, such as pairwise rank-sum tests or Dunn’s test, which compares mean pooled ranks. The family of comparisons, for example all pairs, should be stated, and the family-wise error rate controlled, for example with a Bonferroni or Holm adjustment. Running unadjusted pairwise tests whenever the omnibus test rejects does not control the family-wise error rate in general. With four or more groups, a real difference among some groups can make the omnibus test reject with high probability, and several true null pairs are then tested at the unadjusted level.
In plain words The omnibus test asks whether the groups are all alike. Which groups differ is a separate set of questions, with their own error control, and the two answers need not line up. A report is clearer when it shows the group distributions themselves, for example with plots, medians or mean ranks, rather than only the significance label.
Example For the constructed samples, the exact p-value is evidence, under independent sampling, that the three distributions are not all identical. That conclusion fits several patterns, such as alone differing from two identical distributions for and , or all three differing. Telling these apart needs a declared family, here the three pairs and , and , and . With a Bonferroni adjustment at family-wise level , each pairwise p-value is compared with .
Check yourself
- Independent samples give , and . Find the pooled ranks, the rank sums and the Kruskal-Wallis statistic. For three groups of three without ties, the exact null distribution gives . Does the exact test reject at the 5 percent level?
Show the answer
Sorted, the values are with ranks to . Group has ranks , and , group has , and , and group has , and . The rank sums are , and , which add to as they should. Then
The value is below , so the exact test does not reject at the 5 percent level. Enumerating the allocations gives the exact p-value . This does not show that the three distributions are identical. With three observations per group the test has little power, and the data are compatible with real differences.
- For the constructed samples , and , the exact p-value is . A report concludes that group differs from group . Is that justified? As a follow-up, what is the smallest two-sided p-value an exact rank-sum test of two groups of three can give?
Show the answer
The omnibus result is evidence that the three distributions are not all identical, under independent sampling. It does not by itself support a claim about and in particular, which needs its own stated comparison with multiplicity control.
An exact rank-sum test of two groups of three considers the equally likely allocations of six values. Complete separation in one direction is a single allocation, and the two-sided p-value counts both directions, so the smallest possible value is . Each of the three pairwise tests therefore gives at least , above and far above the Bonferroni level . With separate rank-sum tests as the follow-up, no pair can be singled out at the 5 percent level, even though the omnibus test rejects. The two analyses answer different questions. A follow-up built on the pooled ranks of all nine observations, such as Dunn’s test, is a different procedure and can give smaller p-values for the most separated pair.
- Change the data to , and . Find the midranks, the statistic, the tie correction factor and the corrected statistic. Can the count of six extreme allocations from the untied data be reused for the exact p-value?
Show the answer
The two observations equal to would occupy ranks and , so each receives . The ranks are in , in and in , with rank sums , and . The squared rank sums add to , so
One tie block of size gives , so the corrected statistic is about , with chi-square p-value .
The old count cannot be reused. The group sizes are still , and , so there are still allocations, but the possible values of the statistic have changed. The largest value is now about instead of , and it is reached by twelve allocations, because the two observations equal to can trade places between the lowest and middle blocks without changing any rank. The exact p-value is , twice the value for the untied data.