What Does the Mann-Whitney U Test Compare?
The test works by ranking all observations from both groups together in a single combined list, then checking whether those combined ranks fall randomly across the two groups or cluster systematically. If every Group A observation ranks below every Group B observation, U reaches its minimum of 0. If the groups alternate perfectly, U sits near its midpoint. The p-value measures how surprising the observed U would be if the two populations were identical.
- State H₀ and H₁ — fix the tail direction before examining data
- Combine both samples — pool all observations into one list
- Rank everything together — smallest gets rank 1, largest gets rank N
- Average tied ranks — three values tied at positions 4, 5, 6 each receive rank 5
- Sum ranks per group — find R₁ and R₂; confirm R₁ + R₂ = N(N+1)/2
- Calculate U₁ and U₂ — confirm U₁ + U₂ = n₁ × n₂
- Obtain p-value — exact table, asymptotic approximation, or software
- Decide — reject H₀ if p < α; fail to reject if p ≥ α
- Interpret — state a distributional conclusion, not automatically a median difference
Mann-Whitney U Formula
R₁ = rank sum, Group 1
n₁ = sample size, Group 1
n₂ = sample size, Group 2
N = n₁ + n₂ total
| Symbol | Meaning |
|---|---|
| n₁, n₂ | Sample sizes of Group 1 and Group 2 |
| N | Total observations: n₁ + n₂ |
| R₁, R₂ | Rank sum for Group 1 and Group 2 |
| U₁, U₂ | U statistics for Group 1 and Group 2 |
| α | Significance level (set before data collection) |
| p | p-value from the chosen test method |
| μU | Null mean of U = n₁n₂ / 2 |
| σU | Null standard deviation of U (asymptotic formula below) |
Rank both groups together in a single combined list — never rank each group separately. Group membership is only used after ranking is complete, to split the combined ranks back into R₁ and R₂.
How to Perform the Mann-Whitney U Test
State H₀ and H₁
Two-sided: H₀: the populations are identical; H₁: the distributions differ. Directional: H₁ specifies which group tends to rank higher. The direction must be fixed before seeing the data.
Combine the Samples
Write all n₁ + n₂ observations in one list, keeping the group label with each value.
Rank All Observations Together
Sort from smallest to largest. Assign rank 1 to the smallest, rank 2 to the next, and so on up to rank N. The group label travels with each observation through this step.
Average Tied Ranks
When two or more observations share the same value, give each one the average of the ranks they would have occupied. Three values at positions 4, 5, 6 each receive rank (4+5+6)/3 = 5. This produces fractional ranks when an even number of values are tied.
Calculate Rank Sums
Add the ranks belonging to Group 1 to get R₁. Add ranks for Group 2 to get R₂. Verify: R₁ + R₂ must equal N(N+1)/2. Any other result means an arithmetic error.
Calculate U₁ and U₂
U₁ = R₁ − n₁(n₁+1)/2 and U₂ = n₁n₂ − U₁. Verify: U₁ + U₂ = n₁ × n₂. Fractional values are correct when midranks were used.
Obtain a p-value or Critical Value
Small samples without ties: use the exact method or the Mann-Whitney U table. Ties or larger samples: use a tie-corrected asymptotic approximation or a permutation approach. State which method you used.
Make the Decision
If p < α, reject H₀. If p ≥ α, fail to reject H₀. A non-significant result does not prove the distributions are equal.
Interpret and Report
Describe the result in terms of distributional ordering. Median language is appropriate only when the two distributions have similar shapes and differ primarily by location. Report U, p-value, method, sample sizes, descriptives, and an effect size.
Example 1 — Simple Two-Sided Test (No Ties)
The cleanest possible setup: two groups with no repeated values and complete separation. It locks in the ranking and U calculation before anything more complex arrives.
Problem: Group A: 1, 2, 3, 4, 5. Group B: 6, 7, 8, 9, 10. Do the distributions differ? α = 0.05, two-sided.
Hypotheses: H₀: the distributions are identical. H₁: the distributions differ. n₁ = n₂ = 5, N = 10.
Rank all 10 values together — Group A occupies the entire lower half:
| Value | Group | Rank |
|---|---|---|
| 1 | A | 1 |
| 2 | A | 2 |
| 3 | A | 3 |
| 4 | A | 4 |
| 5 | A | 5 |
| 6 | B | 6 |
| 7 | B | 7 |
| 8 | B | 8 |
| 9 | B | 9 |
| 10 | B | 10 |
Rank sums: R₁ = 1+2+3+4+5 = 15. R₂ = 6+7+8+9+10 = 40. Check: 15+40 = 55 = 10×11/2 ✓
U statistics:
U₁ = 15 − 5×6/2 = 15 − 15 = 0
U₂ = 5×5 − 0 = 25
Check: 0+25 = 25 = 5×5 ✓
Exact two-sided p ≈ 0.00794. U₁ = 0 means every Group A observation ranked below every Group B observation — the most extreme possible outcome for this sample size.
Decision: p = 0.00794 < α = 0.05 → Reject H₀.
✅ Conclusion: Strong evidence that the distributions differ — Group A observations ranked entirely below Group B observations (U₁ = 0, U₂ = 25, exact two-sided p = 0.00794).
Example 2 — One-Sided vs Two-Sided (Same Data, Different Outcomes)
This example shows why the tail direction matters in practice. With the same data, a two-sided test misses significance at α = 0.05 while a correctly prespecified one-sided test would reject H₀. The direction must be committed to before seeing the results — not selected after.
Problem: Group A: 1, 2, 3, 4, 8. Group B: 5, 6, 7, 9, 10. Prior hypothesis: Group A scores tend to be lower. α = 0.05.
| Value | Group | Rank |
|---|---|---|
| 1 | A | 1 |
| 2 | A | 2 |
| 3 | A | 3 |
| 4 | A | 4 |
| 5 | B | 5 |
| 6 | B | 6 |
| 7 | B | 7 |
| 8 | A | 8 |
| 9 | B | 9 |
| 10 | B | 10 |
Rank sums: R₁ = 1+2+3+4+8 = 18. R₂ = 5+6+7+9+10 = 37. Check: 55 ✓
U statistics: U₁ = 18 − 15 = 3. U₂ = 25 − 3 = 22. Check: 25 ✓
Exact p-values:
Two-sided p ≈ 0.05556 → at α = 0.05, fail to reject H₀
One-sided p (A < B, prespecified) ≈ 0.02778 → at α = 0.05, reject H₀
If the two-sided test was the plan, the one-sided result is off-limits. Switching direction after seeing p = 0.056 is a form of p-hacking that inflates the Type I error rate well above the nominal α.
✅ If H₁: A < B was registered before data collection: reject H₀ (U₁ = 3, one-sided p = 0.02778 < 0.05). Group A values tended to rank lower than Group B values.
Example 3 — Fail to Reject (Intermingled Groups)
Problem: Group A: 1, 3, 5, 7, 9. Group B: 2, 4, 6, 8, 10. Two-sided test at α = 0.05.
| Value | Group | Rank |
|---|---|---|
| 1 | A | 1 |
| 2 | B | 2 |
| 3 | A | 3 |
| 4 | B | 4 |
| 5 | A | 5 |
| 6 | B | 6 |
| 7 | A | 7 |
| 8 | B | 8 |
| 9 | A | 9 |
| 10 | B | 10 |
Rank sums: R₁ = 1+3+5+7+9 = 25. R₂ = 2+4+6+8+10 = 30. Check: 55 ✓
U statistics: U₁ = 25 − 15 = 10. U₂ = 25 − 10 = 15. Check: 25 ✓
Exact two-sided p ≈ 0.69048. The groups alternate almost perfectly — no rank clustering favors either one.
✗ Fail to Reject H₀ — p = 0.690 ≫ 0.05. Insufficient evidence that the distributions differ. This is not evidence of equality; it is absence of evidence against H₀.
Example 4 — Tied Observations (Midranks)
Ties are common in real data. Each tied observation receives the average of the ranks it would have occupied — a midrank. Ties also affect the variance used in asymptotic p-value calculations, so the tie correction matters beyond just the ranking step.
Problem: Group A: 1, 2, 2, 4, 5. Group B: 2, 3, 3, 4, 6. Two-sided test at α = 0.05.
Ten observations: 1, 2, 2, 2, 3, 3, 4, 4, 5, 6 — the value 2 appears three times, 3 appears twice, 4 appears twice.
| Value | Positions occupied | Midrank assigned | Group(s) |
|---|---|---|---|
| 1 | 1 | 1 | A |
| 2 | 2, 3, 4 | 3 | A (×2), B (×1) |
| 3 | 5, 6 | 5.5 | B (×2) |
| 4 | 7, 8 | 7.5 | A (×1), B (×1) |
| 5 | 9 | 9 | A |
| 6 | 10 | 10 | B |
Assign ranks to each observation by group:
Group A: 1→1, 2→3, 2→3, 4→7.5, 5→9
Group B: 2→3, 3→5.5, 3→5.5, 4→7.5, 6→10
Rank sums:
R₁ = 1+3+3+7.5+9 = 23.5
R₂ = 3+5.5+5.5+7.5+10 = 31.5
Check: 23.5+31.5 = 55 = 10×11/2 ✓
U statistics:
U₁ = 23.5 − 5×6/2 = 23.5 − 15 = 8.5
U₂ = 25 − 8.5 = 16.5
Check: 8.5+16.5 = 25 ✓ (fractional U is correct with midranks)
p-value (tie-corrected asymptotic, two-sided) ≈ 0.456. U₁ = 8.5 sits close to the null mean of 12.5 — no systematic rank difference.
✗ Fail to Reject H₀ — p ≈ 0.456 > 0.05. No significant distributional difference detected.
When ties are present, applying the standard no-tie exact U distribution produces an inaccurate p-value. Use a tie-corrected asymptotic method or a properly configured permutation test instead. Always document which method produced the p-value you report.
Example 5 — Critical Value Table Method
Problem: Group A: 3, 7, 9, 12. Group B: 5, 10, 15, 18. Two-sided test at α = 0.05 using the Mann-Whitney U critical value table.
| Value | Group | Rank |
|---|---|---|
| 3 | A | 1 |
| 5 | B | 2 |
| 7 | A | 3 |
| 9 | A | 4 |
| 10 | B | 5 |
| 12 | A | 6 |
| 15 | B | 7 |
| 18 | B | 8 |
Rank sums: R₁ = 1+3+4+6 = 14. R₂ = 2+5+7+8 = 22. Check: 36 = 8×9/2 ✓
U statistics: U₁ = 14 − 4×5/2 = 14 − 10 = 4. U₂ = 16 − 4 = 12. Check: 16 ✓
Table lookup: For n₁ = n₂ = 4, α = 0.05 two-tailed, the Mann-Whitney U table gives critical value U* = 0. Many two-tailed tables at this sample size require the minimum of U₁ and U₂ to be ≤ U*. min(4, 12) = 4 > 0 → fail to reject H₀.
Some tables use min(U₁, U₂); others accept either value but require the observed statistic to fall below (not above) the critical value. Read the table's own instructions before comparing. See the downloadable α = 0.05 U table (PDF).
✗ Fail to Reject H₀ at α = 0.05 (table method). With only four observations per group, very few rank arrangements reach significance.
Example 6 — Large-Sample Normal Approximation
Problem: Group A (n₁ = 10) yields R₁ = 85. Group B (n₂ = 10) yields R₂ = 125. No ties. Two-sided test at α = 0.05.
Verify rank sum: N = 20, N(N+1)/2 = 210. R₁+R₂ = 85+125 = 210 ✓
U statistics: U₁ = 85 − 10×11/2 = 85 − 55 = 30. U₂ = 100 − 30 = 70. Check: 100 ✓
Null mean and SD:
μU = 10×10/2 = 50
σU = √[10×10×21/12] = √175 = 13.229
z statistic (U₁ = 30, no continuity correction):
z = (30 − 50) / 13.229 = −20 / 13.229 = −1.512
Two-sided p ≈ 2 × Φ(−1.512) ≈ 0.130
✗ Fail to Reject H₀ — p ≈ 0.130 > 0.05. Insufficient evidence that the distributions differ.
Example 7 — Ordinal Data
Problem: Pain relief rated 1–5. Group Drug: 2, 3, 4, 4, 5. Group Placebo: 1, 2, 2, 3, 3. Prespecified H₁: Drug ratings tend to be higher. α = 0.05.
| Value | Positions | Midrank | Group(s) |
|---|---|---|---|
| 1 | 1 | 1 | Placebo |
| 2 | 2, 3, 4 | 3 | Drug (×1), Placebo (×2) |
| 3 | 5, 6, 7 | 6 | Drug (×1), Placebo (×2) |
| 4 | 8, 9 | 8.5 | Drug (×2) |
| 5 | 10 | 10 | Drug |
Drug ranks: 2→3, 3→6, 4→8.5, 4→8.5, 5→10. R₁ = 3+6+8.5+8.5+10 = 36
Placebo ranks: 1→1, 2→3, 2→3, 3→6, 3→6. R₂ = 1+3+3+6+6 = 19
Check: 36+19 = 55 ✓
U: U₁ = 36 − 15 = 21. U₂ = 25 − 21 = 4. Check: 25 ✓
One-sided p (Drug > Placebo, tie-corrected) ≈ 0.039. Drug group ranks cluster near the top.
✅ Reject H₀ — p ≈ 0.039 < 0.05. Drug observations tended to rank higher than Placebo observations (U₁ = 21, U₂ = 4). Note: the result concerns rank ordering on a 1–5 scale, not a mean difference.
Exact vs Asymptotic Methods
The p-value can be obtained several ways, and software packages do not all use the same default. Two programs can return different p-values from the same data without either being wrong — they are using different methods.
Choosing a p-value Method
No universal sample-size rule governs this choice. Follow your software's documentation and report which method produced the p-value.
Does the Mann-Whitney U Test Compare Medians?
The most widespread misconception in applied nonparametric statistics. The test is not a general test of median equality.
"The Mann-Whitney U test showed the medians were significantly different." This requires additional assumptions about distributional shape that are not part of the test itself.
The general null says the two population distributions are identical. A significant result says that rank ordering differs — a stochastic ordering statement. Median language is only valid when the two distributions have approximately the same shape and differ only in location (a location-shift model). When that holds, a rank-ordering difference and a median difference are equivalent. When it does not, they are not.
| Situation | Appropriate wording |
|---|---|
| General case (no shape assumption) | Group A observations tended to rank lower than Group B (U₁ = 0, p = 0.008) |
| Incorrect for general case | The Group A median was significantly lower than the Group B median |
| Location-shift model justified by subject knowledge | Evidence of a location difference — Group A's central tendency was lower (p = 0.008) |
Mann-Whitney U vs Related Tests
Mann-Whitney U vs Wilcoxon Rank-Sum
These are the same procedure under different names. If R₁ is the rank sum for the first sample, then U₁ = R₁ − n₁(n₁+1)/2. The reported statistic may look different between software programs, but the test inference is equivalent. Note that the Wilcoxon signed-rank test is a completely separate procedure designed for paired data.
| Mann-Whitney U | Wilcoxon Signed-Rank | |
|---|---|---|
| Data structure | Two independent groups | Paired or matched observations |
| What is ranked | All observations pooled together | Absolute values of within-pair differences |
| Key statistic | U₁ and U₂ (rank sums minus correction) | W (sum of positive signed ranks) |
| Design | Between-subjects comparison | Within-subject or before/after |
Mann-Whitney U vs Independent-Samples t-Test
The t-test targets the difference in population means; the Mann-Whitney U test targets distributional ordering. Choosing between them depends on the research question and measurement scale — not simply on passing or failing a normality test. Running Shapiro-Wilk and then selecting the method based on its outcome is a pre-testing strategy that complicates overall inference.
Mann-Whitney U vs Kruskal-Wallis
The Kruskal-Wallis test extends this framework to three or more independent groups. For exactly two groups, use Mann-Whitney U. For three or more, use Kruskal-Wallis. Worked examples for that case are in the Kruskal-Wallis examples guide.
Mann-Whitney U Effect Size
A p-value alone does not convey the size of a group difference. Two measures are commonly reported alongside U.
Rank-Biserial Correlation
One common formula: r = 2U₁ / (n₁n₂) − 1, where the sign depends on the U orientation. Convention varies between packages, so state which group's U was used. The result ranges from −1 to +1, where ±1 means one group's observations all ranked above the other's.
These cutoffs are heuristics, not laws. Interpret effect size in the context of your field and the research question at hand.
Probability of Superiority
U₁ / (n₁n₂) estimates the probability that a randomly chosen Group 1 observation exceeds a randomly chosen Group 2 observation (ties contribute 0.5 under standard conventions). In Example 1, this is 0/25 = 0.00 — every Group B observation ranked above every Group A observation. In Example 3, it is 10/25 = 0.40, close to the 0.50 null value, which is consistent with a non-significant result.
How to Report Mann-Whitney U Results
- General (distribution wording): "A Mann-Whitney U test indicated that the distributions differed between groups, U₁ = 0, p = 0.008 (exact, two-sided). Group A observations tended to rank lower than Group B observations (rank-biserial r = −1.00)."
- Fail to reject: "A Mann-Whitney U test provided no evidence that the distributions differed, U₁ = 10, p = 0.690 (exact, two-sided)."
- With descriptives and effect size: "Group A (n = 5; median = 3, IQR = 2–4) ranked lower than Group B (n = 5; median = 8, IQR = 7–9), U₁ = 0, p = 0.008, rank-biserial r = −1.00."
- Asymptotic method: "Mann-Whitney U test with tie-corrected asymptotic approximation: U = 30, z = −1.51, p = .130 (two-sided)."
Mann-Whitney U Calculator
Enter two groups of numbers separated by commas. The calculator ranks all values together, assigns midranks to ties, computes R₁, R₂, U₁, U₂, and returns an asymptotic p-value with tie correction. For small samples, verify small p-values with an exact method.
🔬 Mann-Whitney U Test Calculator
Common Mistakes
| Mistake | Why it's wrong | Correction |
|---|---|---|
| Ranking each group separately | Produces wrong R values — the test requires ranks from a combined pool | Pool all N observations, sort together, assign ranks, then split back by group |
| Ignoring tied ranks | Assigning sequential ranks to tied values arbitrarily biases R₁ and U | Give each tied observation the average of the ranks it would have occupied |
| Calling it a median test | Medians can be equal while distributions still differ in shape or tails | Describe significance as distributional ordering; use median language only with explicit shape assumptions |
| Using it for paired data | Paired observations violate the independence assumption between groups | Use the Wilcoxon signed-rank test for matched pairs or before/after designs |
| Choosing one-sided after seeing results | Selecting the tail direction after data inspection inflates the Type I error rate | Fix the direction in H₁ before collecting or examining data |
| p > α means equal distributions | Failing to reject H₀ is not proof of equality — it is insufficient evidence against H₀ | Write "insufficient evidence that the distributions differ," not "distributions are the same" |
| Assuming the smaller U is always reported | Textbook tables often use min(U₁, U₂), but software typically returns U for the first sample supplied | Report both U₁ and U₂, and state which sample's U the software returned |
Practice Problems
Problem: Group A: 4, 7, 11. Group B: 2, 8, 15. Two-sided test at α = 0.05. Show all ranks, R₁, R₂, U₁, and U₂.
R₁ = 2+3+5 = 10. R₂ = 1+4+6 = 11. Check: 21 = 6×7/2 ✓
U₁ = 10 − 3×4/2 = 4. U₂ = 9 − 4 = 5. Check: 9 ✓
Exact two-sided p ≈ 1.00 at n=3 each — with only 3 observations per group, virtually no arrangement reaches significance at α = 0.05. Fail to reject H₀.
Problem: Group A: 5, 5, 8, 10. Group B: 3, 5, 7, 9. Assign midranks, compute R₁, R₂, U₁, U₂. Two-sided test at α = 0.05.
Group A: 5→3, 5→3, 8→6, 10→8. R₁ = 3+3+6+8 = 20
Group B: 3→1, 5→3, 7→5, 9→7. R₂ = 1+3+5+7 = 16. Check: 36 = 8×9/2 ✓
U₁ = 20 − 10 = 10. U₂ = 16 − 10 = 6. Check: 16 ✓
Tie-corrected asymptotic p ≈ 0.54. Fail to reject H₀.
Problem: A researcher predicts (before data collection) that a new drug produces lower pain scores. Group Drug: 2, 3, 4, 5. Group Placebo: 4, 6, 7, 8. Test H₁: Drug < Placebo at α = 0.05.
Drug ranks: 1, 2, 3.5, 5. R₁ = 11.5
Placebo ranks: 3.5, 6, 7, 8. R₂ = 24.5. Check: 36 ✓
U₁ = 11.5 − 10 = 1.5. U₂ = 16 − 1.5 = 14.5
One-sided p (Drug < Placebo, tie-corrected asymptotic) ≈ 0.041. Reject H₀ — Drug group ranked lower.
Problem: For each scenario, choose Mann-Whitney U, Wilcoxon signed-rank, or Kruskal-Wallis: (a) Pain scores for the same patients before and after treatment. (b) Satisfaction ratings for three independent stores. (c) Exam scores for two separate classes.
(b) Kruskal-Wallis — three independent groups; see the Kruskal-Wallis examples page.
(c) Mann-Whitney U — two independent groups (separate classes) with rankable scores.
Problem: A test returns U₁ = 18, U₂ = 7, n₁ = n₂ = 5, two-sided p = 0.15. (a) State the correct conclusion. (b) Compute the rank-biserial r using U₂. (c) What does p = 0.15 mean?
(b) Rank-biserial r using U₂: r = 2×7/(5×5) − 1 = 14/25 − 1 = −0.44. (Sign depends on orientation — document which group's U was used.)
(c) p = 0.15 means: if the two populations were identical, 15% of random samples would produce a U this extreme or more so. It does not mean H₀ is 85% likely to be true.
Frequently Asked Questions
U₁ and U₂ are complementary — they always sum to n₁ × n₂, so knowing one gives you the other immediately. Both arise from the same ranking and carry equivalent information. Report both for transparency. Some textbook tables require the smaller one; software typically returns U for the first sample supplied. State your convention clearly when reporting.
Yes. When tied observations receive midranks, the rank sums R₁ and R₂ can be non-integer, producing fractional U values. Example 4 above gives U₁ = 8.5 and U₂ = 16.5. This is correct, not an error — it confirms that average midrank treatment of ties was applied.
No. It avoids the normality assumption of classical parametric tests, but it still requires that observations are rankable, that the two groups are independent of each other, and that observations within each group are independent. The interpretation of results also depends on distributional context — whether a difference in rank ordering reflects a location or median difference depends on additional shape assumptions.
Several sources of variation exist: exact versus asymptotic versus permutation method; whether a continuity correction is applied; how ties are handled in the variance calculation; whether the one-sided p is defined relative to the left or right tail; and which sample's U is returned. Document your method — neither result is automatically wrong if both are internally consistent.
No. This test is designed for two independent groups where observations in one group have no relationship to observations in the other. For before/after measurements on the same subjects, matched pairs, or repeated measures, use the Wilcoxon signed-rank test instead.
Not in general. The general null hypothesis concerns the full distributions — whether one population's observations tend to rank higher than the other's. A median interpretation is only justified when the two distributions are assumed to have the same shape and differ only in location (a location-shift model). When that assumption holds, a rank difference and a median difference are equivalent statements. Without it, they are not.
They are the same test under different names and parameterizations. The Wilcoxon rank-sum statistic W equals R₁, the rank sum for the first sample. The Mann-Whitney U₁ = W − n₁(n₁+1)/2. Because the formulas differ, the reported number looks different even though the inference is identical. The Wilcoxon signed-rank test, by contrast, is an entirely separate procedure for paired data.
Key Takeaways
The Mann-Whitney U test answers a specific question: do two independent groups draw their observations from the same distribution, or does one group's observations tend to rank systematically higher? Getting the ranking right — pooling both samples, sorting together, handling ties with midranks — leads directly to correct U statistics. The p-value method (exact, asymptotic, or permutation) and the U orientation are reporting choices that matter for reproducibility; always document both.
For the full theory, assumptions, and when to prefer this test over parametric alternatives, see the Mann-Whitney U test guide. For critical values, visit the Mann-Whitney U table. For help selecting among nonparametric tests, try the statistical test selector.