The Mann-Whitney U test (also called the Wilcoxon rank-sum test) is the standard way to compare two independent groups when you cannot trust the assumptions of a t-test: the data is skewed, has outliers, or is measured on an ordinal scale such as pain scores or Likert ratings. Instead of comparing means, it compares the ranks of the observations. This guide explains what the test actually asks, works through a small example by hand, and shows how to report the result.
The question the test answers
If you pick one value at random from group A and one from group B, is A just as likely to be larger as B is? Under the null hypothesis the answer is yes (a 50/50 chance). A small p-value says one group tends to produce larger values than the other.
This is why the Mann-Whitney U test is often described loosely as a "test of medians". That description is only accurate when both groups have distributions of the same shape, one simply shifted relative to the other. If one group is tightly clustered and the other is widely spread, the test can be significant even when the medians are identical, or not significant when they differ. When you report the result, describe it as one group tending to have higher values, and show the distributions with a box or violin plot.
How it works: ranks instead of values
- Pool all observations from both groups and sort them from smallest to largest.
- Give each observation its rank: 1 for the smallest, 2 for the next, and so on. Tied values share the average of the ranks they would occupy.
- Add up the ranks belonging to group A. Call this RA.
- Convert it to the U statistic: UA = RA − nA(nA + 1) / 2. UA equals the number of pairs (one value from each group) in which the A value is larger.
- The two U values always add up to nA × nB. Most software reports the smaller one.
Because only the order of the values matters, a single extreme outlier has exactly the same influence as a value that is merely the largest. That is the source of the test's robustness.
A worked example
Suppose you measured reaction times (seconds) in two small groups:
| Group | Values | n |
|---|---|---|
| A | 3, 5, 8, 9 | 4 |
| B | 7, 10, 12, 14, 15 | 5 |
Sorted together, the ranks are: 3 (A, rank 1), 5 (A, 2), 7 (B, 3), 8 (A, 4), 9 (A, 5), 10 (B, 6), 12 (B, 7), 14 (B, 8), 15 (B, 9).
- Rank sum for A: RA = 1 + 2 + 4 + 5 = 12
- UA = 12 − 4 × 5 / 2 = 2. Check by counting: only two pairs have A larger than B (8 > 7 and 9 > 7).
- UB = 4 × 5 − 2 = 18
With samples this small and no ties, the p-value can be calculated exactly by listing every possible way to split the nine ranks into groups of four and five (126 ways). Only 4 of them give a U of 2 or less, so the one-sided probability is 4/126 = 0.032 and the two-sided p-value is 0.063.
Notice the lesson: group B looks clearly higher, yet p is above 0.05. With only nine observations, the test simply does not have enough information to rule out chance. That is not evidence that the groups are the same; it is a sign that the sample is too small. StatFlo uses this exact calculation when both groups have eight or fewer values and there are no ties, and a tie-corrected normal approximation otherwise.
When to use it (and when not to)
| Situation | Mann-Whitney U? |
|---|---|
| Two independent groups, clearly skewed data (e.g. income, reaction times, cytokine levels) | Yes, a good choice |
| Ordinal data: ratings, scores, grades | Yes, the t-test's mean is hard to interpret here |
| A few extreme outliers you have no justification to remove | Yes |
| Roughly normal data with similar spread | Works, but a t-test has slightly more power |
| The same subjects measured twice (before/after) | No, use the Wilcoxon signed-rank test (see paired vs independent data) |
| Three or more groups | No, use the Kruskal-Wallis test |
A common worry is that non-parametric tests are "weaker". For normally distributed data, the Mann-Whitney U test is about 95% as efficient as the t-test, a small price. For heavy-tailed or skewed data it can be considerably more powerful than the t-test, because the t-test's standard deviation gets inflated by the extreme values.
Effect size: how big is the difference?
A p-value says whether a difference is detectable, not how large it is. Two effect sizes pair naturally with U:
- Common-language effect size = UA / (nA × nB). In the example, 2 / 20 = 0.10: a random value from A beats a random value from B only 10% of the time.
- Rank-biserial correlation r = 1 − 2U / (nA × nB), using the smaller U. In the example, 1 − 4/20 = 0.80, a large effect. Values range from 0 (complete overlap) to 1 (no overlap at all).
Reporting a large effect with a non-significant p-value is perfectly legitimate and honest: it tells the reader the study was underpowered rather than that nothing happened.
How to report it
Because the test is based on ranks, report medians and interquartile ranges rather than means and standard deviations:
"Reaction times were longer in group B (median 12 s, IQR 10–14) than in group A (median 6.5 s, IQR 4.5–8.25), but the difference did not reach statistical significance (Mann-Whitney U = 2, nA = 4, nB = 5, exact two-sided p = 0.063; rank-biserial r = 0.80)."
The quartiles above use the same linear interpolation method as Excel's QUARTILE.INC; other software may give slightly different IQRs for very small samples, which is normal.
Running it in StatFlo
- Put each group in its own column with the group name in the first row.
- Upload the file, choose Box Plot or Violin Plot, and keep Show individual data points on.
- Under Statistical Test, choose Mann-Whitney U test and click Generate.
- The results show U, the p-value, the rank-biserial r effect size, and each group's n, median and IQR, followed by a written interpretation. Turn on Significance on graph to add an asterisk bracket.