Ranking two independent samples together and adding one group's ranks gives Wilcoxon's $W$. Mann and Whitney's $U = W - n_1(n_1+1)/2$ counts the pairs in which the first group's value is the larger, and $U/(n_1 n_2)$ estimates $\theta = P(X > Y) + \tfrac12 P(X = Y)$. If the two populations are identical, the exact distribution comes from counting arrangements, with $E(U) = n_1 n_2/2$ and $\operatorname{Var}(U) = n_1 n_2(N+1)/12$, reduced for ties. On 8 men and 8 women the men were higher in 46 of 64 pairs, exact $p = 0.161$; for 10 older and 30 younger adults, $p = 0.0019$. A rejection shows that $\theta \ne \tfrac12$, and that the medians differ only under a shift model. The efficiency to the $t$-test is $3/\pi = 0.955$ under normality and above 1 for heavy tails and skewness.
A study measures the systolic blood pressure of 8 men and 8 women and asks whether one group tends to run higher than the other. The two-sample t-test compares the two sample means, and for small samples it needs populations that are close to normal. Blood pressure is right-skewed, and a single unusually high reading moves a mean of eight values a long way. An alternative is to put the sixteen values in order and ask whether the men's values sit higher in that ordering than chance would put them. For these sixteen people they do not: the men are higher in 46 of the 64 man–woman pairs, and a split at least that lopsided, in one direction or the other, arises by chance about one time in six.
That question is the one the Wilcoxon rank-sum test asks. Frank Wilcoxon (1945) proposed it for "unpaired experiments", in the same short paper that introduced the signed-rank test: rank all the observations together and add up the ranks of one group. Two years later H. B. Mann and D. R. Whitney (1947) proposed a statistic $U$ counting how often an observation of one group exceeds one of the other. They worked out its exact distribution by a recurrence, proved that it is asymptotically normal, and noted that "Wilcoxon proposed an equivalent test". The two statistics differ by a constant. The test goes by both names: the rank-sum test, the Mann–Whitney $U$ test, or the Wilcoxon–Mann–Whitney test.
First we show that $W$ and $U$ are the same test, and what $U$ estimates. Then we work the 8 men and 8 women by hand, find the exact null distribution by counting arrangements, and derive the normal approximation with its correction for ties. Then come two points that the shorthand "nonparametric test of medians" obscures: what hypothesis the test actually examines, stated here and established in What the Rank-Sum Test Tests, and how it compares in power with the $t$-test, under normality and otherwise. Two worked problems close the article. The article assumes The Sign Test and the Wilcoxon Signed-Rank Test, where exact counting and the tie correction are introduced. Its efficiency against the $t$-test is derived in Asymptotic Relative Efficiency of Rank Tests.
The setting and the hypotheses
Two independent random samples are drawn: $x_1, \dots, x_{n_1}$ from a population with distribution function $F$, and $y_1, \dots, y_{n_2}$ from one with distribution function $G$. There are $N = n_1 + n_2$ observations in all. Independence is the same requirement as for the two-sample t-test: no observation in one group is matched to one in the other. For paired data, the signed-rank test is the counterpart.
The null hypothesis is that the two populations are the same,
$$H_0: F = G.$$
Under $H_0$ the $N$ observations are $N$ independent draws from one distribution, which is all the exact distribution of the test needs.
The alternative that Mann and Whitney (1947) had in mind was that one variable is stochastically larger than the other. $X$ is stochastically larger than $Y$ if $P(X > a) \ge P(Y > a)$ for every value $a$, with strict inequality somewhere. Values of $X$ then tend to be higher across the whole range. Their motivating study measured how long infected rats survived with and without a protective drug. There, in their words, "the only relevant alternative" to no effect was that survival times with the drug were stochastically larger (§2). When some survival times are censored, scoring pairs in the same spirit gives Gehan's generalized Wilcoxon test, which The Log-Rank Test (Proposition 2) shows to be the log-rank test weighted by the number at risk.
A shift in location is the simplest case: $X$ has the distribution of $Y + \Delta$ for a constant $\Delta$. In terms of the distribution functions, $F(a) = P(Y + \Delta \le a) = G(a - \Delta)$, or equivalently
$$G(a) = F(a + \Delta).$$
This article keeps that convention throughout: $\Delta$ is the amount by which the first population lies above the second. With $\Delta > 0$, $P(X > a) = P(Y > a - \Delta) \ge P(Y > a)$ for every $a$, so $X$ is stochastically larger than $Y$. What the test detects when the alternative is neither a shift nor stochastic ordering is the subject of What the Rank-Sum Test Tests.
Ranks, W and U
Rank all $N$ observations together from 1 (smallest) to $N$ (largest), tied values receiving the mean of the ranks they span. The rank-sum statistic is
$$W = \sum_{i=1}^{n_1} \operatorname{rank}(x_i),$$
the sum of the ranks of the first sample. The Mann–Whitney statistic counts pairs:
$$U = \#\{(i, j): x_i > y_j\} + \tfrac12\,\#\{(i, j): x_i = y_j\},$$
the number of the $n_1 n_2$ pairs, one observation from each group, in which the $x$ is the larger, with ties counted as one half.
The two are the same test. Here is the idea in one sentence: an $x$'s rank counts the observations at or below it, and the $y$'s among them are exactly the pairs that $U$ counts.
Order the first sample, $x_{(1)} < x_{(2)} < \cdots < x_{(n_1)}$, and suppose for the moment that there are no ties. The rank of $x_{(k)}$ in the combined sample is the number of observations at or below it. That is $k$ from its own sample (itself and the $k - 1$ smaller $x$'s), plus the number of $y$'s below it, $c_k$. So
$$W = \sum_{k=1}^{n_1}(k + c_k) = \frac{n_1(n_1+1)}{2} + \sum_{k=1}^{n_1} c_k = \frac{n_1(n_1+1)}{2} + U,$$
because $\sum c_k$ counts every pair $(x, y)$ with $x > y$ exactly once.
With ties the same identity holds, and the proof uses one fact about midranks. A value $v$ that is tied with $t - 1$ others, with $a$ observations below it, shares the ranks $a + 1, \dots, a + t$, whose mean is $a + (t+1)/2$. So
$$\operatorname{rank}(v) = \#\{\text{observations} < v\} + \frac{\#\{\text{observations} = v\} + 1}{2},$$
where the second count includes $v$ itself. Split each count for an observation $x_i$ into the $y$'s and the $x$'s:
$$\operatorname{rank}(x_i) = \Big[\#\{j: y_j < x_i\} + \tfrac12\,\#\{j: y_j = x_i\}\Big] + \Big[\#\{l: x_l < x_i\} + \frac{\#\{l: x_l = x_i\} + 1}{2}\Big].$$
The first bracket, summed over $i$, is $U$: every pair with $x_i > y_j$ counts 1 and every tied pair $\tfrac12$. The second bracket is the midrank of $x_i$ within the first sample alone. Those $n_1$ midranks total $1 + 2 + \cdots + n_1 = n_1(n_1+1)/2$, because midranks keep the total of the ranks they replace. Hence
$$U = W - \frac{n_1(n_1+1)}{2}$$
always. Since $n_1$ is fixed, any test based on one is a test based on the other. The smallest possible $W$, when the $x$'s occupy the lowest ranks, is $n_1(n_1+1)/2$, which is where $U = 0$. Counting pairs the other way gives $U' = n_1 n_2 - U$, the number of pairs in which the $y$ is larger.
Mann and Whitney (1947, §3) defined $U$ as the number of times a $y$ precedes an $x$ in the ordered sequence, which is this $U$. They gave its relation to Wilcoxon's rank sum $T$ of the $y$'s as $U = mn + m(m+1)/2 - T$, with $n$ $x$'s and $m$ $y$'s. It is the same identity, written for the other sample.
The second form explains what the statistic estimates. Each of the $n_1 n_2$ pairs contributes 1, $\tfrac12$ or 0 to $U$, and each pair's expected contribution is
$$\theta = P(X > Y) + \tfrac12 P(X = Y),$$
so $U/(n_1 n_2)$ is an unbiased estimate of $\theta$. Under $H_0$, $\theta = \tfrac12$. The reason is symmetry: when $X$ and $Y$ are independent with the same distribution, $P(X > Y) = P(Y > X)$, and these two probabilities and $P(X = Y)$ add up to 1, so $P(X > Y) + \tfrac12 P(X = Y) = \tfrac12$. Fay and Proschan (2010, §5.1.1) call $\theta$ the Mann–Whitney functional; it is also called the probability of superiority. Two values from the NHANES population of 2017 to 2018 set the scale:
- a randomly chosen man has a higher systolic blood pressure than a randomly chosen woman with probability $\theta = 0.552$ (ties, at 1.0% of pairs, split);
- an adult aged 60 or over is higher than one aged 18 to 39 with $\theta = 0.825$.
Worked example: 8 men and 8 women
Now the 8 men and 8 women. The script drew them at random from the NHANES adults (seed 1). Their systolic pressures, in mm Hg, are
- men: 140.7, 109.3, 124.7, 109.3, 143.3, 170.7, 124.0, 124.7;
- women: 115.3, 137.3, 140.0, 107.3, 119.3, 121.3, 112.7, 108.0.
Ranked together (M for a man, W for a woman):
| Value | 107.3 | 108.0 | 109.3 | 109.3 | 112.7 | 115.3 | 119.3 | 121.3 |
|---|---|---|---|---|---|---|---|---|
| Group | W | W | M | M | W | W | W | W |
| Rank | 1 | 2 | 3.5 | 3.5 | 5 | 6 | 7 | 8 |
| Value | 124.0 | 124.7 | 124.7 | 137.3 | 140.0 | 140.7 | 143.3 | 170.7 |
|---|---|---|---|---|---|---|---|---|
| Group | M | M | M | W | W | M | M | M |
| Rank | 9 | 10.5 | 10.5 | 12 | 13 | 14 | 15 | 16 |
Two pairs of men share values and receive midranks 3.5 and 10.5. The men's ranks sum to $W = 82$ and the women's to 54; together they make $16 \cdot 17/2 = 136$. Then
$$U = 82 - \frac{8 \cdot 9}{2} = 46,$$
and counting directly, the men are higher in 46 of the 64 man–woman pairs. Each of the three highest men is above all 8 women, the man at 124.0 and the two at 124.7 are above 6 women each, and the two at 109.3 above 2 each: $3 \times 8 + 3 \times 6 + 2 \times 2 = 46$. The women are higher in $U' = 64 - 46 = 18$ pairs. The estimate of $\theta$ is $46/64 = 0.72$.
Example (72% of the pairs, with 8 per group). The men are higher in 72% of the pairs, where chance alone would give about 50%, yet with 8 people per group that is not strong evidence that men run higher: the exact two-sided $p$-value is 0.161. The exact distribution, derived next, shows why.
The exact null distribution
Under $H_0$ every way of choosing which 8 of the 16 positions in the ordering belong to men is equally likely. The reason is that the 16 observations are then independent draws from one distribution. Their joint distribution is unchanged when the observations are relabeled in any order, so, given the sixteen values, every assignment of the labels "man" and "woman" to them (8 of each) has the same probability. There are $\binom{16}{8} = 12{,}870$ assignments, and the null distribution of $U$ is the distribution of the pair count over all of them. This is the counting argument of the signed-rank test, with arrangements of group labels in place of sign patterns, and Permutation Tests proves such relabeling tests exact for any statistic.
Mann and Whitney (1947, §4, equation 1) found the distribution with a recurrence. The idea is to look at the largest observation: it belongs to one group or the other, and either way what remains is a smaller problem of the same kind. Code each $x$ as 0 and each $y$ as 1, and let $p_{n_1, n_2}(u)$ be the probability that a random sequence of $n_1$ zeros and $n_2$ ones has $U = u$. Look at the last element of the sequence.
- It is an $x$ with probability $n_1/(n_1 + n_2)$. Then that $x$ is above all $n_2$ $y$'s, contributing $n_2$ to $U$, and the remaining sequence is a random arrangement of $n_1 - 1$ zeros and $n_2$ ones.
- It is a $y$ with probability $n_2/(n_1+n_2)$, contributing nothing.
So
$$p_{n_1, n_2}(u) = \frac{n_1}{n_1 + n_2}\,p_{n_1 - 1,\, n_2}(u - n_2) + \frac{n_2}{n_1 + n_2}\,p_{n_1,\, n_2 - 1}(u),$$
starting from $p_{n_1, 0}$ and $p_{0, n_2}$, which put all their probability on $u = 0$. Mann and Whitney used it to tabulate $P(U \le u)$ for all sample sizes up to 8 (their Table I). The script's implementation reproduces their table: for example, $P(U \le 13) = 0.025$ and $P(U \le 12) = 0.019$ for 8 and 8, and $P(U \le 4) = 0.048$ for 5 and 5.
The distribution is symmetric about $n_1 n_2/2 = 32$. Reading the ordered sequence from the largest value to the smallest turns every pair with $x > y$ into a pair with $x < y$, so it turns $U = u$ into $U = n_1 n_2 - u$, and it matches the arrangements in pairs. For the observed $U = 46$, or equivalently $U' = 18$, the two-sided $p$-value is
$$p = 2\,P(U \le 18) = 2 \times 0.0803 = 0.161.$$
This sample has ties, and the recurrence assumes none. The exact distribution conditional on the observed midranks treats every one of the 12,870 assignments of these sixteen ranks to the two groups as equally likely. It is computed by a recursion over the ranks $r_1, \dots, r_N$, taken one at a time. Let $c_k(m, s)$ be the number of ways to choose $m$ of the first $k$ ranks with total $s$. The $k$-th rank is either left out or chosen, so
$$c_k(m, s) = c_{k-1}(m, s) + c_{k-1}(m - 1,\ s - r_k), \qquad c_0(0, 0) = 1,$$
and $P(W = s) = c_N(n_1, s)/\binom{N}{n_1}$. It is the recursion of the signed-rank test with one more index, the number of ranks chosen so far. For the 8 men and 8 women it gives $p = 0.152$. Either way, 8 men and 8 women give no evidence that the populations differ, and the pooled $t$-test agrees: $t = 1.267$, $p = 0.226$. The population difference is real, $\theta = 0.552$, but small. As for the $t$-test, 16 people are far too few to see it.
The recurrence also gives critical values. For two samples of 8, a two-sided test at $\alpha = 0.05$ rejects when $\min(U, U') \le 13$, with exact level 0.0499. Very small samples cannot reject at all. With 3 in each group the most extreme arrangement has two-sided probability $2/\binom{6}{3} = 0.1$. Fay and Proschan (2010, §5.3.3) note that at $\alpha = 0.05$ the exact test needs at least 4 per group to have any possibility of rejecting, where the $t$-test needs only 2.
The normal approximation
Counting 12,870 arrangements is easy for a computer, but the count grows quickly with the sample sizes. For larger samples the distribution of $W$ is approximated by a normal distribution with its exact mean and variance. Here is the idea: under $H_0$ the first group's ranks are just a random draw from the numbers 1 to $N$, so $W$ behaves like the total of a sample drawn without replacement.
The formal version. Kruskal and Wallis (1952, §3.1) used this argument for their test. Under $H_0$ the ranks of the first sample are a random sample of $n_1$ drawn without replacement from the integers $1, \dots, N$. That population has mean $(N+1)/2$ and variance $(N^2 - 1)/12$, by the computation for the integers $1, \dots, t$ in the signed-rank article with $t = N$. The sum of $n_1$ values drawn without replacement has mean $n_1$ times the population mean. Its variance is $n_1$ times the population variance times the factor $(N - n_1)/(N - 1)$, the square of the finite population correction, which The Sampling Distribution of the Mean proves for any finite population:
$$E(W) = \frac{n_1(N+1)}{2}, \qquad \operatorname{Var}(W) = n_1 \cdot \frac{N^2 - 1}{12} \cdot \frac{N - n_1}{N - 1} = \frac{n_1 n_2 (N+1)}{12}.$$
Since $U$ differs from $W$ by a constant, $E(U) = n_1 n_2/2$ and $\operatorname{Var}(U) = n_1 n_2(N+1)/12$. These are the values Mann and Whitney derived from their recurrence (their equations 2 and 5). They proved that the limiting distribution is normal however $n_1$ and $n_2$ grow, by showing that every moment of the standardized $U$ approaches the corresponding moment of the standard normal (§4). They noted that for 8 and 8 the distribution already "differs only a negligible amount from the normal distribution". The standardized statistic, with a continuity correction of one half, is
$$z = \frac{\left|W - \dfrac{n_1(N+1)}{2}\right| - \dfrac12}{\sqrt{\dfrac{n_1 n_2 (N+1)}{12}}}.$$
Ties lower the variance of the ranks, and so of $W$. Given the observed midranks, the first sample's ranks are still a random sample of $n_1$ drawn without replacement, now from the population of the $N$ midranks. Midranks keep the total, so that population still has mean $(N+1)/2$ and $E(W)$ is unchanged. As the signed-rank article derives, each group of $t$ tied values reduces the total sum of squares of the ranks by $(t^3 - t)/12$. The population variance of the ranks therefore falls by $\sum(t^3 - t)/(12N)$, to
$$\sigma_r^2 = \frac{N^2 - 1}{12} - \frac{\sum (t^3 - t)}{12N}.$$
Multiplying by $n_1 (N - n_1)/(N - 1) = n_1 n_2/(N - 1)$ as before,
$$\operatorname{Var}(W) = \frac{n_1 n_2}{N - 1}\left[\frac{(N-1)(N+1)}{12} - \frac{\sum (t^3 - t)}{12N}\right] = \frac{n_1 n_2}{12}\left[(N + 1) - \frac{\sum (t^3 - t)}{N(N - 1)}\right],$$
the sum running over the groups of tied values in the combined sample.
Example (the tie correction raises z). The 8 men and 8 women include two tied pairs, and the tie correction makes $z$ slightly larger, because the variance in the denominator shrinks. Here $E(W) = 8 \cdot 17/2 = 68$ and $\operatorname{Var}(W) = 64 \cdot 17/12 = 90.67$ without the correction. The two tied pairs have $\sum(t^3 - t) = 6 + 6 = 12$, which removes $(64/12) \cdot 12/(16 \cdot 15) = 0.27$ and leaves 90.40, and
$$z = \frac{|82 - 68| - 0.5}{\sqrt{90.40}} = \frac{13.5}{9.508} = 1.420, \qquad p = 0.156,$$
close to the exact values 0.161 and 0.152. At the exact critical value for 8 and 8, $U = 13$, the normal approximation with continuity correction gives a two-sided probability of 0.052 against the exact 0.0499.
Two larger samples
The approximation is meant for larger samples, and the earlier units supply two. The two-sample t-test article drew 20 men and 20 women (seed 1) and found $t = 0.674$, $p = 0.504$. The rank-sum test on the same 40 values gives $W = 432.5$ for the men, so $U = 432.5 - 210 = 222.5$ of 400 pairs. That is $U/400 = 0.556$, near the population's 0.552. The other ingredients are:
- $E(W) = 410$;
- six groups of ties (five pairs and a triple), reducing the variance from 1366.67 to 1365.51;
- the continuity correction.
Then
$$z = \frac{|432.5 - 410| - 0.5}{\sqrt{1365.51}} = 0.595, \qquad p = 0.552.$$
The exact conditional $p$-value is 0.551. Without the continuity correction $z = 0.609$ and $p = 0.543$.
The same article's second sample, 10 adults aged 60 and over and 30 aged 18 to 39, gave Welch's $t$-test $p = 0.0068$. The older adults' ranks sum to $W = 301$, so $U = 301 - 55 = 246$ of 300 pairs. In 82% of the pairs the older adult has the higher pressure, close to the population's 82.5%. Then $z = 2.984$, $p = 0.0028$, and the exact conditional $p$-value is 0.0019. Here the rank-sum test gives the stronger evidence of the two. The section on one gross error shows how a single extreme value weakens the $t$-test and leaves the rank-sum test alone.
The test rejects here. The next section establishes exactly what such a rejection shows.
What a rejection shows
A rejection shows that $\theta = P(X > Y) + \tfrac12 P(X = Y)$ differs from one half: values in one group tend to be larger than values in the other. It shows that the medians, or the means, differ only under a shift model, $G(a) = F(a + \Delta)$, where $\theta$ is above, at or below one half exactly as $\Delta$ is above, at or below zero. The test does not repair unequal spreads: when two populations have the same center and different spreads, its level moves away from $\alpha$ in the same direction as the pooled $t$-test's, if less extremely. What the Rank-Sum Test Tests proves the statement about the shift, shows the others by simulation, derives the variance of $U$ when the two distributions differ, and gives the Hodges–Lehmann estimate and interval for a shift.
When the shift model does hold, what remains is the cost of ranking in power, measured as it was for the signed-rank test.
Efficiency and robustness
Under a shift model the asymptotic relative efficiency of the rank-sum test to the two-sample $t$-test is $12\sigma^2\left(\int f^2\right)^2$, the same expression as for the signed-rank test against the paired $t$-test. Asymptotic Relative Efficiency of Rank Tests defines the measure, derives the expression and tabulates it. For normal data it is $3/\pi = 0.955$, so the rank-sum test then needs only about 5% more observations than the $t$-test. For the other shapes used below it is exactly 1 for the uniform, above 1 for the logistic, Laplace, contaminated normal, $t$ with 3 degrees of freedom and exponential, and for no shape is it below $108/125 = 0.864$.
Power at 20 per group
A simulation shows how far the asymptotic numbers carry over to a realistic size. The script compared the two tests with 20 observations per group, with the same design as for the signed-rank test:
- the shift was $0.909\,\sigma$, which gives the pooled $t$-test power 0.80 for normal data at $\alpha = 0.05$;
- every shape was scaled to the same standard deviation;
- the rank-sum test used its exact critical value, $\min(U, U') \le 127$, with exact level 0.0491.
| Shape | Power, pooled $t$ | Power, rank-sum | Level of $t$ / rank-sum when $\Delta = 0$ |
|---|---|---|---|
| Normal | 0.799 | 0.778 | 0.050 / 0.050 |
| Uniform | 0.800 | 0.736 | 0.051 / 0.050 |
| Logistic | 0.800 | 0.820 | 0.050 / 0.049 |
| Laplace | 0.801 | 0.880 | 0.049 / 0.048 |
| Contaminated normal | 0.805 | 0.891 | 0.047 / 0.048 |
| $t$, 3 df | 0.843 | 0.950 | 0.046 / 0.050 |
| Exponential | 0.804 | 0.934 | 0.047 / 0.050 |
Under a shift model both tests hold their level for every shape. The $t$-test does so by the central limit theorem, slightly conservatively for heavy tails; the rank-sum test does so exactly. Their powers differ in the direction the efficiencies give for six of the seven shapes: the rank-sum test has less power than the $t$-test for the normal shape, where its efficiency is below 1, and more for the five shapes where it is above 1. The uniform shape is the exception. Its efficiency is exactly 1, yet at 20 per group the rank-sum test has power 0.736 against the $t$-test's 0.800. That gap is an observation from this experiment. The efficiency is a limit for large samples and small shifts, and it does not say how the two tests compare at 20 per group. The $t$-test's power is nearly the same for every shape, because it depends on the data mainly through the means and the standard deviation, which have the same values in every scenario. The rank-sum test's power depends on how concentrated the distribution is, which is what $\int f^2$ measures. It is high for peaked and skewed shapes and lowest for the flat uniform.
One gross error
Robustness in a narrower sense is the effect of a few bad values. In the sample of 10 older and 30 younger adults, suppose the highest older value, 169.3 mm Hg, had been entered as 1693.3, a slipped decimal point.
Example (an error in the direction of the difference). The error is in the direction of the true difference: it makes the older group look higher still. Even so, it destroys the $t$-test's evidence and leaves the rank-sum test's result exactly as it was. Welch's $t$-test gave $p = 0.0068$ on the correct data. It now gives $t = 1.152$ and $p = 0.279$. The error raises the older group's mean from 142.3 to 294.7 mm Hg, which makes the difference larger. But it raises the group's standard deviation from 24.3 to 491.9, which swamps the difference. The rank-sum test gives exactly the same result as before, $U = 246$ and $p = 0.0028$, because 1693.3 has the same rank as 169.3: it is the largest value either way.
Fay and Proschan (2010, §5.3.5) show the same effect in a simulation with a single outlier of 1000 in samples of 100. The $t$-test's $p$-values rose from below $5 \times 10^{-6}$ to between 0.26 and 0.29, while the rank-sum test still rejected. Even an error in the direction of the true difference can destroy the $t$-test's power. An error cannot move a rank by more than the number of observations it passes.
Choosing between the tests
- When the question is about means (total cost, mean blood pressure reduction), use a test of means: Welch's $t$-test in general. The rank-sum test does not test means unless the shapes are the same.
- When the populations plausibly differ by a shift and may have heavy tails, outliers or skewness, the rank-sum test is the more powerful choice and loses little if the data turn out normal.
- When the data are ordinal (pain scores, stages, ratings), means may not be meaningful at all, and the rank-sum test's $\theta$ is a natural summary. Estimated by $U/(n_1 n_2)$, it is Vargha and Delaney's probability of superiority, which Effect Sizes and Standardized Differences applies to the thirty-run comparisons of the site's evolutionary computing experiments.
- When the spreads differ and the group sizes are unequal, neither the pooled $t$-test nor the rank-sum test holds its level. Welch's $t$-test does for means; for $\theta$, a test with a variance estimate that does not assume equal distributions is needed.
- Choosing the test after a preliminary test of normality is discouraged, like choosing between the pooled and Welch tests after a preliminary test of variances. Fay and Proschan (2010, §5.3.6) advise that the choice "should not be based on a test of normality": the $t$-test can be justified in large samples even when normality is rejected, and normality is hard to reject when the sample is small or the data are close to normal.
Worked problems
The two problems are posed here, on the unit's blood pressure samples and on the article's own results; none is taken from the course text. Each exercises one main result, and the script named under "In Python" checks every number.
Problem 1 (the null distribution for 4 and 4). Find the exact null distribution of $U$ for two samples of 4 without ties, check its mean and variance against the formulas, and find the values of $U$ for which a two-sided test at $\alpha = 0.05$ rejects.
Solution. The test rejects only when $U = 0$ or $U = 16$, that is, when the two samples do not overlap at all. There are $\binom{8}{4} = 70$ equally likely arrangements. Mann and Whitney's recurrence, multiplied through by the number of arrangements, counts them. Write $N_{n_1, n_2}(u)$ for the number of arrangements of $n_1$ $x$'s and $n_2$ $y$'s with $U = u$. The largest observation is an $x$ or a $y$, so
$$N_{n_1, n_2}(u) = N_{n_1 - 1,\, n_2}(u - n_2) + N_{n_1,\, n_2 - 1}(u).$$
For 3 and 4 (and, by the symmetry between the samples, for 4 and 3) the same recurrence gives the 35 arrangements as
| $u$ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| $N_{3,4}(u) = N_{4,3}(u)$ | 1 | 1 | 2 | 3 | 4 | 4 | 5 | 4 | 4 | 3 | 2 | 1 | 1 |
The last step is $N_{4,4}(u) = N_{3,4}(u - 4) + N_{4,3}(u)$. For example, $N_{4,4}(6) = N_{3,4}(2) + N_{4,3}(6) = 2 + 5 = 7$. In full:
| $u$ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|---|
| $N_{4,4}(u)$ | 1 | 1 | 2 | 3 | 5 | 5 | 7 | 7 | 8 |
and the counts for $u = 9, \dots, 16$ repeat these in reverse: 7, 7, 5, 5, 3, 2, 1, 1. They total 70. The distribution is symmetric about 8, so its mean is $8 = n_1 n_2/2$. Its variance is
$$\frac{2\left[1 \cdot 8^2 + 1 \cdot 7^2 + 2 \cdot 6^2 + 3 \cdot 5^2 + 5 \cdot 4^2 + 5 \cdot 3^2 + 7 \cdot 2^2 + 7 \cdot 1^2\right]}{70} = \frac{2 \times 420}{70} = 12,$$
which is $n_1 n_2 (N+1)/12 = 4 \cdot 4 \cdot 9/12$. For the test, $2P(U \le 0) = 2/70 = 0.0286$ and $2P(U \le 1) = 4/70 = 0.0571$. So at $\alpha = 0.05$ the test rejects only for $U = 0$ or $U = 16$, with exact level 0.0286.
Problem 2 (the youngest and oldest age groups). The one-way ANOVA article drew 10 adults from each of four age groups. The systolic pressures (mm Hg) of the youngest group, aged 18 to 29, were $114.7,\ 110.7,\ 110.0,\ 114.0,\ 118.7,\ 114.0,\ 96.7,\ 100.0,\ 110.0,\ 94.0$. Those of the oldest, aged 60 and over, were $144.7,\ 156.0,\ 108.7,\ 134.0,\ 110.0,\ 122.7,\ 144.0,\ 126.0,\ 142.0,\ 115.3$. Compare the two groups with the rank-sum test, using the normal approximation.
Solution. The older adults are higher in 86 of the 100 pairs, and $p = 0.0072$. Ranked together (Y for the youngest group, O for the oldest):
| Value | 94.0 | 96.7 | 100.0 | 108.7 | 110.0 | 110.0 | 110.0 | 110.7 | 114.0 | 114.0 |
|---|---|---|---|---|---|---|---|---|---|---|
| Group | Y | Y | Y | O | Y | Y | O | Y | Y | Y |
| Rank | 1 | 2 | 3 | 4 | 6 | 6 | 6 | 8 | 9.5 | 9.5 |
| Value | 114.7 | 115.3 | 118.7 | 122.7 | 126.0 | 134.0 | 142.0 | 144.0 | 144.7 | 156.0 |
|---|---|---|---|---|---|---|---|---|---|---|
| Group | Y | O | Y | O | O | O | O | O | O | O |
| Rank | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
Three values of 110.0 share ranks 5, 6 and 7, and two of 114.0 share ranks 9 and 10. Take the oldest group as the first sample. Its rank sum is
$$W = 4 + 6 + 12 + 14 + 15 + 16 + 17 + 18 + 19 + 20 = 141,$$
and the youngest group's is 69; together they make $20 \cdot 21/2 = 210$. So $U = 141 - 10 \cdot 11/2 = 86$, and the estimate of $\theta$ is $86/100 = 0.86$.
Under the null hypothesis $E(W) = 10 \cdot 21/2 = 105$, and without ties $\operatorname{Var}(W) = 10 \cdot 10 \cdot 21/12 = 175$. The tie groups have $t = 3$ and $t = 2$, so $\sum(t^3 - t) = 24 + 6 = 30$, and
$$\operatorname{Var}(W) = \frac{100}{12}\left[21 - \frac{30}{20 \cdot 19}\right] = 175 - 0.658 = 174.342,$$
with square root 13.204. Then
$$z = \frac{|141 - 105| - 0.5}{13.204} = \frac{35.5}{13.204} = 2.689, \qquad p = 0.0072.$$
The exact conditional $p$-value, from the recursion over these twenty midranks, is 0.0047. Either way the two groups differ. Without the continuity correction $z = 36/13.204 = 2.726$, a value the Kruskal–Wallis article uses in its own third worked problem.
What we have learned
Ranking two samples together and adding one group's ranks gives Wilcoxon's $W$. Subtracting its minimum gives Mann and Whitney's $U$, the number of pairs in which the first group's value is the larger. Under the null hypothesis every arrangement of the group labels is equally likely, so the exact distribution comes from counting, and the normal approximation with its tie correction is close by 8 per group. On 8 men and 8 women the men were higher in 72% of pairs, but $p = 0.161$.
A rejection means that $\theta = P(X > Y) + \tfrac12 P(X = Y)$ differs from one half. It means the medians differ only under a shift model. The test does not repair unequal spreads, and with unequal group sizes it fails in the same direction as the pooled $t$-test (What the Rank-Sum Test Tests). In return it loses about 5% of the sample size under normality, gains a great deal under heavy tails and skewness, and is unmoved by a single gross error.
For more than two groups, the Kruskal–Wallis test ranks all of them together and runs an analysis of variance on the ranks, and for two groups it reduces to this test.
In Python
from scipy import stats
men = [140.7, 109.3, 124.7, 109.3, 143.3, 170.7, 124.0, 124.7] # 8 men (mm Hg)
women = [115.3, 137.3, 140.0, 107.3, 119.3, 121.3, 112.7, 108.0] # 8 women
res = stats.mannwhitneyu(men, women) # ties present: normal approximation
print(res.statistic, res.pvalue) # U = 46, p = 0.156
perm = stats.mannwhitneyu(men, women, method=stats.PermutationMethod(n_resamples=20000, random_state=1))
print(perm.pvalue) # 0.1515, all 12,870 splits enumerated
print(res.statistic / (8 * 8)) # estimate of theta: 0.719
mannwhitneyu reports $U$ for the first sample; its documentation notes that the $p$-value is identical to the Wilcoxon rank-sum test's and that $W = U + n_1(n_1+1)/2$. Its exact method assumes no ties, so with tied data it uses the normal approximation with the tie correction, and a permutation method gives the exact conditional $p$-value. The outputs shown were checked with scipy 1.17.1, and every number in this article is computed by tools/experiments/applied-statistics/wilcoxon-rank-sum-test.py in the site's repository, which implements Mann and Whitney's recurrence and the exact conditional distribution directly.
References
- Fay, M. P., and Proschan, M. A. (2010). Wilcoxon–Mann–Whitney or t-test? On assumptions for hypothesis tests and multiple interpretations of decision rules. Statistics Surveys, 4, 1–39. record · 4 pages
- Kruskal, W. H., and Wallis, W. A. (1952). Use of ranks in one-criterion variance analysis. Journal of the American Statistical Association, 47(260), 583–621. record · 4 pages
- Mann, H. B., and Whitney, D. R. (1947). On a test of whether one of two random variables is stochastically larger than the other. The Annals of Mathematical Statistics, 18(1), 50–60. record · 4 pages
- National Center for Health Statistics (2020). National Health and Nutrition Examination Survey 2017–2018: Demographic Variables and Sample Weights (DEMO_J) and Blood Pressure (BPX_J) data files. Centers for Disease Control and Prevention. https://wwwn.cdc.gov/nchs/nhanes/continuousnhanes/default.aspx?BeginYear=2017 record · 109 pages
- SciPy.
scipy.stats.mannwhitneyu. SciPy reference documentation. https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mannwhitneyu.html record - Wilcoxon, F. (1945). Individual comparisons by ranking methods. Biometrics Bulletin, 1(6), 80–83. record · 6 pages
Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 11 revisions