
The Mann-Whitney U test, also known as the Wilcoxon Rank Sum test, is a powerful non-parametric statistical method used to compare two independent groups. Unlike the traditional t-test, it makes no assumption that data follows a normal distribution, making it especially useful when working with small samples, skewed data, or ordinal measurements.
Developed independently by Henry Mann and Donald Whitney in 1947, and earlier by Frank Wilcoxon in 1945, the test works by ranking all observations from both groups together, then evaluating whether one group tends to produce higher values than the other. Rather than comparing means, it compares the entire distribution of ranks — a distinction that makes it both robust and flexible.
From clinical trials to social science research, the Mann-Whitney U test has earned its place as a reliable tool in any analyst’s toolkit, offering a straightforward path to meaningful conclusions when standard parametric assumptions simply cannot be met.
What Is the Mann-Whitney U Test?
The Mann-Whitney U test is a non-parametric statistical test designed to determine whether two independent groups come from the same population — or more precisely, whether one group tends to have systematically larger or smaller values than the other.
The test asks a simple question: if you randomly selected one observation from each group, how likely is it that the value from one group would be greater than the value from the other? This probability forms the foundation of the U statistic, which the test calculates and evaluates against expected chance outcomes.
Because it is non-parametric, the Mann-Whitney U test does not require data to be normally distributed, nor does it demand that the two groups have equal variances. It operates on the ranks of observations rather than their raw values, which makes it resistant to the influence of outliers and suitable for ordinal data – data where values can be ordered but the distances between them are not necessarily equal.
The test produces two U statistics — one for each group — and the smaller of the two is typically used for hypothesis testing. A sufficiently small (or large, depending on the direction of the hypothesis) U value suggests a statistically significant difference between the groups.
It is worth noting what the test does not do: it does not compare means. A common misconception is that the Mann-Whitney U test is simply a substitute for comparing averages. In reality, it compares the full rank distributions of both groups, making it a more complete — and often more honest — picture of how two datasets relate to each other.
Mann-Whitney U Test vs Wilcoxon Rank Sum Test
If you have encountered both names in your reading, you may have wondered whether the Mann-Whitney U test and the Wilcoxon Rank Sum test are two different methods or simply two names for the same thing. The short answer is that they are mathematically equivalent — they will always produce the same result given the same data. The longer answer, however, reveals some interesting history and a few practical distinctions worth understanding.
Frank Wilcoxon introduced his rank sum test in 1945 as part of a broader paper presenting non-parametric alternatives to common statistical tests. Two years later, Henry Mann and Donald Whitney independently developed their U statistic, framing the problem in a slightly different way. Despite the separate origins, statisticians eventually recognized that both approaches were testing the same underlying hypothesis and would lead to identical conclusions.
The difference lies in how each method arrives at its test statistic. Wilcoxon’s approach sums the ranks of one group and compares that sum to what would be expected under the null hypothesis. Mann and Whitney’s approach counts the number of times an observation from one group outranks an observation from the other — a concept directly tied to the probability of superiority mentioned in the previous section. These two calculations are algebraically linked, meaning one can always be derived from the other.
In practice, the name you encounter often depends on the software or academic tradition you are working within. R, for example, uses the function wilcox.test() to perform what many textbooks call the Mann-Whitney U test. SPSS labels it as the Mann-Whitney U test in its non-parametric menu. Neither is wrong — they are simply reflecting different conventions that have persisted across decades of statistical practice.
When to Use the Mann-Whitney U Test
Choosing the right statistical test is as important as running it correctly. The Mann-Whitney U test is a strong choice in several specific situations, and understanding those situations will help you avoid both overusing and underusing it.
Your data is not normally distributed. The most common reason analysts turn to the Mann-Whitney U test is that their data violates the normality assumption required by the independent samples t-test. When a histogram reveals heavy skew, or when a Shapiro-Wilk test returns a significant result, the Mann-Whitney U test offers a reliable alternative that does not depend on any assumed distribution shape.
You are working with ordinal data. Likert scale responses, pain ratings, satisfaction scores, and similar measurements can be ranked but cannot be treated as having equal intervals between values. Calculating a mean on such data is statistically questionable. The Mann-Whitney U test, which works on ranks rather than raw values, is naturally suited to this type of measurement.
Your sample size is small. With small samples, it is difficult to verify normality with any confidence, and the central limit theorem cannot be relied upon to rescue a parametric test. The Mann-Whitney U test makes fewer assumptions and performs well even when each group contains as few as five observations.
Outliers are present and meaningful. Unlike the t-test, which is sensitive to extreme values because it works with raw scores, the Mann-Whitney U test converts all observations to ranks. A single extreme outlier therefore has limited influence on the result — it simply becomes the highest or lowest rank rather than pulling the statistic disproportionately.
You have two independent groups. This is a structural requirement, not just a preference. The Mann-Whitney U test is designed for situations where participants or observations belong to one group and one group only — for example, treatment versus control, or male versus female respondents. If your two groups consist of the same subjects measured twice, the appropriate test is instead the Wilcoxon Signed-Rank test, which accounts for the paired nature of the data.
There are also situations where the Mann-Whitney U test is not the right choice. If your data is genuinely normally distributed and your sample is reasonably large, the independent samples t-test is more statistically powerful — meaning it is better at detecting a real difference when one exists. The Mann-Whitney U test trades some of that power for robustness, which is a worthwhile trade in many real-world scenarios but not all.
Assumptions of the Mann-Whitney U Test
One of the appealing qualities of the Mann-Whitney U test is that it comes with far fewer assumptions than its parametric counterparts. However, “fewer assumptions” does not mean “no assumptions.” Violating the assumptions that do exist can lead to misleading results, so it is important to understand and verify each one before proceeding.
The two groups are independent. Observations in one group must have no relationship to observations in the other. This means each participant, subject, or data point belongs to exactly one group, and the value recorded for one observation has no bearing on the value recorded for any other. If your data involves matched pairs, repeated measurements, or any other form of dependency between groups, the Mann-Whitney U test is not appropriate.
The response variable is at least ordinal. The test requires that observations can be meaningfully ranked. This is satisfied by ordinal data, such as survey ratings, as well as by continuous data, such as reaction times or blood pressure readings. Purely nominal data — categories with no natural order, such as eye color or nationality — cannot be ranked and therefore cannot be analyzed with this test.
The observations are randomly sampled. Like most inferential statistical tests, the Mann-Whitney U test assumes that your data represents a random sample drawn from the broader population you wish to make conclusions about. Non-random sampling does not invalidate the mathematics of the test, but it does limit how far you can generalize your findings.
The distributions of both groups share the same shape. This assumption is frequently overlooked but carries real consequences for how results should be interpreted. When both groups have similarly shaped distributions — whether symmetric, skewed left, or skewed right — the Mann-Whitney U test can be interpreted as a test of whether the two groups differ in their central location, essentially comparing medians. If the shapes differ substantially, the test is more accurately described as evaluating whether values from one group tend to exceed values from the other, which is a valid but distinct conclusion.
It is worth pausing on this last point, as it is a source of genuine confusion in applied statistics. Many textbooks and software guides present the Mann-Whitney U test as a straightforward test of medians. Strictly speaking, this is only true when the equal-shape assumption holds. In practice, verifying this assumption involves visually inspecting side-by-side box plots or overlaid histograms for both groups. Perfect symmetry is not required — reasonable similarity in shape is sufficient.
Taken together, these assumptions are considerably less demanding than those of the independent samples t-test, which additionally requires normality and, in its standard form, equal variances. That relative flexibility is precisely what makes the Mann-Whitney U test such a practical tool across a wide range of research contexts.
Mann-Whitney U Test Formula
The U Statistic
The test produces a U statistic for each of the two groups being compared. Given two groups, group 1 with n1 observations and group 2 with n2 observations, the two U statistics are calculated as follows:
Where R1 is the sum of ranks assigned to group 1 and R2 is the sum of ranks assigned to group 2.
As a useful check, the two U statistics will always sum to the total number of possible pairwise comparisons between the groups:
If your two U values do not satisfy this relationship, an error has been made in the calculation.
Ranking the Observations
Before the formula can be applied, all observations from both groups are pooled together and ranked from smallest to largest, with a rank of 1 assigned to the lowest value. When two or more observations share the same value — known as ties — each is assigned the average of the ranks they would have otherwise occupied. For example, if two observations are tied for ranks 4 and 5, both receive a rank of 4.5.
Once ranks are assigned, the observations are separated back into their original groups, and the rank sums R1 and R2 are calculated by adding up all the ranks within each group.
Interpreting the U Statistic
The smaller of the two U values — often simply called U — is the one used for hypothesis testing. Intuitively, U counts the number of times an observation from one group precedes an observation from the other when all values are ordered together. A U value near zero suggests that one group almost entirely outranks the other, indicating a strong difference between the groups. A U value near 2n1n2 suggests considerable overlap, consistent with the null hypothesis that the two groups come from the same distribution.
The Normal Approximation for Larger Samples
For small samples, the U statistic is evaluated against a critical value table. When both groups contain more than around 20 observations, however, the sampling distribution of U approximates a normal distribution, allowing the calculation of a Z score:
This Z score can then be used to determine a p-value in the standard way. When ties are present in the data, a correction factor is applied to the denominator of this formula to account for the reduced variability that ties introduce into the rank distribution. Most statistical software applies this correction automatically.
A Note on Effect Size
The U statistic can also be converted into a useful effect size measure known as the probability of superiority, sometimes denoted f^ or the common language effect size. It is calculated simply as:
This value represents the probability that a randomly selected observation from one group will exceed a randomly selected observation from the other. A value of 0.5 indicates complete overlap between groups, while values approaching 0 or 1 indicate increasing separation — making it one of the more intuitive effect size measures available in statistics.
Step-by-Step Procedure
The Scenario
Suppose a researcher wants to know whether two different teaching methods produce different exam scores. Eight students were taught using Method A and seven using Method B. Their scores are as follows:
Method A: 55, 62, 68, 72, 75, 81, 85, 90
Method B: 48, 57, 63, 70, 74, 78, 83
Step 1: State the Hypotheses
Before touching the data, clearly define what you are testing.
- Null hypothesis (H₀): There is no difference between the two groups. Values from Method A and Method B are equally likely to be higher than the other.
- Alternative hypothesis (H₁): There is a systematic difference between the two groups. Values from one method tend to be higher than values from the other.
This example uses a two-tailed test, meaning we are open to a difference in either direction.
Step 2: Pool and Rank All Observations
Combine all 15 scores into a single list and rank them from lowest to highest, assigning rank 1 to the smallest value.
| Score | Group | Rank |
|---|---|---|
| 48 | B | 1 |
| 55 | A | 2 |
| 57 | B | 3 |
| 62 | A | 4 |
| 63 | B | 5 |
| 68 | A | 6 |
| 70 | B | 7 |
| 72 | A | 8 |
| 74 | B | 9 |
| 75 | A | 10 |
| 78 | B | 11 |
| 81 | A | 12 |
| 83 | B | 13 |
| 85 | A | 14 |
| 90 | A | 15 |
There are no tied values in this dataset, so no averaging of ranks is required.
Step 3: Calculate the Rank Sums
Separate the ranks back into their original groups and sum them.
Group A ranks: 2, 4, 6, 8, 10, 12, 14, 15
Group B ranks: 1, 3, 5, 7, 9, 11, 13
As a quick check, the rank sums should add up to the total number of ranks: 2N(N+1)=215×16=120. Since 71+49=120, the ranking is confirmed correct.
Step 4: Calculate the U Statistics
Apply the formula for each group, where n1=8 and n2=7.
Verification: U1+U2=21+35=56=n1n2=8×7. The calculation checks out.
The test statistic is the smaller of the two values: U=21.
Step 5: Determine the P-Value
With sample sizes of 8 and 7, this example sits at the boundary where either a critical value table or the normal approximation can be applied. Using the normal approximation:
A Z score of −0.81 corresponds to a two-tailed p-value of approximately 0.418.
Step 6: Make a Decision
With a p-value of 0.418, which is well above the conventional significance threshold of 0.05, we fail to reject the null hypothesis. There is insufficient evidence to conclude that the two teaching methods produce systematically different exam scores.
Step 7: Calculate the Effect Size
Even when a result is not statistically significant, reporting an effect size is good practice, as it communicates the practical magnitude of any observed difference.
This value indicates that a randomly selected Method A student has approximately a 37.5% chance of scoring lower than a randomly selected Method B student — a modest difference in favor of Method B that the sample size was likely too small to detect reliably.
Worked Example of Mann-Whitney U Test
The Scenario
A clinical researcher is investigating whether a new dietary supplement reduces fasting blood glucose levels compared to a placebo. Twenty participants were randomly assigned to two groups — ten received the supplement and ten received the placebo — over a 12-week period. Because the sample is small and blood glucose levels in clinical populations often show skewed distributions, the researcher opts for the Mann-Whitney U test rather than an independent samples t-test.
Fasting blood glucose levels (in mg/dL) recorded at the end of the trial are as follows:
Supplement group: 88, 92, 95, 97, 99, 103, 104, 107, 110, 118
Placebo group: 95, 101, 104, 108, 112, 115, 119, 122, 126, 131
Step 1: State the Hypotheses
- Null hypothesis (H₀): There is no difference in fasting blood glucose levels between the supplement and placebo groups.
- Alternative hypothesis (H₁): Fasting blood glucose levels differ systematically between the two groups.
The researcher uses a two-tailed test at a significance level of α=0.05.
Step 2: Pool and Rank All Observations
All 20 observations are combined and ranked from lowest to highest. Note that the value 95 appears in both groups, and 104 appears in both groups — these ties must be handled by averaging ranks.
| Score | Group | Rank |
|---|---|---|
| 88 | Supplement | 1 |
| 92 | Supplement | 2 |
| 95 | Supplement | 3.5 |
| 95 | Placebo | 3.5 |
| 97 | Supplement | 5 |
| 99 | Supplement | 6 |
| 101 | Placebo | 7 |
| 103 | Supplement | 8 |
| 104 | Supplement | 9.5 |
| 104 | Placebo | 9.5 |
| 107 | Supplement | 11 |
| 108 | Placebo | 12 |
| 110 | Supplement | 13 |
| 112 | Placebo | 14 |
| 115 | Placebo | 15 |
| 118 | Supplement | 16 |
| 119 | Placebo | 17 |
| 122 | Placebo | 18 |
| 126 | Placebo | 19 |
| 131 | Placebo | 20 |
The two tied pairs — 95 and 104 — are each assigned the average of their respective ranks. The value 95 occupies positions 3 and 4, so both receive rank 3.5. The value 104 occupies positions 9 and 10, so both receive rank 9.5.
Step 3: Calculate the Rank Sums
Supplement group ranks: 1, 2, 3.5, 5, 6, 8, 9.5, 11, 13, 16
Placebo group ranks: 3.5, 7, 9.5, 12, 14, 15, 17, 18, 19, 20
Verification: R1+R2=75+135=210=220×21. The rank sums are correct.
Step 4: Calculate the U Statistics
With n1=n2=10:
Verification: U1+U2=80+20=100=n1n2. The calculation is confirmed.
The test statistic is the smaller value: U=20.
Step 5: Apply the Tie Correction and Calculate Z
Because ties are present in the data, the standard deviation used in the Z formula requires a correction. The tie correction factor is:T=12∑(t3−t)
Where t is the number of observations sharing each tied rank. There are two tied pairs, each with t=2:
The corrected standard deviation is:
The Z score is then:
Step 6: Determine the P-Value and Make a Decision
A Z score of −2.27 corresponds to a two-tailed p-value of approximately 0.023.
Since 0.023<0.05, the researcher rejects the null hypothesis. There is statistically significant evidence that fasting blood glucose levels differ between the supplement and placebo groups, with the supplement group showing consistently lower values.
Step 7: Calculate and Interpret the Effect Size
A probability of superiority of 0.20 indicates that if one participant from each group were selected at random, there is only a 20% chance that the supplement group participant would have a higher blood glucose level than the placebo group participant. Stated differently, there is an 80% chance that the placebo participant would record a higher reading — reflecting a practically meaningful separation between the two groups.
Reporting the Results
In a research report or academic paper, these findings might be written up as follows:
A Mann-Whitney U test indicated that fasting blood glucose levels were significantly lower in the supplement group (Mdn = 101 mg/dL) than in the placebo group (Mdn = 113.5 mg/dL), U = 20, z = −2.27, p = .023. The probability of superiority effect size was 0.20, indicating a large practical difference between groups.
Mann-Whitney U Test vs Other Tests
Mann-Whitney U Test vs. Independent Samples T-Test
The independent samples t-test is the parametric counterpart to the Mann-Whitney U test, and the comparison between them is the one researchers face most often.
The t-test compares the means of two independent groups and assumes that the data in each group is normally distributed. It is also sensitive to outliers, since extreme values directly influence the mean. When these assumptions are met, the t-test is more statistically powerful than the Mann-Whitney U test — meaning it has a better chance of detecting a true difference between groups when one exists. Simulation studies have shown that the Mann-Whitney U test retains approximately 95% of the t-test’s power under ideal normal conditions, meaning very little efficiency is sacrificed by choosing the non-parametric route even when normality holds.
When normality cannot be assumed, however, the Mann-Whitney U test can be considerably more powerful than the t-test, since the t-test’s results become unreliable when its core assumption is violated. For small samples, skewed distributions, or ordinal data, the Mann-Whitney U test is the stronger choice.
| Feature | Mann-Whitney U | Independent T-Test |
|---|---|---|
| Assumes normality | No | Yes |
| Works with ordinal data | Yes | No |
| Compares | Rank distributions | Means |
| Sensitive to outliers | Low | High |
| Statistical power (normal data) | Slightly lower | Higher |
Mann-Whitney U Test vs. Wilcoxon Signed-Rank Test
These two tests are frequently confused because they share the Wilcoxon name and both operate on ranked data. The critical distinction is the structure of the data they are designed for.
The Mann-Whitney U test is for two independent groups — subjects belong to one group or the other, with no connection between them. The Wilcoxon Signed-Rank test is for two related groups — typically the same subjects measured under two different conditions or at two different time points. In other words, the Wilcoxon Signed-Rank test is the non-parametric equivalent of the paired samples t-test, while the Mann-Whitney U test is the non-parametric equivalent of the independent samples t-test.
Applying the Mann-Whitney U test to paired data ignores the dependency between observations and discards valuable information, reducing statistical power unnecessarily. If your data is paired or matched in any way, the Wilcoxon Signed-Rank test is the appropriate choice.
| Feature | Mann-Whitney U | Wilcoxon Signed-Rank |
|---|---|---|
| Data structure | Independent groups | Paired or repeated measures |
| Parametric equivalent | Independent t-test | Paired t-test |
| Unit of analysis | Individual observations | Differences between pairs |
| Handles ties between groups | Yes | Yes |
Mann-Whitney U Test vs. Kruskal-Wallis Test
The Kruskal-Wallis test is best understood as the extension of the Mann-Whitney U test to three or more groups. Just as the Mann-Whitney U test is the non-parametric alternative to the independent samples t-test, the Kruskal-Wallis test is the non-parametric alternative to the one-way analysis of variance (ANOVA).
When comparing exactly two groups, both tests will produce equivalent results. The moment a third group is introduced, the Mann-Whitney U test is no longer appropriate as a single omnibus test. Running multiple Mann-Whitney U tests across all possible pairs inflates the risk of a false positive — the same multiple comparisons problem that makes running several t-tests a poor substitute for ANOVA. The Kruskal-Wallis test evaluates all groups simultaneously, controlling that risk at the outset. If it returns a significant result, post-hoc pairwise comparisons using adjusted Mann-Whitney U tests can then identify which specific groups differ.
| Feature | Mann-Whitney U | Kruskal-Wallis |
|---|---|---|
| Number of groups | Exactly two | Three or more |
| Parametric equivalent | Independent t-test | One-way ANOVA |
| Post-hoc testing needed | No | Yes, if significant |
| Controls familywise error | N/A | Yes |
Mann-Whitney U Test vs. Chi-Square Test
At first glance, the Mann-Whitney U test and the chi-square test may seem to occupy different corners of statistics entirely. They are both useful for comparing groups without assuming normality, but they apply to fundamentally different types of data.
The chi-square test of independence is designed for categorical data — it asks whether the distribution of categories differs across groups. For example, it could test whether the proportion of patients who improved, stayed the same, or worsened differs between a treatment and a control group. The Mann-Whitney U test, by contrast, requires data that can be meaningfully ranked. It would be inappropriate to apply it to purely nominal categories that have no natural order.
Where the two tests can appear to overlap is with ordinal data that has been collapsed into categories — for instance, treating a 5-point Likert scale as categorical rather than ordered. In such cases, the Mann-Whitney U test is generally preferred because it preserves the ordering information that the chi-square test discards, making it more sensitive to genuine differences between groups.
| Feature | Mann-Whitney U | Chi-Square Test |
|---|---|---|
| Data type | Ordinal or continuous | Categorical (nominal or ordinal) |
| Uses ranking | Yes | No |
| Preserves order information | Yes | Not always |
| Tests | Distributional differences | Frequency distributions |
Taken together, these comparisons reinforce a consistent principle: the Mann-Whitney U test occupies a specific and well-defined role in the statistical toolkit. It is not a universal fallback for whenever parametric assumptions feel inconvenient, but rather a precisely appropriate tool for independent group comparisons involving ranked, non-normal, or outlier-prone data.
Advantages and Limitations of the Mann-Whitney U Test

