Mann-Whitney U Test Calculator (Wilcoxon Rank-Sum Test)
By FindMySum · Last reviewed
The Mann–Whitney U test, also called the Wilcoxon rank-sum test, compares two independent groups without assuming that the data follow a normal distribution. Instead of the values themselves, it uses their ranks, which makes it robust to outliers and suitable for ordinal data such as survey ratings. This calculator ranks your two samples, computes the U statistic and the rank sums, and gives the p-value either exactly or from the normal approximation, along with three effect sizes and the Hodges–Lehmann estimate of the shift between the groups.
How the test works
Pool the two samples and sort all the values from smallest to largest. Give each value its rank: 1 for the smallest, N = n₁ + n₂ for the largest. When values tie, each gets the average of the ranks they span (midranks). Then add up the ranks of sample 1 to get R₁.
U₁ = R₁ − n₁(n₁ + 1)/2
U₁ counts, over every pair of one value from each sample, how many times the sample-1 value is larger (ties count one half). It runs from 0, when every sample-1 value is smaller than every sample-2 value, to n₁n₂, when every one is larger. U₂ = n₁n₂ − U₁ counts the opposite. If the groups come from the same distribution, U₁ should be near its expected value n₁n₂/2.
The p-value
For small samples without ties, the calculator uses the exact null distribution of U: the share of all equally likely arrangements of the ranks that give a U at least as extreme as yours. It is computed with the recursion Mann and Whitney published in 1947, and matches SciPy's mannwhitneyu with method="exact".
For larger samples, or when there are ties, U is close to normal with mean n₁n₂/2 and variance
σ² = n₁n₂/12 × ((N + 1) − Σ(t³ − t)/(N(N − 1)))
where t is the size of each group of tied values. The calculator applies a continuity correction of ½, as SciPy and R do by default, and you can switch it off. "Automatic" uses the exact method when there are no ties and both samples have 20 values or fewer.
Worked example
The default data are two small groups of measurements: sample 1 has 8 values (7.1, 8.4, 6.2, 9.5, 7.8, 8.9, 10.2, 6.9) and sample 2 has 7 (5.4, 6.1, 4.9, 7.0, 5.8, 6.6, 5.2).
- Ranking all 15 values, sample 1's ranks add up to R₁ = 89 and sample 2's to 31.
- U₁ = 89 − 8 × 9/2 = 53, and U₂ = 8 × 7 − 53 = 3. Only 3 of the 56 pairs have the sample-2 value larger.
- There are no ties and both samples are small, so the exact two-sided p-value is 0.0022. The one-sided p for "sample 1 is larger" is 0.0011.
- The normal approximation with continuity correction would give 0.0046: close, but less accurate for samples this small.
- Rank-biserial correlation: 2 × 53/56 − 1 = 0.89, a very large effect. The probability that a random sample-1 value beats a random sample-2 value is 53/56 = 0.946.
- Hodges–Lehmann shift: the median of the 56 differences is 2.25, so sample 1 is about 2.25 units higher.
Effect sizes
A p-value says whether a difference is likely to be real, not how large it is. The rank-biserial correlation (2U₁/(n₁n₂) − 1) is the difference between the proportion of pairs favouring sample 1 and the proportion favouring sample 2. The common-language effect size U₁/(n₁n₂) is the probability of superiority. r = z/√N converts the normal-approximation z into a correlation-like scale, where 0.1, 0.3 and 0.5 are often called small, medium and large. The Hodges–Lehmann estimate is the most practical: a shift in the original units.
When to use something else
Use a paired test (the Wilcoxon signed-rank test) when each value in one sample is matched with one in the other, such as before-and-after measurements on the same people. With three or more groups, the Kruskal–Wallis test extends the same idea. If your data are roughly normal, the t-test compares means directly and gives a confidence interval for the difference; the Mann–Whitney test is the safer choice when you can't rely on that assumption.
More questions
What sample size do I need for a Mann–Whitney U test?
The test works with very small samples, but it cannot reach significance if they are tiny: with 3 values in each group, the smallest possible two-sided exact p-value is 0.1. As a rule of thumb, aim for at least 5 to 10 per group, and plan larger samples with a power analysis if you expect a modest effect.
Do the two samples need the same size?
No. The test handles unequal group sizes directly; n₁ and n₂ enter the formulas separately. Very unequal sizes reduce power compared with the same total split evenly, but the p-value remains valid.
What are the assumptions of the Mann–Whitney test?
The observations are independent within and between the groups, and the variable is at least ordinal, so values can be ranked. To interpret a significant result as a difference in medians, the two distributions should have roughly the same shape; otherwise it tells you that one group tends to have larger values, which can come from a difference in spread.
How do I report the result?
Give the group medians, U, the sample sizes, the p-value and an effect size, for example: 'Scores were higher in group A (median 8.1) than in group B (median 5.8), U = 53, n₁ = 8, n₂ = 7, exact p = 0.002, rank-biserial r = 0.89.' Say whether the test was one- or two-sided and exact or approximate.
Why does my statistics package give a different p-value?
Packages differ in their defaults: exact versus normal approximation, whether the continuity correction is applied, and how ties are handled. SciPy's mannwhitneyu and R's wilcox.test both use the continuity correction by default. Set the same options in the advanced section to match them.
Sources
- Mann, H. B. and Whitney, D. R. (1947). On a Test of Whether one of Two Random Variables is Stochastically Larger than the Other. Annals of Mathematical Statistics 18(1)
- SciPy documentation: scipy.stats.mannwhitneyu
- NIST/SEMATECH e-Handbook of Statistical Methods: Mann–Whitney U test (nonparametric two-sample comparisons)
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.