Mann-Whitney U test
Compare two separate groups on an ordinal or quantitative variable without assuming normality – the nonparametric alternative to the independent-samples t-test: the scores are ranked together, and the test checks whether the ranks in one group are systematically higher. The output: the table of ranks and medians, the test table as in SPSS (U, W, z, asymptotic and exact p), two effect-size measures (r and rrb), a boxplot and a report sentence in English.
Loading the data
Paste columns directly from the sheet (including the header row) – select them in Excel, copy, and paste here:
Variable selection
When to use?
When there are two groups of different participants and one variable to compare between them – and the t-test is not appropriate. Gravetter and Wallnau (2017, Appendix E.1) list the reasons for moving from scores to ranks: the data were measured on an ordinal scale to begin with; the scores violate the assumptions of t and ANOVA (normality, equal variances); especially high variance, which ranks "erase"; or an undefined score – a participant who did not finish the task simply receives the highest rank. Field (2024, section 7.2) adds the common situation: a small sample, in which the central limit theorem cannot be relied on and the data cannot be corrected – and remarks that robust methods (the Outliers and assumptions page) have already superseded the nonparametric tests, but SPSS offers few of them, and these tests are "a gentle introduction" to hypothesis testing. Pallant (2020, chapter 16) presents it as the nonparametric alternative to the independent-samples t-test: "do men and women differ in their levels of self-esteem?".
On this site it is the natural place for two situations: a single rating item (Likert 1-5), which by the site's convention is an ordinal variable and has no mean (Variables and measurement scales) – a comparison between two groups is done here, or in Frequencies and chi-square; and a scale score or quantitative variable in a small sample or with outliers, when the normality check (Normality check, by group) or the boxplot shows a distribution that is not reasonable for t. When both groups are large (30 or more) and the data are quantitative, the t-test is the default – Gravetter and Wallnau: "if the data are appropriate for an ANOVA or one of the t tests, the standard test is preferable to the alternative for ordinal data" (Appendix E.1) – and Mann-Whitney supports it or replaces it at your discretion; the "Reading the result" box tells you which situation you are in. Three or more groups – the Kruskal-Wallis test, the extension of this test (Gravetter & Wallnau, Appendix E.4).
The logic: ranks instead of scores
The idea, as Field (2024, section 7.4.1) describes it, is "wonderfully elegant": rank all the scores of the two groups together, from lowest (rank 1) to highest, regardless of group. If there is no difference between the groups, the high and low ranks will be spread between them roughly equally, and the rank sums will be similar; if one group is higher, the high ranks will concentrate in it and its rank sum will be larger. Identical values (ties) receive the mean of the ranks they would have received – two scores of 6 that would have been ranks 3 and 4 receive 3.5, three scores of 35 in places 16-18 receive 17 (Field; Gravetter & Wallnau, 2017, Appendix E.1: "3 4 4 7 9 9 9 12 ← 1 2.5 2.5 4 6 6 6 8"). This gives two equivalent statistics: Wilcoxon's Ws – the rank sum in the smaller group (and when the groups are equal – the smaller sum) – and Mann-Whitney's U, which is computed from it: U = n1n2 + n1(n1 + 1)/2 − R1 (equation 7.8). Gravetter and Wallnau (Appendix E.2) give U a direct interpretation: "as if the two groups were two teams in a competition" – each participant in group A receives a point for every participant in group B ranked below them; UA is A's total points, UB B's, UA + UB = nAnB, and the reported statistic is the smaller of the two. In their example (E.1), two groups of six: UA = 30, UB = 6, so U = 6.
Significance. Both sources have two routes. In a small sample – the exact distribution: Gravetter and Wallnau's table B9 gives a critical value (for 6 versus 6, U ≤ 5 is significant at .05; U = 6 is not), and SPSS prints Exact Sig.; Field (box 7.2): in a small sample – "basically anything below 50" – use the exact p. In a large sample – the normal approximation: the expected value and standard error of the statistic are derived from the group sizes alone – W̄s = n1(n1 + n2 + 1)/2, SE = √(n1n2(n1 + n2 + 1)/12) (Field, equations 7.1-7.2; for 10 versus 10: 105 and 13.23) – and z is the distance of the statistic from its expected value in standard-error units (equation 7.5; Gravetter & Wallnau, Appendix E.2, with U: z = (U − nAnB/2)/√(nAnB(nA + nB + 1)/12); in example E.1 – −1.92, not in the critical region of ±1.96, "the same conclusion as from the table"). SPSS corrects the standard error for ties – and so does the page; Gravetter and Wallnau and PSPP do not correct, and the difference in z is usually in the third digit.
How to read the output?
Table 1 – ranks and medians. This is the SPSS Ranks table (N, Mean Rank, Sum of Ranks) plus the median, the quartiles and the range of each group. The first thing to read: the mean rank – "the group with the lower mean rank is the group with more low scores" (Field, 2024, Section 7.4.4); in Field's drug example, on Sunday the mean ranks were 11.95 and 9.05 – similar – and on Wednesday 15.10 versus 5.90. The median is what is reported instead of the mean: "a more appropriate statistic for nonparametric tests" (Field, section 7.4.6; Pallant, 2020, chapter 16 – there it is produced in a separate step with Means). Note that identical medians do not mean there is no difference: the test compares the whole distribution through the ranks, not the medians – so a significant test with equal medians is possible, especially for a rating item.
Table 2 – the test. The Test Statistics table of the old SPSS menu: Mann-Whitney U, Wilcoxon W, Z, Asymp. Sig. (2-tailed) and Exact Sig.. U and W are descriptive – their size depends on the group sizes, and they do not measure an effect; z is always negative, because U is the smaller of the two, so it says nothing about direction – the direction is read from Table 1. The page prints two p values: asymptotic (from the normal approximation, with tie correction) and exact (2·P(U ≤ Uobserved) from the exact distribution of U without ties – what SPSS prints as Exact Sig. [2*(1-tailed Sig.)]; the site's convention: computed when both groups have up to 50 participants). Field's rule (box 7.2): small sample – the exact one; large – the asymptotic one is sufficient. In his example, on Sunday U = 35.5, p = .280 (not significant: "ecstasy is no more depressing than alcohol the day after"), and on Wednesday U = 4, p < .001 – "we write p < .001 because the observed p is very small"; these values are among the page's tests. The last two columns – the effect sizes.
The boxplot shows what the test examines: where the distributions sit relative to each other – the median (thick line), the quartiles (the box), the whiskers and the outliers (Pallant, 2020, Chapter 6). Field (section 7.4.6): "report the medians and their ranges, or draw a boxplot".
Effect size – two yardsticks, "both-and"
SPSS does not print an effect size for the test, and the two sources propose two different ones. Pallant's r (2020, chapter 16): r = |z|/√N, where N is the number of all participants – "an approximate value of r" – with Cohen's conventions (1988, pp. 79-83): .1 small, .3 medium, .5 large; in her example z = −1.23, N = 436, r = .06, "very small". Field's rrb (2024, section 7.4.5): the rank-biserial correlation (rank-biserial; Cureton, as cited in Field), in Wendt's formula: rrb = 1 − 2U/(n1n2) (equation 7.11), with Kerby's intuitive interpretation: in the example, rrb = .29 on Sunday – "about 29% of the ranked data support the idea that depression is higher after ecstasy" – and .92 on Wednesday, "very strong support". The page computes it from the U1 of the first group you selected, so the sign indicates direction: positive – group A is higher; and it shows the percentage of supporting pairs. The two measures are not identical and cannot be converted into each other (r also depends on N through z); report at least one, and say which.
Assumptions and warnings
Two general assumptions (Pallant, 2020, Chapter 16): random sampling, and independent observations – "each participant is counted only once, cannot appear in more than one group, and the data of one participant do not influence those of another"; repeated measurements of the same participants – for the Wilcoxon signed-rank test, not here. Field (2024, note 2 to chapter 7) points out that these tests are not "distribution-free" either: they assume a continuous distribution – so with rating data with many ties, the tie correction in z matters. Power. Field (box 7.1): ranks lose information about the size of the differences, so when the assumptions of the parametric test hold, it is more powerful; but when the sampling distribution is not normal, the Type I error rate of the parametric test is unknown – and then the claim "nonparametric tests have less power" is simply not defined. Very small groups. With fewer than five participants per group the test can hardly come out significant (the exact distribution is coarse); the page warns.
Missing values. A participant is included when they have a valid value on the dependent variable and on the grouping variable – analysis-by-analysis deletion (/MISSING ANALYSIS). Multiple tests. Several variables in one click are several tests, each with a 5% risk of a Type I error. What the page does not compute. Exact p for groups larger than 50, Monte Carlo (box 7.2), the two-sample Kolmogorov-Smirnov test, Moses and Wald-Wolfowitz (Field's tip 7.1), a one-tailed test as output, a confidence interval for the difference in medians (R's Hodges-Lehmann) and bootstrap.
And how do you do it in SPSS?
Two menus, two outputs. The new way (Pallant, 2020, Chapter 16; Field, 2024, Sections 7.3 and 7.4.3): Analyze › Nonparametric Tests › Independent Samples… – on the Objective tab select Customize analysis (Field: "it's not a good idea to let the computer think for you"); on Fields – the categorical variable to Groups and the dependent variable to Test Fields; on Settings – Customize tests and Mann-Whitney U (2 samples); before that, Pallant: in Edit › Options › Output select Pivot tables and charts. The output: Hypothesis Test Summary (the decision only), and a double click opens the Independent-Samples Mann-Whitney U Test Summary with the rank chart – Total N, Mann-Whitney U, Wilcoxon W, Standard Error, Standardized Test Statistic (the z) and Asymptotic Sig., and in versions with the Exact Tests module also Exact Sig.. Note: in the new menu U and W are computed from the second group (the higher code) and are not necessarily the smaller ones – in Pallant's example U = 21594 with n = 184 × 252, and the standardized statistic is negative or positive according to the direction; the p is identical. The medians are not in the output – Pallant produces them with Analyze › Compare Means › Means with Median under Cell Statistics.
The old way, which the page generates as syntax (because it allows choosing two of several groups and prints U and W as in Table 2): Analyze › Nonparametric Tests › Legacy Dialogs › 2 Independent Samples… – the variable to Test Variable List, the grouping variable to Grouping Variable with Define Groups, and Mann-Whitney U checked:
NPAR TESTS /M-W=attitude_score BY group(1 2) /MISSING ANALYSIS. MEANS TABLES=attitude_score BY group /CELLS=COUNT MEDIAN.
Reading the output. Ranks = Table 1 (N, Mean Rank, Sum of Ranks); Test Statistics = Table 2 – Mann-Whitney U, Wilcoxon W, Z, Asymp. Sig. (2-tailed), and for small groups also Exact Sig. [2*(1-tailed Sig.)]; MEANS – the medians. The syntax was checked against PSPP (the free implementation): U, W and the rank sums are identical; PSPP's z is without tie correction.
And how do you do it in R?
In base R, wilcox.test(x, y) – under the name "Wilcoxon rank sum test", the same test. Three differences from SPSS worth knowing: R's statistic W is the number of pairs in which the first group is higher (not the smaller U and not Wilcoxon's W); the default adds a continuity correction to the asymptotic p – correct = FALSE gives the p of SPSS and of the page; and the exact p (exact = TRUE) is computed only without ties. The script was run as is on the sample data file and gave the table values (in the comments). The site rule for R: a UTF-8 file, every comment line starts with an English word, and a UTF-8 environment for Hebrew names.
# Mann-Whitney test – Professor Stat. This file is saved as UTF-8; every comment line starts with an English word
library(readxl) # reading Excel
# Loading: the standard template – row = participant, column = variable; the sheet "data"
d <- read_excel("C:/Rdata/DATA_mw_example_eng.xlsx", sheet = "data")
y <- d[["attitude_score"]]; g <- d[["group"]]
y1 <- y[g == 1 & !is.na(y)]; y2 <- y[g == 2 & !is.na(y)]
# Median and quartiles (type = 6 = SPSS) for each group – Table 1
median(y1); quantile(y1, c(.25, .75), type = 6) # experimental: Mdn 3.375, [2.91, 4.00]
median(y2); quantile(y2, c(.25, .75), type = 6) # control: Mdn 3.125, [2.50, 3.55]
# Ranks: sum and mean rank for each group (mean rank for ties)
r <- rank(c(y1, y2)); R1 <- sum(r[seq_along(y1)]); R2 <- sum(r[-seq_along(y1)])
c(R1, R2, R1 / length(y1), R2 / length(y2)) # 4147, 3113; mean ranks 69.12, 51.88
# The test: asymptotic p without continuity correction = SPSS; R's W = n1n2 − U1
wt <- wilcox.test(y1, y2, exact = FALSE, correct = FALSE)
wt # W = 2317, p = .0066
n1 <- length(y1); n2 <- length(y2)
U1 <- n1 * n2 + n1 * (n1 + 1) / 2 - R1; U2 <- n1 * n2 + n2 * (n2 + 1) / 2 - R2
c(U = min(U1, U2), W = min(R1, R2)) # U = 1283, W = 3113 – as in SPSS
# The z (negative as in SPSS), r = |z|/√N (Pallant) and r_rb = 1 − 2U1/(n1n2) (Field)
z <- -abs(qnorm(wt$p.value / 2))
c(z = z, r = abs(z) / sqrt(n1 + n2), r_rb = 1 - 2 * U1 / (n1 * n2)) # −2.72, .248, .287
# Small sample without ties – exact p (example E.1 of Gravetter and Wallnau)
wilcox.test(c(27, 2, 9, 48, 6, 15), c(71, 63, 18, 68, 94, 8), exact = TRUE) # W = 6, p = .065
Reporting the results
Field (2024, section 7.4.6): report the statistic (U, or Ws if preferred), z, the exact p (not p ≤ .05), an effect size – and the medians of the two groups: "depression levels in ecstasy users (Mdn = 17.50) did not differ significantly from alcohol users (Mdn = 16.00) the day after, U = 35.50, z = −1.11, p = .280, rrb = .29. However, by Wednesday, ecstasy users (Mdn = 33.50) were significantly more depressed (Mdn = 7.50), U = 4.00, z = −3.48, p < .001, rrb = .92". Pallant (2020, chapter 16) uses the same template with n and r: "U = 21594, z = −1.23, p = .22, r = .06". Gravetter and Wallnau (Appendix E.2) add that according to APA the rank sums should also be included. The report sentences in the output are built like this – median and n for each group, U, z, p (the exact one when computed), rrb and r. The formatting rules (American Psychological Association [APA], 2020, Section 6.36): p and r without a zero before the decimal point; U, W, z with one.
Common mistakes
Reading direction from the sign of z. In the old output z is always negative; the direction – from the mean ranks or the medians (Field, 2024, Section 7.4.4).
Reporting means. The test is on ranks; report medians (Field, Section 7.4.6; Pallant, 2020, Chapter 16).
Reading "not significant" in a small sample as "no difference". With 6 versus 6 participants, U = 6 is not significant although the groups clearly differ (Gravetter & Wallnau, example E.1) – power.
Comparing the U of R, of the new menu and of the old one. Three definitions (the number of pairs; from the second group; the smaller) – the same p.
Thinking that equal medians = a nonsignificant test. The test compares distributions; for a rating item two medians of "3" can hide a significant difference in ranks.
Escaping to Mann-Whitney every time a normality test is significant. In large groups the central limit theorem covers t (Field, 2024, section 6.2.7; the Normality check page) – and Mann-Whitney loses the size of the differences (box 7.1).
Reporting only r or only rrb without saying which. Two different yardsticks; .29 in Field is rrb, .06 in Pallant is r.
References
American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.). https://doi.org/10.1037/0000165-000
Cohen, J. (1988). Statistical power analysis for the behavioral sciences (2nd ed.). Lawrence Erlbaum Associates.
Field, A. (2024). Discovering statistics using IBM SPSS statistics (6th ed.). SAGE.
Gravetter, F. J., & Wallnau, L. B. (2017). Statistics for the behavioral sciences (10th ed.). Cengage Learning.
Pallant, J. (2020). SPSS survival manual: A step by step guide to data analysis using IBM SPSS (7th ed.). Open University Press.
Mann and Whitney (1947), Wilcoxon (1945), Cureton (1956), Wendt (1972) and Kerby (2014) – as cited in Field (2024). By the site rule, the reference list includes only sources read in the original; Gravetter and Wallnau (2017, Appendix E, pp. 687-692), Cohen (1988), Pallant (2020) and APA (2020) – by page, chapter and section of the print edition; Field (2024) in a reflowable digital copy – by section, equation and box (his table 7.1 is the page's test file). The syntax – verified against PSPP; R was run in 4.3.3.