How to Perform Mann-Whitney U Test in Software
While understanding the manual calculation builds conceptual clarity, in practice the Mann-Whitney U test is almost always conducted using statistical software. Below is a practical guide to running the test in four of the most widely used environments: Excel, SPSS, R, and Python.
In Excel
Excel does not include a built-in Mann-Whitney U test function, but the test can be performed manually using Excel’s ranking and arithmetic capabilities, or through third-party add-ins.
Manual Approach
Step 1: Enter your data in two columns, one for each group. Label them clearly in the header row.
Step 2: Pool and rank the data using Excel’s RANK.AVG function, which automatically handles ties by assigning average ranks – exactly what the Mann-Whitney U test requires.
Assuming Group A data is in column A (A2:A11) and Group B data is in column B (B2:B11), create a third column containing all values combined, then in an adjacent column use:
=RANK.AVG(C2, $C$2:$C$21, 1)
Drag this formula down for all observations. The second argument references the full pooled range, and the third argument (1) specifies ascending rank order.
Step 3: Separate the ranks back into their original groups and sum them to obtain $R_1$ and $R_2$ using SUMIF or by direct reference.
Step 4: Apply the U formulas using standard arithmetic cells:
=n1*n2 + (n1*(n1+1)/2) - R1
=n1*n2 + (n2*(n2+1)/2) - R2
Step 5: Calculate the Z score using the normal approximation formula, then obtain the two-tailed p-value with:
=2*(1-NORM.S.DIST(ABS(Z), TRUE))
Using the Analysis ToolPak or Third-Party Add-Ins
Excel’s built-in Analysis ToolPak does not include the Mann-Whitney U test. However, third-party add-ins such as XLSTAT and Real Statistics Resource Pack add full non-parametric testing capabilities to Excel, including the Mann-Whitney U test with automatic tie correction and effect size output. These are worth considering if you conduct statistical analysis regularly in Excel.
In SPSS
SPSS provides a straightforward menu-driven interface for the Mann-Whitney U test under its non-parametric testing options.
Using the Legacy Dialogs Menu
Step 1: Structure your data. SPSS requires data in long format — one column for the outcome variable and one column for the grouping variable. Each row represents one observation. For example, a column named glucose containing all blood glucose values, and a column named group coded as 1 for supplement and 2 for placebo.
Step 2: Navigate to the test. From the menu bar, select:
Analyze → Nonparametric Tests → Legacy Dialogs → 2 Independent Samples
Step 3: Assign variables. Move your outcome variable into the Test Variable List box and your grouping variable into the Grouping Variable box. Click Define Groups and enter the two group codes (e.g., 1 and 2).
Step 4: Select the test. Ensure Mann-Whitney U is checked under Test Type. Click OK to run.
Reading the Output
SPSS produces two output tables. The first, Ranks, shows the mean rank and rank sum for each group — useful for understanding the direction of any difference. The second, Test Statistics, reports the U statistic, the Wilcoxon W statistic (the rank sum for the first group), the Z score, and the asymptotic two-tailed p-value. For small samples, check the Exact option before running to obtain an exact p-value rather than the normal approximation.
Using the Modern Non-Parametric Tests Menu
SPSS also offers a more automated route via:
Analyze → Nonparametric Tests → Independent Samples
This interface guides you through the analysis using an objective-based workflow and produces more visually polished output, including effect size estimates. However, the legacy dialogs approach above gives more direct control over the specific options applied.
In R
R handles the Mann-Whitney U test through the built-in wilcox.test() function, reflecting the Wilcoxon naming convention discussed earlier in this article.
Basic Syntax
wilcox.test(x, y, alternative = "two.sided", correct = TRUE)
Where x and y are numeric vectors containing the data for each group. The alternative argument specifies the hypothesis direction: "two.sided", "greater", or "less". The correct = TRUE argument applies a continuity correction when computing the normal approximation.
A Complete Example
# Enter the data
supplement <- c(88, 92, 95, 97, 99, 103, 104, 107, 110, 118)
placebo <- c(95, 101, 104, 108, 112, 115, 119, 122, 126, 131)
# Run the Mann-Whitney U test
wilcox.test(supplement, placebo, alternative = "two.sided", correct = TRUE)
Interpreting the R Output
Wilcoxon rank sum test with continuity correction
data: supplement and placebo
W = 20, p-value = 0.02522
alternative hypothesis: true location shift is not equal to 0
Note that R reports the statistic as W rather than U. In this context W is equivalent to $U_1$ — the U statistic for the first group entered. The p-value here matches the result calculated manually in the worked example, with minor rounding differences due to the continuity correction.
Calculating Effect Size in R
The base wilcox.test() function does not automatically return an effect size. The probability of superiority can be calculated manually, or obtained using the rstatix package:
install.packages("rstatix")
library(rstatix)
# Combine data into a data frame
data <- data.frame(
glucose = c(supplement, placebo),
group = rep(c("supplement", "placebo"), each = 10)
)
# Calculate effect size (r)
wilcox_effsize(data, glucose ~ group)
This returns a rank-biserial correlation coefficient $r$, which is a closely related effect size measure. Values around 0.1, 0.3, and 0.5 are conventionally interpreted as small, medium, and large effects respectively.
In Python
Python’s primary statistical library for the Mann-Whitney U test is scipy.stats, which provides a clean and direct implementation.
Basic Syntax
from scipy import stats
statistic, p_value = stats.mannwhitneyu(x, y, alternative='two-sided')
The alternative parameter accepts 'two-sided', 'greater', or 'less'. By default, scipy.stats.mannwhitneyu applies the normal approximation with continuity correction for larger samples and computes exact p-values for smaller ones.
A Complete Example
from scipy import stats
import numpy as np
# Enter the data
supplement = [88, 92, 95, 97, 99, 103, 104, 107, 110, 118]
placebo = [95, 101, 104, 108, 112, 115, 119, 122, 126, 131]
# Run the Mann-Whitney U test
stat, p = stats.mannwhitneyu(supplement, placebo, alternative='two-sided')
print(f"U statistic: {stat}")
print(f"P-value: {p:.4f}")
Output
U statistic: 20.0
P-value: 0.0232
The U statistic of 20 matches the manual calculation exactly. The minor difference in p-value compared to the manual Z-score approach reflects the exact method used by SciPy for this sample size.
Calculating Effect Size in Python
The probability of superiority effect size can be computed directly from the U statistic:
n1 = len(supplement)
n2 = len(placebo)
probability_of_superiority = stat / (n1 * n2)
print(f"Probability of superiority: {probability_of_superiority:.3f}")
Probability of superiority: 0.200
For a more complete analysis with descriptive statistics, visualizations, and formatted output, the pingouin library offers an accessible alternative:
import pingouin as pg
import pandas as pd
# Construct a long-format dataframe
data = pd.DataFrame({
'glucose': supplement + placebo,
'group' : ['supplement'] * 10 + ['placebo'] * 10
})
# Run the test
result = pg.mwu(data[data['group'] == 'supplement']['glucose'],
data[data['group'] == 'placebo']['glucose'],
alternative='two-sided')
print(result)
The pingouin output includes the U statistic, p-value, rank-biserial correlation, and a confidence interval for the effect size — making it one of the most informative single-function implementations available in Python.
FAQs
What type of data is required for the Mann-Whitney U test?
The test requires ordinal, interval, or ratio data that can be ranked. It works best with independent samples where observations are not related.
What does the U value represent?
The U value represents the number of times observations from one group precede observations from another group when ranked. It helps determine whether the groups differ significantly.
Can the Mann-Whitney U test compare more than two groups?
No, the Mann-Whitney U test is limited to comparing two independent groups. For more than two groups, you should use the Kruskal-Wallis test.