Group A has the outcomes , and , and an independent group B has the outcomes , and . Does one group tend to produce larger values? A rank comparison answers by pooling the six values, ranking them once and asking how the ranks split between the two labels, without a normal model for the measurements. This lesson builds the rank sum and the Mann-Whitney U statistic, computes the exact permutation p-value, and makes clear which null the test checks and why it is not automatically a test of medians.
Key terms
Rank sum
Definition Let be the sample from group A and the sample from group B, with . Pool the values, sort them and give them the ranks to . Tied values get the average of the positions they occupy, called a midrank. The rank sum is the sum of the ranks of the A values, and is the sum for the B values. Together they use every rank once, so
In plain words There is one ranking for both groups together, and each rank then goes back to its group label. A small means that the A values sit low in the pooled order. Ranks record order only, so applying one strictly increasing function to every value, such as the logarithm of positive values, leaves every rank and both rank sums unchanged.
Example The pooled values to have ranks equal to themselves, so and , which add to . With ties, take A with the values and and B with the values and . The sorted values are , , and , and the two values share positions and , so each gets rank . Then and , which add to .
Mann-Whitney U statistic
Definition Compare every A value with every B value, which makes cross-group pairs. Counting a pair as a win for A when the A value is larger and as half a win when the two values are equal,
The statistic counts wins for B in the same way. With midranks for ties,
So runs from to . Texts and software differ in orientation. Some report , some the statistic of the first sample listed, and some the smaller of and , so a reported U needs its orientation stated.
In plain words When no values are tied, the rank of an A value counts the pooled values at or below it. Those include the A values at or below it, and removing them leaves the number of B values it beats. Adding over all A values removes in total, which is where the subtraction comes from. A large means that A values usually come out on top.
Example For A with , and and B with , and , the value beats no B value, beats , and beats and . So out of pairs, and the rank formula agrees, since . The other orientation gives . In the tied example, the A value loses both comparisons, and the A value ties the B value and loses to . So , matching .
Wilcoxon rank-sum test
Definition Suppose are independent observations from a population with distribution function , are independent observations from a population with distribution function , and the two samples are independent of each other. The Wilcoxon rank-sum test of
compares the observed with its distribution under , which is the exact permutation distribution described below or, for larger samples, a normal approximation. Without ties the null mean and variance are
A two-sided test counts values of far from the center in either direction as evidence against . Because differs from by a constant, the Mann-Whitney test based on is the same test with the same p-value, and the two names are often joined as the Wilcoxon-Mann-Whitney test. In a randomized experiment that assigns of units to A completely at random, the random assignment justifies the same reference under the sharp null hypothesis that every unit would give the same response under either treatment.
In plain words If both groups come from one population, the labels A and B carry no information about the values, and any split of the pooled ranks is as likely as the observed one. The null is that the whole distributions are equal, which says more than equal medians or equal means. The test needs independent units. It is a different procedure from the Wilcoxon signed-rank test, which analyzes the within-pair differences of paired data.
Example For the running example , so the center is , and the observed lies below it. On the U scale the center is , and also lies below it. The null variance of either statistic is . Whether a distance of is unusual is settled by the exact permutation distribution.
Exact permutation distribution
Definition Fix the pooled observations and their ranks. Under with the sampling conditions above, the observations are exchangeable. Given the pooled values, every one of the ways of choosing which observations carry the label A is then equally likely. Computing for every allocation gives the exact permutation distribution of . The p-value is the fraction of allocations whose statistic is at least as extreme as the observed one, under a rule for extremeness fixed before the data are seen. Without ties this distribution depends only on and , which is why it can be tabulated. With ties it depends on the pattern of ties, so the allocations are enumerated on the actual midranks, or a tie-corrected approximation is used.
In plain words The reference distribution lists what the statistic would be under every relabeling of the pooled values, all equally likely when the labels carry no information. The number of possible allocations also limits how small the p-value can be.
Example For there are allocations. The table shows how many give each low value of , and the counts for mirror those for .
| Allocations |
The center is and the observed is below it, so the two-sided rule counts allocations with or , which is on each side, and
This large p-value does not show that the two distributions are equal. It says only that the observed split of ranks is not unusual under the null, and three observations per group carry little information. For the tied samples, A with and and B with and , the six allocations of the midranks , , and give , and twice each, while untied samples of two and two give , , , , and . The observed is from the center , and of the allocations are that far away, so .
Probability of superiority
Definition For independent draws from population A and from population B, the probability of superiority of A over B is
Under independent random sampling, each of the cross-group pairs scores for an A win, for a tie and otherwise, with expected score , so
is an unbiased estimate of . If , then and . The converse fails, because different distributions can also give . For this reason the ordinary rank-sum test of is not automatically a valid test of the weaker null when the shapes differ. Procedures built for that null, such as the Brunner-Munzel test, use a different standard error.
In plain words The probability says how often a randomly chosen A outcome beats an independently chosen B outcome, with ties counted as half. A value of does not mean that three quarters of the A units beat every B unit, and is neither a difference in medians nor a difference in means.
Example For the running example , so an A value beat a B value in one third of the cross-group pairs, an estimate with large uncertainty at three values per group. For the tied samples . For two different distributions with , let A be normal with mean and variance and B normal with mean and variance . The difference is continuous and symmetric about , so although the spreads differ.
Location-shift model
Definition Two distributions follow a location-shift model if there is a constant with
for every , which means that A has the same distribution as . Every quantile of A then equals the same quantile of B plus , so the medians differ by , and so do the means when they exist. Within this model and with a continuous , the null is the same as . The rank-sum test then becomes a test of , and exactly when .
In plain words The shared shape is what lets a rank result speak about medians. Without it, two groups can have the same median but differ in spread or skewness, and the rank-sum test can then reject for reasons that have nothing to do with the median. A rejection by itself does not show that the medians differ. That reading needs the shift model or another argument.
Example Let B be uniform on and A uniform on , so that A has the distribution of . The medians differ by , and so do the means. Write and with and independent and uniform on . Then exactly when , which has probability , so .
Check yourself
- Take A with the values , and and B with the values , and . Find , , and the exact two-sided p-value. Does complete separation guarantee rejection at the percent level?
Show the answer
The ranks equal the values, so and . No A value beats any B value, so . The observed is from the center , and only the allocations with or are that far away, one each, so
Complete separation does not guarantee rejection. With three values per group the smallest attainable two-sided p-value is , so this test cannot reject at the percent level for any data. Failing to reject does not show that the distributions are equal either. The report should give the ordering, the sample sizes and together.
- Eight runners are timed before and after a training block. An analyst treats the before times and the after times as two groups and runs a rank-sum test. What is wrong, and what should be done instead?
Show the answer
The two groups are the same eight runners, so the samples are not independent. A runner’s before and after times are linked, and much of the variation in the times typically comes from differences between runners. The rank-sum reference shuffles labels across all times as if they were exchangeable, which ignores the matching, so the reference does not describe how the data arose, and the comparison is also diluted by the between-runner variation.
A paired analysis works with the eight within-runner differences, after minus before. The sign test fits a question about the median difference, the Wilcoxon signed-rank test needs differences that are symmetric under the null, and the paired t test targets the mean difference. When a runner’s before and after times are exchangeable under the null, the valid relabeling swaps them within each runner, which flips the sign of that runner’s difference. Without a control group, a before-after comparison also cannot by itself attribute a change to the training.
- Population A is uniform on . Population B also has median , but its lower half is more spread out. With probability a B value is uniform on , and with probability it is uniform on . Find . With large samples, would the rank-sum test tend to reject, and would a rejection show that the medians differ?
Show the answer
Let come from A and from B, independently. Ties have probability , so . When is uniform on , an A value in loses with probability , and an A value above always wins. The value lies in half the time, and there the loss probability averages , so loses with probability . When is uniform on , an A value in wins with probability , which averages there, and an A value below never wins, so wins with probability . Hence
Because , the two distributions differ, and as both samples grow settles near , so the rejection probability approaches . A rejection correctly signals that , but both medians are . The difference lies in the shape of B, so reporting that the medians differ would be wrong. Without a location-shift model, a rank-sum result should be described as a difference in distributions, with as its effect estimate.