MathsStatistics & Probability

Mann-Whitney U Test
calculator.

Compare two independent groups by rank, with no need for normal data.

How it's worked out

The Mann-Whitney U test, also called the Wilcoxon rank-sum test, asks whether a value from one group tends to be larger than a value from the other. It uses only the order of the values, so it copes with skewed data, outliers and rating scales, where a two-sample t test can mislead. For three or more groups, use the Kruskal-Wallis test.

You rank all the values together, smallest first, and tied values share their average rank. R₁ is the sum of the ranks in group 1, and n₁ and n₂ are the group sizes.

U1\displaystyle U_1=R1−n1(n1+1)2\displaystyle {}= R_1 - \frac{n_1(n_1 + 1)}{2}
U2\displaystyle U_2=n1n2−U1\displaystyle {}= n_1 n_2 - U_1

U₁ equals the number of pairs, one value from each group, in which the group 1 value is larger, with ties counted as half. So U1n1n2\frac{U_1}{n_1 n_2} estimates the chance that a group 1 value beats a group 2 value. The tool reports the smaller of the two as U, as tables do.

μU\displaystyle \mu_U=n1n22\displaystyle {}= \frac{n_1 n_2}{2}
c\displaystyle c=N+1−∑(t3−t)N(N−1)\displaystyle {}= N + 1 - \frac{\sum (t^3 - t)}{N(N - 1)}
σU\displaystyle \sigma_U=n1n212×c\displaystyle {}= \sqrt{\frac{n_1 n_2}{12} \times c}

Here N is the total count, and each t is the size of a set of tied values, so c is just N + 1 when nothing ties. With no ties and neither group above 50 values, the tool counts every possible arrangement of the ranks for an exact p-value, as R's wilcox.test does for samples of this size. Otherwise it uses z from the mean and spread above, with an optional 0.5 continuity correction.

Three effect sizes go beside p. r is |z|N\frac{|z|}{\sqrt{N}}, the rank-biserial correlation is 2U1n1n2−1\frac{2U_1}{n_1 n_2} - 1, and the probability of superiority is U1n1n2\frac{U_1}{n_1 n_2}. The Hodges-Lehmann shift is the median of all the differences between the two groups, not the difference between their medians.

Worked examples

Permeability of tissue, a published data set

R's documentation for wilcox.test uses data from Hollander and Wolfe: permeability constants at term against those at 12 to 26 weeks, ten values against five, asking whether the first group is larger.

The first group's ranks add to 90, so U₁ is 35 and the exact one-sided p-value is 0.1272. The rank-biserial correlation is 0.4, a tendency for group 1 to be larger that a sample this small cannot confirm. The smaller U here is 15, and a two-sided test at 0.05 with these sizes would need 8 or less.

Open this example in the tool

Reaction times, eight people per group

Group 1's times run from 12 to 27 and group 2's from 22 to 35, so they overlap only a little. R₁ is 39.5, U₁ is 3.5 and U₂ is 60.5.

3.5+60.5\displaystyle 3.5 + 60.5=64\displaystyle {}= 64

The two groups share the value 22, which is a tie, so the normal approximation applies: z = −2.943 and the two-sided p is 0.0033. The effect size r is 0.736, which reads as large. The Hodges-Lehmann shift is 10.5, so group 1 runs about that much lower.

A single tie is enough to switch off the exact count. No single value changes the verdict at 0.05: leaving one out gives a p-value of at most 0.0054, when 12 goes from group 1.

Open this example in the tool

Pain ratings with many ties

Two groups of nine people rate pain from 1 to 7. Scores repeat often, as they do on any rating scale, so most ranks are shared averages.

U is 6.5. The tie-corrected standard deviation of U is 11.095, z is −3.02 and the two-sided p is 0.0025. Group 1 beats group 2 in only 8% of pairs, with ties counted as half, so the scores in group 2 clearly tend to run higher.

Open this example in the tool

Reading your result

U. A U₁ near half of n1n2n_1 n_2 means the groups overlap evenly. A U₁ near 0 or near n1n2n_1 n_2 means one group almost always wins.

Effect size r. Cohen's thresholds call 0.1 small, 0.3 medium and 0.5 large. The same paper warns that these labels are only heuristics, and they may not match what matters in practice.

Rank-biserial correlation. The share of pairs that favor group 1 minus the share that favor group 2, from −1 to 1. It keeps the direction, which r does not.

Exact critical U. With no ties and a two-sided test, the smaller U must be at or below the value in this table, computed from the same exact counts. With four per group, even complete separation has a two-sided p of 0.029, so tiny samples can barely reach significance at 0.05 and cannot reach it at 0.01.

Largest U that is significant, equal groups
Per groupα = 0.05α = 0.01
40None
520
652
8137
102316
156451
20127105

Common mistakes

  • Calling it a test of medians without checking. GraphPad's note explains that the test compares mean ranks. It reads as a test of medians only if the two distributions have the same shape, shifted. Unequal spreads can give a significant result even when the medians match.
  • Using it on paired data. Each value must come from a different subject and the groups must be unrelated. For before and after readings on the same people, use the Wilcoxon signed-rank test.
  • Reporting only the p-value. A large sample makes tiny differences significant. Give an effect size and the Hodges-Lehmann shift beside it.
  • Expecting an exact p-value with ties. Here, one tied value switches the test to the normal approximation. Other software differs: SciPy's automatic choice is exact only when a sample has 8 or fewer values and there are no ties, so a small gap between programs is normal.

Questions people ask

Use it for rating scales, clearly skewed data or data with outliers. When both groups are roughly normal, the t test has slightly more power, but the rank test gives up little: its efficiency is about 3 over pi, or 0.95. Choose the test before you look at the result, not after.

Sources