Mann-Whitney U Test Calculator

Group 1 Data

Group 2 Data

Your results will be displayed here.

How to Use This Calculator

Follow these simple steps to perform a Mann-Whitney U test on your data:

1Enter Your Data

Enter numerical data for each group in the text areas provided. You can separate values using commas, spaces, or new lines. For example:

22, 23, 25, 28 or 22 23 25 28

2Calculate Results

Click the "Calculate" button to run the analysis. The calculator will automatically display:

  • Mann-Whitney U statistic
  • Z-score (normal approximation)
  • P-value (two-tailed test)
  • Sample sizes and sum of ranks for each group
  • Statistical interpretation of the results

3Review the Visualizations

The calculator generates four plots to help you understand your data:

  • Histograms: Show the distribution of values in each group
  • Density plots: Display the shape and spread of your data with individual data points

4Interpret Your Results

Look at the p-value in the test results:

  • If p < 0.05: There is a statistically significant difference between the two groups
  • If p ≥ 0.05: No significant difference was detected between the groups
💡 Tip: The Mann-Whitney U test is ideal when your data doesn't meet the assumptions for a t-test (such as normality). It's based on ranks rather than the actual values, making it robust to outliers and skewed distributions.
⚠️ Important: Make sure your two groups are independent (not paired or matched). For paired data, use the Wilcoxon Signed-Rank test instead.

Understanding the Mann-Whitney U Test

The Mann-Whitney U test, also known as the Wilcoxon Rank-Sum Test, is a non-parametric statistical test used to compare differences between two independent groups when the dependent variable is either ordinal or continuous, but not normally distributed. It is the non-parametric equivalent of the independent samples t-test. The test determines whether two independent samples were drawn from a population with the same distribution.

When to Use the Mann-Whitney U Test

You should consider using the Mann-Whitney U test when the assumptions for a parametric test like the t-test are not met, such as when the data is not normally distributed. It is particularly useful for ordinal data or for continuous data that is skewed. This test is frequently applied in various fields such as psychology, healthcare, and business to compare things like attitudes, the effects of two different treatments, or customer preferences between two groups.

Assumptions of the Mann-Whitney U Test

Interpreting the Results

The Mann-Whitney U test works by ranking all the data from both groups together and then comparing the sum of the ranks for each group. The output of the test includes:

In the strictest sense, a significant result from a Mann-Whitney U test indicates that one population tends to have higher values than the other.


Frequently Asked Questions (FAQ)

Q1: How is the U statistic calculated manually?

The calculation involves a few key steps. First, combine all data from both groups into a single set and rank them from lowest to highest. Then, calculate the sum of the ranks for each group, denoted as \(R_1\) and \(R_2\).

Next, calculate a U value for each group using the following formulas, where \(n_1\) and \(n_2\) are the sample sizes of group 1 and group 2, respectively:

$$ U_1 = n_1 n_2 + \frac{n_1(n_1 + 1)}{2} - R_1 $$ $$ U_2 = n_1 n_2 + \frac{n_2(n_2 + 1)}{2} - R_2 $$

The Mann-Whitney U test statistic is the smaller of these two values:

$$ U = \min(U_1, U_2) $$

Q2: How does the test handle tied ranks?

When two or more observations have the same value, they are assigned the average of the ranks they would have occupied. For example, if three values are tied for the 5th, 6th, and 7th positions, each is assigned the rank of \((5 + 6 + 7) / 3 = 6\). While this does not affect the calculation of U, it does reduce the variance of the U distribution. For large samples that use the Z-approximation, a correction factor is applied to the standard deviation formula to account for ties.

Q3: When is the Z-approximation used and how is it calculated?

For larger sample sizes (a common rule of thumb is when both \(n_1\) and \(n_2\) are greater than 10), the sampling distribution of the U statistic can be approximated by a normal distribution. This allows for the calculation of a Z-score, which is then used to find the p-value. The Z-score is calculated as:

$$ Z = \frac{U - \mu_U}{\sigma_U} $$

Where:

Q4: What is the difference between the Mann-Whitney U test and the Wilcoxon Rank-Sum test?

In modern statistics, these two names are used interchangeably to refer to the same statistical test. Historically, they were developed independently but are mathematically equivalent. Frank Wilcoxon first proposed the test using the sum of the ranks (\(R\)), while Henry Mann and Donald Whitney later developed it using the \(U\) statistic, which is a simple linear function of \(R\). The conclusions drawn from both will always be identical.

How to Run the Mann-Whitney U Test in Statistical Software

The calculator above uses the normal (z) approximation with a tie correction and no continuity correction. Below is how to run the same test in the most common statistics programs.

💡 Data layout: In R and Python you can pass the two groups as two separate lists. In SPSS, JMP, JASP and jamovi, use long format: one column with the measurements (e.g., Score) and one column identifying the group (e.g., Group with values A and B).

R / RStudio

In RStudio, paste the code into a script and run it with Ctrl+Enter (Cmd+Enter on Mac). The base function wilcox.test() performs the Mann-Whitney U test, so no extra packages are needed.

group1 <- c(22, 23, 25, 28, 30, 32, 34, 35, 37, 38)
group2 <- c(18, 19, 20, 21, 24, 26, 27, 29, 31, 33)

