How to do a Mann–Whitney U test (worked example, table of critical values, ties, effect size)
The Mann–Whitney U test compares two independent groups using ranks instead of the raw values. It is robust to outliers and skewed data, but it has little power with very small samples. With a 7-vs-7 example, this guide walks through ranking, U, the P value and the effect size so you can check every number by hand.
Mann–Whitney U test calculatorPaste two groups and choose “Mann–Whitney”: U, P (exact or normal approximation) and a results sentence.Calculate →When to use it
- Two independent groups (different animals or samples)
- All values are ranked together and compared by rank, so outliers and skew matter little
- If the data are close to normal, Welch’s t test is more powerful
- For paired data use the Wilcoxon signed-rank test; for three or more groups, the Kruskal–Wallis test
It is widely used for concentrations, counts and scores, which often have a long right tail or occasional extreme values. See choosing a statistical test for the bigger picture.
The steps
- Pool the two groups, sort, and rank from 1 (tied values get the average rank)
- Add up the ranks in each group, R₁ and R₂
- Compute U₁ = R₁ − n₁(n₁ + 1)/2 and U₂ = n₁n₂ − U₁
- The smaller U = min(U₁, U₂), the more clearly the groups separate. Use the exact distribution for small samples without ties, otherwise the normal approximation
Example: 7 vs 7
Plasma concentration in a control and a treated group (n = 7 each, made up). Sort all 14 values and rank them.
| Group | Values | Ranks (all 14 values in order) | Rank sum R |
|---|---|---|---|
| Control | 2.8, 3.1, 3.4, 3.9, 4.1, 4.5, 5.2 | 1 + 2 + 3 + 4 + 5 + 7 + 9 | 31 |
| Treated | 4.4, 4.9, 5.8, 6.1, 7.2, 9.4, 12.6 | 6 + 8 + 10 + 11 + 12 + 13 + 14 | 74 |
R₁ = 31, so U₁ = 31 − 7 × 8 / 2 = 3 and U₂ = 49 − 3 = 46; U = 3. In only 3 of the 49 possible pairs is the control value higher than the treated value.
| Result | |
|---|---|
| Mann–Whitney U test (exact P) | U = 3, P = 0.0041 |
| Same, normal approximation (continuity-corrected) | z = 2.68, P = 0.0073 |
| Effect size (rank-biserial r) | r = 0.88 |
| For comparison: Welch’s t test | t(7.0) = 2.94, P = 0.022 |
The value 12.6 in the treated group inflates the mean and SD, so Welch’s t test gives P = 0.022; in ranks it is simply “the largest”, so its influence on the Mann–Whitney test is limited.
How to do it: by hand, in R, in Python, in BenchFig
By hand: compute U as above, then look up n₁ = n₂ = 7 in the table of critical values below. The two-tailed critical value is 8 at 0.05 and 4 at 0.01. U = 3 is below both, so the difference is significant even at the 1% level (consistent with the exact P = 0.0041).
R: use wilcox.test(a, b) (two-sided by default). The reported W is U for the first group (U₁), here W = 3. Up to R 4.5, an exact P is computed when each sample has fewer than 50 values and there are no ties; otherwise a normal approximation with continuity correction is used. Since R 4.6.0, wilcox.test also computes an exact (conditional) P when there are ties, so with tied data the P value can depend on the R version. State your R version.
b <- c(5.8, 4.9, 7.2, 6.1, 9.4, 4.4, 12.6)
wilcox.test(a, b) # W = 3, exact P = 0.00408
Python: use SciPy’s scipy.stats.mannwhitneyu(a, b). The defaults are two-sided and method='auto' (exact when one group has 8 or fewer values and there are no ties). The returned statistic is U₁ for the first group, so report the smaller U = min(U₁, n₁n₂ − U₁).
res = mannwhitneyu(a, b)
print(res.statistic, res.pvalue) # 3.0 0.004079…
BenchFig: paste two columns into the free t test / Mann–Whitney calculator and choose “Mann–Whitney” to get the smaller U, the P value (labelled exact or normal approximation) and a results sentence. On the Graph screen, set Test type to Nonparametric.
Mann–Whitney U table of critical values (two-tailed 0.05 and 0.01, n = 2–20)
Use this table when you work by hand or want to check software output. How to read it: find the cell where row n₁ meets column n₂. The result is significant if the observed U (the smaller of U₁ and U₂ = n₁n₂ − U₁) is less than or equal to the table value. For example, with 7 vs 7 and U = 3, U is below both the 0.05 critical value (8) and the 0.01 critical value (4), so it is significant at the 1% level. A “—” means no outcome can be significant at that sample size.
The values come from the exact distribution without ties (the largest U for which the two-tailed P = 2 × P(U ≤ value) is at most α), and every cell was checked against SciPy’s exact P. With many ties or n above 20, use the normal approximation or software.
Two-tailed α = 0.05
| n₁ \ n₂ | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | — | — | — | — | — | — | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 2 | 2 | 2 | 2 |
| 3 | — | — | — | 0 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 | 5 | 5 | 6 | 6 | 7 | 7 | 8 |
| 4 | — | — | 0 | 1 | 2 | 3 | 4 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 11 | 12 | 13 | 14 |
| 5 | — | 0 | 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 |
| 6 | — | 1 | 2 | 3 | 5 | 6 | 8 | 10 | 11 | 13 | 14 | 16 | 17 | 19 | 21 | 22 | 24 | 25 | 27 |
| 7 | — | 1 | 3 | 5 | 6 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 |
| 8 | 0 | 2 | 4 | 6 | 8 | 10 | 13 | 15 | 17 | 19 | 22 | 24 | 26 | 29 | 31 | 34 | 36 | 38 | 41 |
| 9 | 0 | 2 | 4 | 7 | 10 | 12 | 15 | 17 | 20 | 23 | 26 | 28 | 31 | 34 | 37 | 39 | 42 | 45 | 48 |
| 10 | 0 | 3 | 5 | 8 | 11 | 14 | 17 | 20 | 23 | 26 | 29 | 33 | 36 | 39 | 42 | 45 | 48 | 52 | 55 |
| 11 | 0 | 3 | 6 | 9 | 13 | 16 | 19 | 23 | 26 | 30 | 33 | 37 | 40 | 44 | 47 | 51 | 55 | 58 | 62 |
| 12 | 1 | 4 | 7 | 11 | 14 | 18 | 22 | 26 | 29 | 33 | 37 | 41 | 45 | 49 | 53 | 57 | 61 | 65 | 69 |
| 13 | 1 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 33 | 37 | 41 | 45 | 50 | 54 | 59 | 63 | 67 | 72 | 76 |
| 14 | 1 | 5 | 9 | 13 | 17 | 22 | 26 | 31 | 36 | 40 | 45 | 50 | 55 | 59 | 64 | 69 | 74 | 78 | 83 |
| 15 | 1 | 5 | 10 | 14 | 19 | 24 | 29 | 34 | 39 | 44 | 49 | 54 | 59 | 64 | 70 | 75 | 80 | 85 | 90 |
| 16 | 1 | 6 | 11 | 15 | 21 | 26 | 31 | 37 | 42 | 47 | 53 | 59 | 64 | 70 | 75 | 81 | 86 | 92 | 98 |
| 17 | 2 | 6 | 11 | 17 | 22 | 28 | 34 | 39 | 45 | 51 | 57 | 63 | 69 | 75 | 81 | 87 | 93 | 99 | 105 |
| 18 | 2 | 7 | 12 | 18 | 24 | 30 | 36 | 42 | 48 | 55 | 61 | 67 | 74 | 80 | 86 | 93 | 99 | 106 | 112 |
| 19 | 2 | 7 | 13 | 19 | 25 | 32 | 38 | 45 | 52 | 58 | 65 | 72 | 78 | 85 | 92 | 99 | 106 | 113 | 119 |
| 20 | 2 | 8 | 14 | 20 | 27 | 34 | 41 | 48 | 55 | 62 | 69 | 76 | 83 | 90 | 98 | 105 | 112 | 119 | 127 |
Two-tailed α = 0.01
| n₁ \ n₂ | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | — | 0 | 0 |
| 3 | — | — | — | — | — | — | — | 0 | 0 | 0 | 1 | 1 | 1 | 2 | 2 | 2 | 2 | 3 | 3 |
| 4 | — | — | — | — | 0 | 0 | 1 | 1 | 2 | 2 | 3 | 3 | 4 | 5 | 5 | 6 | 6 | 7 | 8 |
| 5 | — | — | — | 0 | 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 6 | — | — | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 |
| 7 | — | — | 0 | 1 | 3 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | 24 |
| 8 | — | — | 1 | 2 | 4 | 6 | 7 | 9 | 11 | 13 | 15 | 17 | 18 | 20 | 22 | 24 | 26 | 28 | 30 |
| 9 | — | 0 | 1 | 3 | 5 | 7 | 9 | 11 | 13 | 16 | 18 | 20 | 22 | 24 | 27 | 29 | 31 | 33 | 36 |
| 10 | — | 0 | 2 | 4 | 6 | 9 | 11 | 13 | 16 | 18 | 21 | 24 | 26 | 29 | 31 | 34 | 37 | 39 | 42 |
| 11 | — | 0 | 2 | 5 | 7 | 10 | 13 | 16 | 18 | 21 | 24 | 27 | 30 | 33 | 36 | 39 | 42 | 45 | 48 |
| 12 | — | 1 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 31 | 34 | 37 | 41 | 44 | 47 | 51 | 54 |
| 13 | — | 1 | 3 | 7 | 10 | 13 | 17 | 20 | 24 | 27 | 31 | 34 | 38 | 42 | 45 | 49 | 53 | 57 | 60 |
| 14 | — | 1 | 4 | 7 | 11 | 15 | 18 | 22 | 26 | 30 | 34 | 38 | 42 | 46 | 50 | 54 | 58 | 63 | 67 |
| 15 | — | 2 | 5 | 8 | 12 | 16 | 20 | 24 | 29 | 33 | 37 | 42 | 46 | 51 | 55 | 60 | 64 | 69 | 73 |
| 16 | — | 2 | 5 | 9 | 13 | 18 | 22 | 27 | 31 | 36 | 41 | 45 | 50 | 55 | 60 | 65 | 70 | 74 | 79 |
| 17 | — | 2 | 6 | 10 | 15 | 19 | 24 | 29 | 34 | 39 | 44 | 49 | 54 | 60 | 65 | 70 | 75 | 81 | 86 |
| 18 | — | 2 | 6 | 11 | 16 | 21 | 26 | 31 | 37 | 42 | 47 | 53 | 58 | 64 | 70 | 75 | 81 | 87 | 92 |
| 19 | 0 | 3 | 7 | 12 | 17 | 22 | 28 | 33 | 39 | 45 | 51 | 57 | 63 | 69 | 74 | 81 | 87 | 93 | 99 |
| 20 | 0 | 3 | 8 | 13 | 18 | 24 | 30 | 36 | 42 | 48 | 54 | 60 | 67 | 73 | 79 | 86 | 92 | 99 | 105 |
Exact P vs normal approximation
Without ties, the distribution of U can be counted exactly over all 14C7 = 3,432 ways of choosing 7 ranks from 14. Seven of them give U ≤ 3, so the two-sided P = 2 × 7 / 3,432 = 0.0041.
For larger samples, counting becomes heavy, so U is treated as normal with mean n₁n₂/2 and SD √(n₁n₂(N + 1)/12). Here z = 2.68 and P = 0.0073, slightly larger than the exact P. With small samples, prefer the exact P.
Like SciPy’s mannwhitneyu (default method='auto'), BenchFig uses the exact distribution when at least one group has n ≤ 8 and there are no ties, and otherwise the normal approximation with tie and continuity corrections, and it shows which one was used.
Handling ties
Tied values share the average of their ranks. If the treated value 4.4 were 4.5, matching a control value, both would get rank (6 + 7)/2 = 6.5 and U = 2.5.
With ties, the exact no-ties distribution no longer applies. Software differs here: SciPy’s default and BenchFig switch to the normal approximation (with a variance correction for ties), giving P = 0.0060; with method='exact', SciPy instead applies the no-ties exact distribution to U = 2.5, which amounts to rounding U up to 3 and gives P = 0.0041 (breaking the tie the other way, U = 2, would give P = 0.0023). When your measurements are coarse and ties are common, stating which method you used makes the result reproducible.
Effect size r
Because P depends on n, report an effect size for the size of the difference. For Mann–Whitney the rank-biserial correlation r is common.
Some authors use r = z/√N instead, which gives a different number, so say which r you report. BenchFig shows the rank-biserial correlation.
How to write it in a paper
Methods: “Two groups were compared using a two-tailed Mann–Whitney U test.” Results: give medians (IQR) with U, P and the effect size, e.g. “Concentrations were higher in the treated group (median 6.1 vs 3.9 ng/mL; U = 3, P = 0.004, r = 0.88).” Medians and IQRs fit the test better than mean ± SD, and a box plot or points with the median suits the figure. For general formats see how to report statistics.
FAQ
Is the Mann–Whitney U test the same as the Wilcoxon rank-sum test?
Yes. Wilcoxon used the rank sum W of one group and Mann and Whitney used U, but U = W − n(n + 1)/2 and the P values are identical. It is a different test from the Wilcoxon signed-rank test for paired data, so name it precisely.
Does it test a difference in medians?
Only if the two distributions have the same shape and differ only in location. In general it tests whether values in one group tend to be larger than in the other. With differently shaped distributions it can be significant even when the medians are equal.
Can I use it with 3 animals per group?
You can compute it, but with 3 vs 3 even the most extreme ordering gives a two-sided P of 2/20 = 0.1, so it can never reach 0.05. With 4 vs 4 the smallest possible P is 0.029. With tiny samples, nonparametric tests have almost no power.
How do I read a Mann–Whitney U table?
Find the cell where n₁ and n₂ meet and compare it with the observed U (the smaller of U₁ and U₂). If U is less than or equal to the table value, the result is significant. The table on this page covers two-tailed 0.05 and 0.01 for n = 2–20, computed from the exact no-ties distribution, and is available as a printable PDF.
Which U should I report, the smaller or the larger?
Papers usually report the smaller one, U = min(U₁, U₂). SciPy’s mannwhitneyu returns U₁ for the first group, so copying it directly can give a different number. BenchFig shows the smaller U.
Related guides
Product and journal names are trademarks or registered trademarks of their respective owners.