Mann-Whitney U Test: Formula and Calculation
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
To calculate the Mann–Whitney U statistic, pool the observations from two independent groups, rank them together, and use the rank sums to find U for each group; the smaller value is usually reported. Enter the two groups’ observations below to get U, the corresponding rank sum, and a normal-approximation z score for a quick reference.
Formula
For two groups with sizes n₁ and n₂ and rank sums R₁ and R₂, calculate:
- U₁ = R₁ − n₁(n₁ + 1)/2
- U₂ = R₂ − n₂(n₂ + 1)/2
- U = min(U₁, U₂), the smaller of the two statistics.
Here, n₁ and n₂ are counts of observations, while R₁ and R₂ are sums of ranks assigned after pooling both groups. U is a dimensionless count-like statistic, not a measurement in the original data’s units. The displayed z is an approximate standardized statistic: z = [U₁ − n₁n₂/2] / √[n₁n₂(n₁+n₂+1)/12]. This simple variance formula assumes no tied values and uses a normal approximation.
The calculator ranks the combined data from smallest to largest. In the example, the three x values have ranks 1, 3, and 5, so R₁ = 9; the y values have ranks 2, 4, and 6, so R₂ = 12. Both groups contain three observations.
Worked Example
- Pool the default values: 1, 2, 3, 4, 5, 6. Assign ranks 1 through 6 in that order.
- For Group 1, the values 1, 3, 5 have ranks 1, 3, 5. Thus R₁ = 1 + 3 + 5 = 9.
- For Group 2, the values 2, 4, 6 have ranks 2, 4, 6. Thus R₂ = 2 + 4 + 6 = 12.
- Compute U₁ = 9 − 3(4)/2 = 3 and U₂ = 12 − 3(4)/2 = 6. The reported smaller U is min(3, 6) = 3.
- For the displayed z, use U₁ = 3: z = (3 − 3×3/2) / √[3×3×(3+3+1)/12] = −1.5 / √5.25 ≈ −0.65.
The outputs are U = 3.00 and z = −0.65. The sign of z depends on which group is treated as Group 1; swapping the groups reverses that sign. The smaller U does not have that ambiguity.
What the Test Measures
The Mann–Whitney U test, also called the Wilcoxon rank-sum test, assesses whether observations in one independent group tend to be higher or lower than those in another. It uses the ordering of observations rather than their raw distances, so a gap of 100 is not given 100 times the influence of a gap of 1. The groups do not need to have equal sample sizes.
A useful interpretation is pairwise: U₁ can be viewed as the number of cross-group pairs in which a Group 1 observation exceeds a Group 2 observation, with half-credit for ties under the usual convention. Depending on the convention for ordering, software may describe the complementary count instead. The two U statistics add to n₁n₂, which explains why programs may display different U values while agreeing on the test.
When to Use It and How to Interpret Results
Use the test for two independent samples when the outcome is at least ordinal and a rank-based comparison is appropriate. Examples include comparing ratings from two separate groups or measurements from two unrelated samples. It is not a test for paired observations such as before-and-after measurements on the same people; those generally call for a paired rank procedure instead.
The test is often described as a nonparametric alternative to the independent-samples t test, but that shorthand can mislead. It does not automatically test whether the two medians differ. A median-focused interpretation is most defensible when the group distributions have similar shapes and spreads; otherwise, a result may reflect differences in spread or overall distribution as well as location.
U alone does not establish statistical significance. To assess evidence against the null hypothesis, obtain a p-value using an exact method or an appropriate approximation, then interpret it alongside the study design, sample size, and effect size. The z output above is only a basic reference: ties alter its variance, and small samples may need an exact calculation. A p-value is not the probability that the null hypothesis is true, nor does it measure how large or practically important a difference is.
Ties, Assumptions, and Common Mistakes
- Average tied ranks. If equal observations occur, assign each the average of the ranks they would occupy. For example, values that would receive ranks 2 and 3 both receive 2.5. The calculator expression does not implement this: its list functions cannot pool and rank two lists, so it is suitable only as a specification of the intended calculation, not an executable ranking operation in the stated calculator format.
- Keep observations independent. Each subject or unit should contribute to only one group, and observations should be independent within and across groups according to the study design.
- Do not rank groups separately. Ranks must be assigned once across the combined sample; separate ranking loses the between-group ordering the test needs.
- Check direction and reporting. State which group is first, whether the reported statistic is the smaller U, and whether the test is one- or two-sided. Software conventions differ.
- Do not confuse U with a p-value. U is a statistic. Its distribution, sample sizes, ties, and alternative hypothesis are needed to obtain the p-value.
In a fully implemented calculation, ties also require a variance correction for an asymptotic z test. Exact p-value methods may handle small samples differently, and their availability or definition can vary with ties. For a formal analysis, use statistical software that supports tied ranks and clearly reports its method; verify that its reported U convention matches your report.
Frequently Asked Questions
What is the formula for the Mann–Whitney U test?
For each group, subtract n(n+1)/2 from its pooled rank sum: U₁ = R₁ − n₁(n₁+1)/2 and U₂ = R₂ − n₂(n₂+1)/2. Many reports give the smaller of U₁ and U₂.
Do I use the larger or smaller U value?
Many textbook procedures report the smaller U, while software may show either group’s U or both. Follow the convention required for the chosen p-value method and state it clearly.
Can I use Mann–Whitney for paired data?
No. Its standard form assumes two independent groups. For paired or repeated measurements, use a method designed for matched observations, such as the Wilcoxon signed-rank test when its assumptions fit.
Does Mann–Whitney compare medians?
Not in general. It compares the distributions through their ranks. It can be interpreted as a location or median comparison when the distributions have broadly similar shapes and spreads.
How do I handle tied observations?
Give tied observations their average pooled rank, then use a tie-corrected variance for an approximate test or a suitable exact method. Do not break ties arbitrarily or use the no-ties z formula as if ties had no effect.
Related
Formula used
list x | Group 1 values | 1, 3, 5 list y | Group 2 values | 2, 4, 6 out u | Mann-Whitney U | - | min(sum_rank_x - count(x)*(count(x)+1)/2, sum_rank_y - count(y)*(count(y)+1)/2) | 2 out z | Normal approximation z | - | (sum_rank_x - count(x)*(count(x)+1)/2 - count(x)*count(y)/2) / sqrt(count(x)*count(y)*(count(x)+count(y)+1)/12) | 2
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.