CalculatorsToolsGuides 日本語
BenchFig › Guides › How to do a Mann–Whitney U test (worked example, table of critical values, ties, effect size)
Statistics

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.

Updated: BenchFig日本語
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

Key points
  • 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

  1. Pool the two groups, sort, and rank from 1 (tied values get the average rank)
  2. Add up the ranks in each group, R₁ and R₂
  3. Compute U₁ = R₁ − n₁(n₁ + 1)/2 and U₂ = n₁n₂ − U₁
  4. 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
U1 = R1 − n1(n1 + 1)2  U2 = n1n2 − U1U₁ equals the number of (control, treated) pairs in which the control value is larger (ties count 0.5).

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.

GroupValuesRanks (all 14 values in order)Rank sum R
Control2.8, 3.1, 3.4, 3.9, 4.1, 4.5, 5.21 + 2 + 3 + 4 + 5 + 7 + 931
Treated4.4, 4.9, 5.8, 6.1, 7.2, 9.4, 12.66 + 8 + 10 + 11 + 12 + 13 + 1474

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 testt(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.

02468101214ControlTreatedConcentration (ng/mL)P = 0.0041
Example data (made up, n = 7 each). Horizontal line = median, vertical line = interquartile range. The treated group has one large value (12.6). P from the Mann–Whitney U test (exact).

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.

a <- c(3.1, 4.5, 2.8, 5.2, 3.9, 4.1, 3.4)
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₁).

from scipy.stats import mannwhitneyu
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.

Download the U table as a PDF (A4, 2 pages)Free, no sign-up. Japanese version here

Two-tailed α = 0.05

Two-tailed α = 0.05 (one-tailed α = 0.025). Significant if the observed (smaller) U is less than or equal to this value. — = cannot be significant at this n. Swapping n₁ and n₂ gives the same value.
n₁ \ n₂234567891011121314151617181920
2——————0000111112222
3———0112233445566778
4——01234456789101111121314
5—012356789111213141517181920
6—123568101113141617192122242527
7—1356810121416182022242628303234
8024681013151719222426293134363841
90247101215172023262831343739424548
100358111417202326293336394245485255
110369131619232630333740444751555862
1214711141822262933374145495357616569
1314812162024283337414550545963677276
1415913172226313640455055596469747883
15151014192429343944495459647075808590
16161115212631374247535964707581869298
172611172228343945515763697581879399105
1827121824303642485561677480869399106112
19271319253238455258657278859299106113119
202814202734414855626976839098105112119127

Two-tailed α = 0.01

Two-tailed α = 0.01 (one-tailed α = 0.005). Significant if the observed (smaller) U is less than or equal to this value. — = cannot be significant at this n. Swapping n₁ and n₂ gives the same value.
n₁ \ n₂234567891011121314151617181920
2—————————————————00
3———————000111222233
4————001122334556678
5———01123456778910111213
6——0123456791011121315161718
7——013467910121315161819212224
8——1246791113151718202224262830
9—013579111316182022242729313336
10—0246911131618212426293134373942
11—02571013161821242730333639424548
12—13691215182124273134374144475154
13—137101317202427313438424549535760
14—147111518222630343842465054586367
15—258121620242933374246515560646973
16—259131822273136414550556065707479
17—2610151924293439444954606570758186
18—2611162126313742475358647075818792
1903712172228333945515763697481879399
20038131824303642485460677379869299105

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.

Switch a two-group sample to Mann–WhitneyChoose Nonparametric to see U, how P was computed (exact or normal approximation) and the effect size r. You can also switch the graph to a box plot or points + median.
Open for free →

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.

r = U1 − U2n1n2From −1 to 1: 0 means no difference, ±1 means complete separation. Here (3 − 46)/49 = −0.88 (0.88 ignoring direction).

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.

Try a Mann–Whitney test on sample dataOpen a two-group sample on the Graph screen and set Test type to Nonparametric to see U, the P value (and how it was computed), the rank-biserial r and a ready-to-paste sentence.
Open for free →
Your own data, all the way to the final figure.Loading your files, saving, and journal-ready export (PDF, TIFF, PNG, SVG) are in BenchFig Pro for Windows, updated based on researchers’ requests: ¥3,980/year (2 PCs), with lab and perpetual licenses too.
About the app →

Related guides

Product and journal names are trademarks or registered trademarks of their respective owners.