Why Compare Ranks?
When two independent groups are measured on the same scale, a familiar approach is to compare their means. But measurements may be strongly skewed, contain outliers, or be better understood by their order than by their numerical distances. The Wilcoxon rank-sum test addresses this setting by pooling the observations and replacing each value with its rank. The test then asks whether the ranks tend to differ between groups.
The same procedure is commonly called the Mann–Whitney test. These are two formulations of one test for two independent samples: the rank-sum formulation uses the sum of ranks in a group, while the Mann–Whitney formulation expresses the comparison through cross-group pairs. Their statistics are related by a simple formula.
Hypotheses and Conditions
Let the first sample contain \(n_1\) observations from a distribution \(F_1\), and let the second contain \(n_2\) observations from a distribution \(F_2\). Here, a distribution describes the pattern of possible values and their probabilities in a group. The samples must consist of separate, independent observations; the two groups should also be independent of one another. The response must be at least ordinal, so that comparing which value is larger is meaningful. For quantitative data, both groups must be measured on the same scale.
For the standard two-sided rank-sum test, the null hypothesis is that the two population distributions are identical. The alternative is that they differ. This is a statement about the entire distributions, not just their means or medians.
Under \(H_0\), group labels are exchangeable: conditional on the pooled observed values, any allocation of \(n_1\) observations to group 1 and \(n_2\) to group 2 is equally plausible. This provides the basis for assessing how unusual the observed rank sum would be under the null. If observations are paired, such as two measurements on each person, their dependence violates the independent-groups design; a paired procedure is needed instead.
Random sampling or random assignment supports the validity of the intended inference. The particular design determines what population or treatment comparison the conclusion can address. Independence is not guaranteed simply because a rank test is used: repeated measurements on one individual, or observations clustered within a small number of units, require attention to their dependence.
How the Rank-Sum Statistic Is Formed
Pool the observations from both groups and rank them together in increasing order. The smallest value receives rank 1, the next smallest rank 2, and so on. When values tie, assign each tied observation the average of the ranks they would have occupied. Let \(R_1\) denote the sum of the ranks assigned to the first group. This is the Wilcoxon rank-sum statistic. A large \(R_1\) means that the first group tends to occupy higher positions in the pooled ordering; a small \(R_1\) means it tends to occupy lower positions. The inferential decision requires comparing the statistic with its null distribution, which is not calculated here.
The two groups’ rank sums are not independent quantities once the pooled ranks are fixed. If \(R_2\) is the rank sum for group 2, then the two sums together equal the sum of all pooled ranks:
This follows because the pooled ranks are \(1,2,\ldots,n_1+n_2\), whose sum is \(N(N+1)/2\), where \(N=n_1+n_2\). In particular, if one group has an unusually high rank sum, the other necessarily has a correspondingly low one.
Worked Example: Ranking Two Independent Groups
Suppose, hypothetically, that two independent groups provide measurements on the same scale. Group A has values 3, 5, 8, and 10; Group B has values 1, 4, 6, and 9. Find the pooled ranks and the rank sum for Group A.
Check the design. Treat the eight observations as coming from separate units, with no unit measured in both groups. Both groups use the same measurement scale, and the values can be ordered, so the rank-sum setup is appropriate.
Order all values and assign ranks: \(1_B\) has rank 1, \(3_A\) rank 2, \(4_B\) rank 3, \(5_A\) rank 4, \(6_B\) rank 5, \(8_A\) rank 6, \(9_B\) rank 7, and \(10_A\) rank 8. Thus Group A receives ranks 2, 4, 6, and 8.
The rank-sum statistic is
Group B has ranks 1, 3, 5, and 7, so \(R_B=1+3+5+7=16\). As a check, \(R_A+R_B=20+16=36\), which equals \(8(9)/2=36\), the sum of ranks 1 through 8. This calculation identifies the observed rank sum; deciding whether it is unusual requires a null-distribution calculation.
Ties and the Mann–Whitney Equivalence
Tied observations receive average ranks whether the tie occurs within one group or across groups. Averaging preserves the total rank sum. For example, if three pooled observations tie for ranks 4, 5, and 6, each receives rank \((4+5+6)/3=5\). This convention is essential: assigning arbitrary different ranks to equal values would make the result depend on an arbitrary ordering.
The equivalence with the Mann–Whitney formulation can be shown by examining pairs with one observation from each group. Define \(U_1\) to count, across all \(n_1n_2\) cross-group pairs, one point when a group 1 value is larger than its group 2 value, zero when it is smaller, and one-half for a tie. With ranks formed from the pooled observations,
To justify the relationship, consider the contributions to the rank sum \(R_1\). Each group 1 observation’s rank includes its position relative to the other group 1 observations and relative to every group 2 observation. The within-group contributions, added across group 1, total \(1+2+\cdots+n_1=n_1(n_1+1)/2\). This remains true with ties because average ranks give each within-group tied pair a total contribution of 1. Each cross-group pair contributes 1 to the group 1 rank sum if the group 1 value is larger, 0 if it is smaller, and one-half if tied. Those cross-group contributions sum to \(U_1\). Subtracting the within-group total gives the displayed formula.
The complementary count is \(U_2=n_1n_2-U_1\), because each cross-group pair contributes a total of 1 across the two complementary orderings, including a tie split as one-half and one-half. Thus the rank-sum and Mann–Whitney statistics encode the same ordering information. They are not two different tests; they are alternate ways to express the same comparison.
Worked Example: Average Ranks and the Equivalent Pair Count
Imagine two independent groups with hypothetical values A: 2, 4, 4 and B: 1, 3, 4. Assign pooled average ranks and relate the Group A rank sum to its cross-group pair count.
Check the design. The three values in each group are from distinct units, with no pairing across groups, and the measurements share one ordered scale. The rank-sum procedure is therefore appropriate.
In increasing order, the pooled values are \(1_B, 2_A, 3_B, 4_A, 4_A, 4_B\). The three observations equal to 4 occupy ranks 4, 5, and 6, so each receives average rank \((4+5+6)/3=5\). Group A’s ranks are 2, 5, and 5, giving
There are \(n_1(n_1+1)/2=3(4)/2=6\) within-group rank contributions. Therefore \(U_1=R_A-6=12-6=6\). Directly counting cross-group pairs gives the same result: the A value 2 exceeds only B’s 1, contributing 1; the first A value 4 exceeds B’s 1 and 3 and ties B’s 4, contributing \(1+1+0.5=2.5\); the second A value 4 contributes another 2.5. The total is \(1+2.5+2.5=6\). The pair count is shown to establish the equivalence, not to carry out a significance test.
What the Null Hypothesis Does—and Does Not—Say
The null hypothesis \(F_1=F_2\) says that the population distributions are identical. It is broader than a claim that the medians are equal: distributions can have the same median but differ in spread or shape. Conversely, a difference in medians is one possible feature of different distributions, but the rank-sum test is not automatically a test of medians alone.
A median-centered interpretation is justified only under additional structure, such as a location-shift model in which the distributions have the same shape and spread and differ only by a shift. Without that condition, a difference in ranks could reflect other features of the distributions. Accordingly, conclusions should be phrased as evidence about the distributions or their relative ordering, not simply as a statement that the medians differ.
The rank transformation makes the procedure less dependent on the numerical distances between observations: it uses order. That does not make the test assumption-free. It still needs appropriate independence, comparable measurements, and a design that supports the intended inference. Nor does ranking prove that one treatment caused an outcome; causal interpretation depends on the study design, especially whether treatment assignment was randomized.
Worked Example: Similar Medians, Different Distributional Patterns
Consider hypothetical independent samples on the same quantitative scale. Group A has values 1, 5, 5, 5, 9; Group B has values 3, 4, 5, 6, 7. Compare the pooled ranks and state what the rank-sum framing can establish.
Check the design. Assume each value comes from a different unit, the groups are independent, and all measurements are comparable. These conditions make a two-sample rank comparison suitable.
Both groups have median 5. In the pooled ordering, the values are \(1_A, 3_B, 4_B, 5_A, 5_A, 5_A, 5_B, 6_B, 7_B, 9_A\). The four observations tied at 5 occupy ranks 4 through 7, so each receives rank \((4+5+6+7)/4=5.5\). Group A therefore has ranks 1, 5.5, 5.5, 5.5, and 10:
Group B has ranks 2, 3, 5.5, 8, and 9, with sum \(2+3+5.5+8+9=27.5\). The group medians match, but the observations are arranged differently: Group A includes more extreme values, while Group B’s values lie closer to 5. Equal rank sums in this small example do not prove that the population distributions are identical. They illustrate why the test’s null is distributional equality and why neither the median nor one observed rank sum alone gives a complete conclusion.
Common Mistakes
- Treating rank-sum data as paired. The test is for independent groups. If each person contributes a measurement under both conditions, the paired structure must be analyzed with a paired method.
- Calling the test a test of medians in every setting. Its null is that the distributions are identical. A median-only interpretation needs additional assumptions about the shapes of those distributions.
- Ranking groups separately. Ranks must be assigned after pooling both groups. Separate ranks erase the cross-group ordering that the test uses.
- Breaking ties arbitrarily. Equal values receive the average of their pooled ranks. An arbitrary ordering of tied observations can alter the result.
- Assuming ranks eliminate design requirements. Ranking changes how the observations are represented; it does not remove the need for independent observations or a design that supports the inference.
Check Your Understanding
Use these questions to review the design, statistic, and interpretation.
- What must be true about the observations for a two-sample rank-sum test to be appropriate?
- State the standard two-sided null hypothesis in terms of the population distributions.
- Four pooled observations tie for ranks 6, 7, 8, and 9. What rank should each receive, and why?
- In one sentence, explain how the Wilcoxon rank-sum statistic relates to the Mann–Whitney statistic.
- Why is it not always correct to describe the rank-sum test as a test of equal medians?