res <- wilcox.test(group1, group2,
                   paired  = FALSE,
                   exact   = FALSE,   # normal approximation
                   correct = FALSE)   # no continuity correction
res

# R reports W = the U value of group 1
W  <- unname(res$statistic)
n1 <- length(group1); n2 <- length(group2)
U  <- min(W, n1 * n2 - W)   # the smaller U, as in this calculator

If your data is in a file with a measurement column and a group column:

df <- read.csv("data.csv")   # columns: score, group
wilcox.test(score ~ group, data = df,
            exact = FALSE, correct = FALSE)

If you leave out exact and correct, R uses its defaults: an exact p-value for small samples without ties, and otherwise the normal approximation with a continuity correction.

Python (SciPy)

Install the libraries once with pip install scipy pandas. The method argument requires SciPy 1.7 or newer.

from scipy.stats import mannwhitneyu

group1 = [22, 23, 25, 28, 30, 32, 34, 35, 37, 38]
group2 = [18, 19, 20, 21, 24, 26, 27, 29, 31, 33]

res = mannwhitneyu(group1, group2,
                   alternative="two-sided",
                   use_continuity=False,
                   method="asymptotic")   # normal approximation

n1, n2 = len(group1), len(group2)
U = min(res.statistic, n1 * n2 - res.statistic)

print("U of group 1:", res.statistic)
print("Smaller U:", U)
print("p-value:", res.pvalue)

To read the groups from a CSV file with pandas:

import pandas as pd

df = pd.read_csv("data.csv")   # columns: score, group
group1 = df.loc[df["group"] == "A", "score"]
group2 = df.loc[df["group"] == "B", "score"]

SciPy reports the U value of the first sample, so take the smaller of U and n1·n2 − U if you want the value used in most textbook tables. With the default method="auto" and use_continuity=True, SciPy uses an exact p-value for small samples without ties, and otherwise the normal approximation with a continuity correction.

SPSS

  1. Enter your data in long format: one numeric column (e.g., Score) and one grouping column (e.g., Group, coded 1 and 2).
  2. Go to Analyze → Nonparametric Tests → Legacy Dialogs → 2 Independent Samples…
  3. Move Score to Test Variable List and Group to Grouping Variable, then click Define Groups… and enter 1 and 2.
  4. Under Test Type, make sure Mann-Whitney U is checked, then click OK.
  5. Read the Ranks table (mean ranks and sums of ranks) and the Test Statistics table (Mann-Whitney U, Wilcoxon W, Z, and Asymp. Sig. (2-tailed)).

Or use syntax:

NPAR TESTS
  /M-W= Score BY Group(1 2).

Newer SPSS versions also offer Analyze → Nonparametric Tests → Independent Samples…. There, choose Compare Distributions across Groups on the Objective tab, assign the fields, and select Mann-Whitney U (2 samples) under Settings → Customize tests. If the Exact… button is available in your installation, it adds an exact p-value for small samples.

JMP

  1. Enter your data in long format: a continuous column for the measurements and a nominal column for the group.
  2. Go to Analyze → Fit Y by X. Put the measurement column in Y, Response and the group column in X, Factor, then click OK.
  3. Click the red triangle next to Oneway Analysis and choose Nonparametric → Wilcoxon Test.
  4. In the Wilcoxon / Kruskal-Wallis Tests (Rank Sums) output, read the rank sums and the normal-approximation Z and Prob>|Z| (the two-sided p-value). JMP does not report the U statistic directly; it can be derived from the rank sum of a group.

JASP

  1. Open your data file (CSV, Excel, or SPSS .sav) in long format and set the measurement column as Scale and the group column as Nominal.
  2. Go to T-Tests → Classical → Independent Samples T-Test.
  3. Move the measurement column to Variables and the group column to Grouping Variable.
  4. Under Tests, tick Mann-Whitney (untick Student if you only want the nonparametric test).
  5. Optionally tick Descriptives and the effect-size option in the panel to see group summaries and the rank-biserial correlation.

The results table shows the statistic W (the U value of the first group, as in R) and the p-value.

jamovi

  1. Open your data file (CSV, Excel, SPSS, or .omv) in long format. Set the measurement column as Continuous and the group column as Nominal.
  2. Go to Analyses → T-Tests → Independent Samples T-Test.
  3. Move the measurement column to Dependent Variables and the group column to Grouping Variable.
  4. Under Tests, tick Mann-Whitney U (untick Student's if you only want the nonparametric test).
  5. Optionally open Additional Statistics → Descriptives for group summaries, and Assumption Checks to test normality and equality of variances when deciding between a t-test and Mann-Whitney.
⚠️ Why results can differ slightly: Programs differ in three defaults: exact vs. normal-approximation p-values, continuity correction, and which U they report (U of group 1, U of group 2, or the smaller). For the default example data in this calculator (U = 23, z ≈ −2.04, p ≈ 0.041), R and SciPy report 77, which is the U of group 1 (n₁·n₂ − 23). Both numbers describe the same result. For very small samples or data with many ties, an exact test is generally preferable to the normal approximation.

Related Statistical Calculators