3.7 Wilcoxon Rank Sum

For two independent samples, pool the observations, rank them together, and ask whether one sample’s ranks are systematically larger. If the \(X\)’s tend to exceed the \(Y\)’s, the ranks of the \(X\)’s in the combined ordering will tend to be the larger ones.

Definition 3.8. Let \(X_1,\ldots ,X_n\) and \(Y_1,\ldots ,Y_m\) be independent samples, \(N = n+m\). Rank all \(N\) observations together, smallest first, averaging tied ranks. The Wilcoxon rank-sum statistic is \[W_N = \sum ^{N}_{i=1} i\,Z_i, \qquad Z_i = \begin {cases} 1 & \text {the } i\text {th value in the combined ordering is an } X,\\ 0 & \text {otherwise}, \end {cases}\] that is, the sum of the ranks belonging to the \(X\) sample.

Note 3.9. Writing \(W_X\) and \(W_Y\) for the two rank sums, \[W_X + W_Y = \dfrac {N(N+1)}{2},\] since every rank from \(1\) to \(N\) is counted exactly once. Computing both and checking this identity catches most ranking mistakes immediately.

Theorem 3.10. Under \(H_0\) that the two samples come from the same distribution, \[E\left (W_X\right ) = \dfrac {n(N+1)}{2}, \qquad \operatorname {var}\left (W_X\right ) = \dfrac {nm(N+1)}{12},\] and for \(n, m\) not too small \[Z = \dfrac {W_X - E(W_X)}{\sqrt {\operatorname {var}(W_X)}}\] is approximately standard normal.

Note 3.11. Which rank sum, and which tail. Tables of critical values are built for the sample with the smaller \(n\), listed down the side, against the larger \(m\) across the top, and they give a lower critical value \(W_0\): reject when \[W \leq W_0 .\] The two directions are related by symmetry, the upper critical value being \(n(N+1) - W_0\). Using a tabulated lower value as though it were an upper threshold reverses the test, and the next example shows what that costs.

Example 3.12. A researcher asks whether men store more films than women. Four of each are sampled, and the amounts in GB are ranked together.

Men 305 (8) 16 (1) 122 (7) 68 (4) \(W_{\text {men}} = 20\)
Women 25 (2) 63 (3) 84 (5) 103 (6) \(W_{\text {women}} = 16\)

The check holds: \(20 + 16 = 36 = \frac {8(9)}{2}\).

Hypotheses. \(H_0\): the two distributions are identical. \(H_1\): men store more, so \(W_{\text {men}}\) tends to be large.

The exact test. With \(n = m = 4\) there are only \(\binom {8}{4} = 70\) equally likely rank assignments, so the null distribution can be written down. The upper tail is \[P(W \geq 26) = \tfrac {1}{70} = 0.0143, \quad P(W \geq 25) = \tfrac {2}{70} = 0.0286, \quad P(W \geq 24) = \tfrac {4}{70} = 0.0571 .\] So the one-sided \(5\%\) critical value is \(W \geq 25\), and the matching lower value is \(n(N+1) - 25 = 36 - 25 = 11\).

Decision. The observed \(W_{\text {men}} = 20\) is far short of \(25\); the exact one-sided \(P\)-value is \[P(W \geq 20) = \tfrac {24}{70} = 0.3429 .\] We fail to reject \(H_0\). There is no evidence that men store more.

Note 3.13. A warning drawn from this example. It is tempting to take the tabulated value \(11\) and reject because \(20 > 11\). That inverts the test: \(11\) is the lower critical value, to be used with the smaller rank sum in the direction \(W \leq 11\). Read correctly, the women’s sum \(16\) is greater than \(11\) and the conclusion is the same — do not reject.

The mistake matters because it changes the answer, not merely the route. A \(P\)-value of \(0.34\) is about as far from significant as this design allows, and four observations per group could hardly detect anything else.

Example 3.14. Two independent samples, \(n_1 = 10\) and \(n_2 = 11\), ranked together over \(N = 21\) observations. Ties are averaged, so \(10.2\) appears twice at rank \(2.5\) and \(13.0\) three times at rank \(12\).

Sample 1 Rank Sample 2 Rank
12.5 8 15.1 19
13.0 12 13.4 14
10.2 2.5 14.6 17
9.0 1 13.0 12
11.4 5 15.2 20
12.6 9 15.4 21
11.7 6 14.5 16
12.2 7 13.0 12
10.5 4 14.8 18
10.2 2.5 12.8 10
13.7 15
\(W_1 = 57\) \(W_2 = 174\)

Check: \(57 + 174 = 231 = \frac {21(22)}{2}\).

With \(H_0\) that the distributions are identical against \(H_1\) that \(D_1\) is shifted left of \(D_2\), \[E(W_1) = \dfrac {10(22)}{2} = 110, \qquad \operatorname {var}(W_1) = \dfrac {10 \times 11 \times 22}{12} = 201.67,\] \[Z = \dfrac {57-110}{\sqrt {201.67}} = -3.73 .\] Against \(Z_{0.05} = -1.645\) we reject \(H_0\): sample 1 lies to the left of sample 2.

Note 3.15. This example has ties, so strictly the corrected variance applies. With one group of three and one of two, \(\sum (t^{3}-t) = 24 + 6 = 30\), and the corrected variance of the next subsection gives \[\operatorname {var}(W_1) = \dfrac {10 \times 11}{12} \left [22 - \dfrac {30}{21 \times 20}\right ] = 201.01, \qquad Z = -3.74 .\] The change is in the third decimal place and the conclusion is untouched — but the correction should be applied as a matter of course, because with heavier ties it will not always be negligible.

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.