The Mann-Whitney U test answers one question: when you have two groups of people, does one group tend to score higher than the other? This guide explains how it works in plain language, how it is calculated, and how to run it in AnalyZ Solutions.
The Mann-Whitney U test answers a simple question: when you have two groups of people, does one group tend to score higher than the other?
Suppose you ask customers who used your online service, and customers who did not, to rate it from 1 (very poor) to 5 (excellent). The first group's ratings look a little higher. Is that a real difference, or did it happen by chance because of who happened to answer? The test gives you a way to tell.
The usual way to compare two groups is to compare their averages, and the standard test for that is the independent t-test. It works well when the values spread evenly around the average in a roughly bell-shaped pattern. It works badly in three common situations.
Instead of the exact values, the test uses their order. It lines everyone from both groups up from lowest to highest and gives each person a position number, called a rank. Then it checks whether the people in one group tend to sit higher in the line. A very large value is only the last in line, so it cannot drag the result around. For background on this whole family of tests, see What are non-parametric tests?
Suppose 85 respondents rate a service from 1 to 5, and they fall into two groups, such as customers who used the online service and customers who did not. You want to know three things. Do the two groups rate the service differently? Which group rates it higher? And how big is the difference? The Mann-Whitney U test answers all three.
Use it to compare two separate groups, meaning each person belongs to only one of them, when at least one of these is true:
Typical examples are satisfaction ratings of men and women, incomes in two cities, and symptom scores in a treatment group and a comparison group in a small pilot.
When the values spread evenly around their average and the groups are large, the independent t-test is slightly better, because it uses the exact values. For three or more groups, use the Kruskal-Wallis test. When the same people are measured twice, use the Wilcoxon signed-rank test. For help choosing between this test and the t-test, see What are non-parametric tests?
Two ideas make the test work: turning values into position numbers, and asking whether one group tends to sit higher than the other.
A rank is a position number. Line all the values up from smallest to largest and number them 1, 2, 3 and so on. If two or more values are equal, they share the average of the positions they occupy. The ratings 2, 3, 3, 4, for example, get the ranks 1, 2.5, 2.5 and 4, because the two 3s occupy positions 2 and 3, so each gets 2.5. Only the order matters. The largest value gets the last rank, however large it is.
The test asks whether people in one group tend to have higher values than people in the other. When the two groups have a similar shape, this comes down to a difference in medians. The median is the middle value, so half the group scores above it and half below. AnalyZ Solutions reports each group's median because it describes the gap simply.
The test itself uses every position in the line, including those far from the middle. If the groups differ a lot in how spread out they are, the test can find a difference even when the medians match, so always look at the descriptive table as well.
The calculation has four steps. The formulas are there for readers who want to check the arithmetic, and the worked example below follows every step with real numbers.
In symbols, where n₁ and n₂ are the number of people in each group:
U₁ is the number of wins for the first group and U₂ the number for the second. They always add up to n₁ × n₂, the total number of pairings. AnalyZ Solutions reports U for the first group listed.
For larger samples, U is converted into a z value, which says how many standard errors U sits from its no-difference value of n₁ × n₂ ÷ 2. The standard error measures how much U would vary from sample to sample by luck alone. The p-value then comes from the normal curve, the familiar bell shape. The p-value is the chance of seeing a gap this big by luck alone if the groups were really the same. The effect size r compares the share of pairings the first group wins with the share the second group wins.
The effect size r runs from 0, when each group wins half the pairings, to 1, when one group wins them all.
Two groups of six people rate a service from 1 to 5. Group A gives 4, 5, 3, 4, 5, 4 and Group B gives 2, 3, 3, 4, 2, 3.
| Rating | Group | Rank |
|---|---|---|
| 2 | B | 1.5 |
| 2 | B | 1.5 |
| 3 | A | 4.5 |
| 3 | B | 4.5 |
| 3 | B | 4.5 |
| 3 | B | 4.5 |
| 4 | A | 8.5 |
| 4 | A | 8.5 |
| 4 | A | 8.5 |
| 4 | B | 8.5 |
| 5 | A | 11.5 |
| 5 | A | 11.5 |
The independent t-test is the standard test for comparing the averages of two separate groups.
| Feature | Independent t-test | Mann-Whitney U test |
|---|---|---|
| What it uses | The exact values | The position of each value in the line |
| What it compares | The two group averages | Whether one group tends to sit higher |
| What it needs from the data | Values that spread evenly around the average in a bell shape | No particular shape |
| Very large or very small values | Can pull an average a long way | Count only as first or last in line |
| Measure of how big the difference is | A gap measured in standard deviations (Cohen's d) | The share of pairings one group wins minus the share the other wins (r) |
| Best for | Measured numbers that are roughly bell-shaped | Ratings, numbers with a few extreme values, and small samples |
Every test gives trustworthy results only when some conditions hold. These are called assumptions. For this test they are modest.
The descriptive table lists, for each group, the number of people, the median and the mean rank. The median is the middle value. The mean rank is the average position number of the group's members in the combined line, so a higher mean rank means the group's people generally sit higher. When two groups share a median, which often happens with short rating scales, the mean ranks still show which group tends to score higher.
The significance level tells you how sure you can be that the difference is real. AnalyZ Solutions reports it as 5%, 1% or 0.1%, and the smaller the percentage, the stronger the evidence. "Significant at the 5% level" means that if the groups were truly the same, a gap this large would appear by luck in fewer than 5 samples out of 100. A result that is not significant means the evidence is not strong enough to say the groups differ. That is not the same as showing they are equal, especially when there are few people.
The effect size tells you how big the difference is, which is a separate question from how sure you can be. For this test it is called r and runs from 0 to 1. A value of 0 means neither group tends to score higher. A value of 1 means every person in one group scores higher than every person in the other. AnalyZ Solutions labels it negligible below 0.1, small from 0.1 to 0.3, medium from 0.3 to 0.5 and large above 0.5. With a big sample even a tiny difference can be significant, so check the size as well as the significance.
Open Inferential Analysis, choose Non-parametric Tests, then Mann-Whitney U.
You can export the tables as CSV, Excel or Word, send them to Sense Making, or add a chart to a Data Canvas slide.
The figures below are invented to show the steps, and they follow the results tables in AnalyZ Solutions, with a few columns left out to save space. Suppose 85 respondents rated a service from 1 to 5, and you compare two groups.
| Group | N | Median | Mean Rank |
|---|---|---|---|
| Group A | 45 | 4.0 | 48.51 |
| Group B | 40 | 3.0 | 36.80 |
| U | p-value | Sig | r (effect) | N |
|---|---|---|---|---|
| 1148.0 | 0.0232 | * | 0.276 | 85 |
People in Group A rated the service higher than people in Group B, with a median rating of 4 against 3. The difference is small but unlikely to be luck, because it is significant at the 5% level. A larger sample would show whether it holds.
Calling it a test of averages. It compares positions in the line, so describe the result with medians.
Using it on paired data. If the same people appear in both groups, for example before and after, use the Wilcoxon signed-rank test.
Using it on more than two groups. Running several two-group tests raises the chance of finding a difference that is not real. Use the Kruskal-Wallis test instead.
Ignoring group sizes. With very small groups the test can miss a real difference, so "no significant difference" may simply mean too few people.
Open Non-parametric Tests in AnalyZ Solutions. Free to sign up, free to analyze.
Get started