TapCub is live — analytics, insights and live chat, free on one platform
Glossary

Mann-Whitney U test: ranks and U worked by hand

The Mann-Whitney U test compares two independent samples by rank. Compute U on skewed revenue data, compare it with a t test, and see why it is not simply a test of medians.

Lin Zhou Reviewed by Su He Also called Wilcoxon rank-sum test Last updated Dec 3, 2026 Glossary

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.

Rank12345678
Value1215192224272931
GroupAAAABABA
Rank910111213141516
Value35384146526075410
GroupBABBBBBA

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 AGroup B
Mean$71.75$45.25
Median$24.50$43.50
Rank sum5086

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.

ScenarioWelch t testMann-Whitney U
Data as listedt = 0.54, p = 0.60U = 14, p = 0.065
The $410 order becomes $4,100A's mean jumps to $533, p = 0.37Unchanged: U = 14, p = 0.065
The $410 order removed (7 vs 8)t = −3.17, p = 0.009U = 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.

  1. Record the version. Have your testing tool assign A or B and send it as an event property on the purchase event.
  2. 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.
  3. 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.
  4. Run the test elsewhere. Pass the two columns to scipy.stats.mannwhitneyu or your statistics package. Report n per group, the medians, the means, U ÷ (n₁ × n₂) and the p-value together.

Sources

Was this explanation clear?

We use your answers to fix and expand this page.

Lin Zhou

Product Experience Specialist

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

FAQ

Questions people ask

Short answers to the follow-up questions that come up most.

Still have a question?

Chat with the team behind TapCub — we usually reply within a few hours on business days.

When should I use a Mann-Whitney U test instead of a t test?

Use it for two independent groups when the outcome is ordinal, such as 1–5 ratings, or strongly skewed and you care whether typical values in one group are higher. If the decision depends on totals or averages, such as revenue, compare means instead.

Does the Mann-Whitney U test compare medians?

Not in general. It is sensitive to whether values from one group tend to exceed values from the other. Two groups with identical medians can give a small p-value. It can be read as a median shift only if both distributions share shape and spread.

How do you calculate the U statistic?

Rank all observations together, giving ties their average rank. Add the ranks in group 1, then subtract n1(n1 + 1) ÷ 2. The other group's U is n1 × n2 minus the first. Many tables use the smaller of the two.

What is the difference between Mann-Whitney U and Wilcoxon signed-rank?

Mann-Whitney, also known as the Wilcoxon rank-sum test, is for two independent groups. The Wilcoxon signed-rank test is for paired data, such as the same people measured before and after, and works on the ranked differences.

See this number on your own site

Add one script tag for web and apps, and the first reports fill in within minutes.

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics