Quick answer
The Mann-Whitney U test, or Wilcoxon rank-sum test, compares two independent samples using the ranks of the pooled values. U counts how often a value from one group exceeds a value from the other, so the test suits ordinal and skewed data without assuming normality.
Formula: U1 = R1 − n1(n1 + 1) ÷ 2, where R1 is the rank sum of group 1; U1 + U2 = n1 × n2
What is the Mann-Whitney U test?
The Mann-Whitney U test, also called the Wilcoxon rank-sum test, is a nonparametric test for comparing two independent samples. Instead of working with the values themselves, it pools both samples, sorts them, replaces each value with its position in the sorted list (its rank) and asks whether one group collects noticeably higher ranks than the other. H. B. Mann and D. R. Whitney published the test in 1947 under a title that states the idea: whether one of two random variables is stochastically larger than the other.
Because only the order of the values matters, the test does not assume a normal distribution and a single huge value cannot dominate it. That makes it a common choice for ordinal scores such as 1–5 ratings and for strongly skewed measurements such as spending per customer or time on task.
It still has conditions. The two samples must be independent of each other, each observation should come from a different unit, and the values must be at least orderable. It is not for before-and-after data on the same people; the Wilcoxon signed-rank test covers that.
Worked example: ranks and U for revenue per customer
Two pricing page versions, eight paying customers each, first-order value in dollars (sample data):
- A: 12, 15, 19, 22, 27, 31, 38, 410
- B: 24, 29, 35, 41, 46, 52, 60, 75
Step 1: rank all 16 values together.
| Rank | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Value | 12 | 15 | 19 | 22 | 24 | 27 | 29 | 31 |
| Group | A | A | A | A | B | A | B | A |
| Rank | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
|---|---|---|---|---|---|---|---|---|
| Value | 35 | 38 | 41 | 46 | 52 | 60 | 75 | 410 |
| Group | B | A | B | B | B | B | B | A |
Step 2: sum the ranks. A: 1 + 2 + 3 + 4 + 6 + 8 + 10 + 16 = 50. B: 5 + 7 + 9 + 11 + 12 + 13 + 14 + 15 = 86. Check: 50 + 86 = 136 = 16 × 17 ÷ 2.
Step 3: compute U. U for a group is its rank sum minus the smallest rank sum it could have, n(n + 1) ÷ 2 = 36:
- U for A = 50 − 36 = 14
- U for B = 86 − 36 = 50
- Check: 14 + 50 = 64 = 8 × 8
U has a direct meaning. Compare every A customer with every B customer: in 50 of the 64 pairs the B customer spent more, in 14 the A customer did. The NIST handbook writes the formula the other way round, so its U for A equals 50 here. The two always add up to n₁ × n₂; say which convention you report.
Step 4: p-value. With 8 and 8 values and no ties, the exact two-sided p-value is 0.065; the smaller U of 14 just misses the 5% critical value of 13. The normal approximation gives nearly the same: mean of U = 32, standard deviation √(8 × 8 × 17 ÷ 12) = 9.52, z = (|14 − 32| − 0.5) ÷ 9.52 = 1.84, p = 0.066.
Mann-Whitney vs t test on the same data
| Group A | Group B | |
|---|---|---|
| Mean | $71.75 | $45.25 |
| Median | $24.50 | $43.50 |
| Rank sum | 50 | 86 |
The means say A earns more per customer. The ranks and medians say a typical B customer spends more. Both are true: one $410 order lifts A's total.
| Scenario | Welch t test | Mann-Whitney U |
|---|---|---|
| Data as listed | t = 0.54, p = 0.60 | U = 14, p = 0.065 |
| The $410 order becomes $4,100 | A's mean jumps to $533, p = 0.37 | Unchanged: U = 14, p = 0.065 |
| The $410 order removed (7 vs 8) | t = −3.17, p = 0.009 | U = 6, p = 0.009 |
The rank test is blind to how large the largest value is. That is a strength if the large order is noise and a weakness if revenue totals are what you are paid on. If the business adds the metric up, compare means (with enough data, perhaps with winsorization decided in advance). If you care whether a typical customer is better off, ranks are a fair question. Do not run both and report the smaller p-value. The wider decision table is in which statistical test.
What the test actually tests
It is often described as a test of medians. In general it is not. The null hypothesis, as the SciPy documentation puts it, is that the distribution behind one sample is the same as the distribution behind the other. The test is sensitive to whether a random value from one group tends to exceed a random value from the other. Divine and colleagues published counterexamples under the plain title that the procedure fails as a test of medians.
Here is one you can check. Two groups of 15 task times in seconds (sample data):
- C: 1, 2, 3, 4, 5, 6, 7, 50, 51, 52, 53, 54, 55, 56, 57
- D: 43, 44, 45, 46, 47, 48, 49, 50, 101, 102, 103, 104, 105, 106, 107
Both medians are exactly 50. Yet D exceeds C in 161.5 of 225 pairs (a tie counts half), 72%, and the asymptotic two-sided p-value is about 0.044. The test is picking up the difference in the two halves, not in the middle.
Reading it as a shift in medians is reasonable only if you can assume both distributions have the same shape and spread and differ just by location. Say so when you rely on it.
Ties, sample size and effect size
- Ties receive the average of the ranks they would occupy: the values 5, 7, 7, 9 get ranks 1, 2.5, 2.5, 4. Ties require a correction in the normal approximation.
- Exact or approximate. SciPy computes an exact distribution when a sample is small and there are no ties, and otherwise uses the normal approximation with a continuity correction by default. With small tied samples, a permutation test is safer.
- Many zeros. In revenue per visitor, most values are zero and tie with each other. The result then mostly reflects the share of buyers; test conversion and spend among buyers separately.
- Effect size. Report U ÷ (n₁ × n₂), here 50 ÷ 64 = 0.78: the chance that a random B customer outspends a random A customer. 0.5 means neither group tends to be higher.
- Three or more groups. Use the Kruskal-Wallis test first instead of many pairwise runs.
Getting the two samples from TapCub
TapCub does not run A/B tests or calculate the Mann-Whitney test. It can supply the per-person values.
- Record the version. Have your testing tool assign A or B and send it as an event property on the purchase event.
- Look at the skew. In All-platform analytics › Behavior › Distribution, choose the order amount as a numeric property. A mean well above the median tells you a few large values dominate.
- Get one row per customer. In All-platform analytics › Behavior › SQL query, return each person's version and order value, keeping one value per person (for example the first order). Download the result as CSV. For large volumes use All-platform analytics › Data › Data export on a plan that includes it.
- Run the test elsewhere. Pass the two columns to
scipy.stats.mannwhitneyuor your statistics package. Report n per group, the medians, the means, U ÷ (n₁ × n₂) and the p-value together.
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), 50–60.
- NIST/SEMATECH e-Handbook of Statistical Methods, 7.3.5 Do two arbitrary processes have the same central tendency?.
- SciPy documentation, scipy.stats.mannwhitneyu.
- Divine, G. W., Norton, H. J., Barón, A. E. and Juarez-Colunga, E. (2018). The Wilcoxon–Mann–Whitney procedure fails as a test of medians. The American Statistician, 72(3), 278–286.
Was this explanation clear?
We use your answers to fix and expand this page.
Couldn’t send. Please try again in a minute.
Thanks for the feedback. We’ll use it to improve this page.You’ve already sent feedback on this page. Thanks.

Product Experience Specialist
Writes about product experience, practical workflows, and growth, turning complex processes into clear steps for everyday decisions.