Celeus

T-test vs Mann-Whitney U test: which to use?

Welch's t-test, Student's t-test or Mann-Whitney U for two groups? What each one tests, what skewed data changes, and why Welch is a sensible default.

On this page

For two independent groups on a continuous outcome, use Welch’s t-test by default and report the difference in means with a confidence interval. Use the Mann-Whitney U test when a rank-based comparison is what you actually care about, as with ordinal scores, or when a small sample is badly skewed and a comparison of means is not meaningful anyway.

The usual advice is “use a t-test if the data are normal and Mann-Whitney if they are not”. That framing hides the more important difference: the tests ask different questions. Welch’s t-test compares means. The Mann-Whitney U test (also called the Wilcoxon rank-sum test) asks whether a value drawn from one group tends to be larger than a value drawn from the other. Pick the test whose question you want answered, then check whether its assumptions are reasonable for your data.

Three tests, three sets of assumptions

All three assume the two groups are independent: different people, plots or animals in each group, one value per unit. If the same units were measured twice, see paired t-test vs Wilcoxon signed-rank instead. With three or more groups, see one-way ANOVA, Welch’s ANOVA or Kruskal-Wallis.

Student’s t-test

Null hypothesis: the two population means are equal. It assumes the outcome is normally distributed within each group and that the two groups have the same variance. It pools the two sample variances into one estimate. When the variances differ and the group sizes differ too, that pooled estimate is wrong in a predictable direction: if the smaller group has the larger variance, Student’s test rejects too often; if the larger group has the larger variance, it becomes too conservative.

Welch’s t-test

Same null hypothesis, equal means. It drops the equal-variance assumption: each group’s variance is estimated separately and the degrees of freedom are adjusted (Welch, 1947). When the variances really are equal, Welch loses very little power compared with Student’s test. When they are not, it keeps the false-positive rate close to the nominal level where Student’s test does not. That trade is why Delacre, Lakens and Leys (2017) argue it should be the default, and why R’s t-test function already runs Welch unless you explicitly assume equal variances.

Testing for equal variances first (with Levene’s test, say) and then choosing between Student and Welch is not a good fix. The pre-test has low power in small samples and adds its own error to the procedure. Using Welch from the start avoids the problem.

Normality matters less than it seems. The t-test depends on the sampling distribution of the mean, which approaches normality as samples grow even when the raw data are skewed. With small samples and strong skew, the confidence interval can be off, and this is where a rank test earns its place.

Mann-Whitney U test

The statistic U counts, over every pair of one observation from each group, how often the first group’s value is larger (ties count one half). Divide U by the number of pairs and you get an estimate of

P(X > Y) + 0.5 x P(X = Y),

sometimes called the probability of superiority. The test’s exact null hypothesis is that both groups come from the same distribution, and it has power against alternatives where that probability differs from 0.5, which is what Mann and Whitney (1947) set out to test: whether one variable is “stochastically larger” than the other.

It does not assume normality. It does not, however, test whether the medians are equal, and it does not escape the unequal-variance problem. Two points are worth being precise about:

  • It is a test of medians only under a shift model, where the two distributions have the same shape and spread and differ only in location. Then the shift equals the difference in medians (and in means). Outside that model, two groups with identical medians can produce a significant Mann-Whitney result, and two groups with different medians can fail to (Divine et al., 2018).
  • Different spreads can create significance on their own. If the groups differ in shape or variance, the test’s null distribution no longer fits, so it can reject more often than its nominal rate even when neither group tends to be larger. Fay and Proschan (2010) set out the different hypotheses the same Mann-Whitney decision rule can be read as testing, and which assumptions each reading needs.

Worked example: reaction times after sleep restriction

A psychology lab compares mean reaction times (ms, one value per participant) between 40 control participants and 25 who were sleep restricted. Reaction times are right-skewed, and the restricted group is more variable. The data are synthetic, generated in R 4.6.1.

The control group had mean 503.4 ms (SD 80.0, median 501). The restricted group had mean 575.2 ms (SD 142.3, median 598).

Test Estimate (control minus restricted) 95% CI p
Welch’s t -71.8 ms difference in means -135.1 to -8.5 0.0275
Student’s t -71.8 ms difference in means -126.9 to -16.7 0.0114
Mann-Whitney -68 ms Hodges-Lehmann shift -135 to -7 0.0333

Welch’s test gives t = -2.31 on 33.6 degrees of freedom. Student’s test, which pools the variances, gives t = -2.61 on 63 degrees of freedom and a narrower interval. The narrower interval is not extra precision. The smaller group is the more variable one here, which is exactly the case where pooling understates the standard error. Welch’s interval is the honest one.

The Mann-Whitney test used an exact null distribution, which R 4.6.1 does by default when both groups have fewer than 50 values (a few rounded reaction times are tied, and this version of R handles ties exactly; older versions switch to a normal approximation and give a slightly different p-value). Its estimate is the Hodges-Lehmann shift, the median of all 1,000 pairwise differences between groups. R reported the interval at an achieved level of 95.11%, since exact rank-based intervals can only hit certain confidence levels. The more direct summary of what the test examines is the probability of superiority: across all restricted-control pairs, the restricted participant was slower in 65.8% of them (ties counted as half).

All three agree on direction. They should not be read as three attempts at the same number. The t-tests estimate a difference in means; the Mann-Whitney estimate is a shift that equals the difference in medians only if the two distributions have the same shape, and here the spreads clearly differ.

Same medians, significant Mann-Whitney

To see the shape sensitivity directly, we drew 1,000 values from a symmetric normal distribution and 1,000 from a right-skewed exponential distribution shifted so that its population median is also zero.

The sample medians were 0.005 (symmetric) and 0.002 (skewed). The Mann-Whitney test still gave W = 559,105 and p < 0.001, because values from the skewed distribution exceed values from the normal one in 55.9% of pairs. The result is correct for the question the test asks, P(skewed > symmetric) differs from 0.5. It is wrong only if you report it as “the medians differ”.

Which one to report

  • You want a difference in means, with a confidence interval: Welch’s t-test. With moderate to large samples this holds up well even for skewed data.
  • The outcome is ordinal, or you want to know which group tends to score higher: Mann-Whitney, reported with the probability of superiority or a rank-biserial correlation, not described as a comparison of medians.
  • You need a difference in medians specifically: neither test gives you that without extra assumptions. Estimate the median difference directly, for example with a bootstrap confidence interval or quantile regression.
  • Small sample, heavy skew: consider whether the mean is the right summary at all. A log transformation often makes a ratio of geometric means the natural quantity.

Avoid running both and reporting whichever has the smaller p-value. Decide from the question before looking at results. If an outcome has values below a detection limit, neither plain test is right; see data below the detection limit.

Common mistakes with two independent groups

  • Describing Mann-Whitney as a test of medians. Outside a shift model it is not one, as the equal-medians run above shows.
  • Choosing the test from a normality pre-test. In small groups that test has little power, and the choice should follow the question.
  • Pooling variances by habit. Student’s test keeps its error rate only with equal variances, or approximately so when group sizes are equal; Welch’s test costs little when they hold.
  • Treating repeated measures as independent. Several rows per participant make the observations dependent, and neither test applies to the rows as they stand.
  • Reporting a p-value alone. Give a mean difference with its interval for the t-test, or a probability of superiority for Mann-Whitney.

How Celeus handles this

Celeus uses Welch’s t-test by default when you compare two groups on a continuous outcome, reports the mean difference with its 95% confidence interval, and checks normality and equal variances for you. If the normality check fails, it offers Mann-Whitney as a re-run and describes that result as which group tends to have larger values, not as a comparison of means.

Student’s version stays available when you want it: see the Student’s t-test reference. For the wider family of t-tests, see t-tests explained.

Worked example

Data: synthetic, made for this example. Seed: 3.

Run on Celeus engine 0.49.0, seed 3, synthetic data.

Output

# Results

- Test: Welch's t-test
- n: 65
- statistic: -2.305
- p-value: 0.0275
- effect size: Cohen's d = -0.6643 (95% CI -1.175 to -0.1489)
- 95% CI (mean in group control minus mean in group restricted): [-135.1, -8.467]
- seed: 3

## Assumption checks
- normality by group (Shapiro-Wilk): passed=FALSE
- variance homogeneity (Levene): passed=FALSE (evidence of unequal variances)
- sample size: passed=TRUE (adequate n)

## Power (sensitivity, not observed power)
- minimum detectable effect at n=65: Cohen's d = 0.7254
- to detect a conventional medium effect: 64 per group to detect d=0.50
- alpha = 0.05, target power = 0.8
R script
# Celeus - reproduce.R  (run from this package folder; bundled data in data/)
# Test: Welch's t-test  |  engine 0.49.0  |  catalog c40-dc08
# Research context: not provided for this run.
# Reproduces the recorded result deterministically.

set.seed(3)
.data_path <- "data/t-test-vs-mann-whitney.csv"
if (!file.exists(.data_path)) stop("Run reproduce.R from the package folder (the bundled data is in data/).")
data <- readr::read_csv(.data_path, show_col_types = FALSE)  # needs the readr package
clean_cells <- function (df) 
{
    ctrl_collapse <- "[\r\n\t\v\f]+"
    zero_width_chars <- intToUtf8(c(8203L, 65279L), multiple = TRUE)
    uni_space_chars <- intToUtf8(c(160L, 8239L, 8199L), multiple = TRUE)
    clean_text <- function(x) {
        out <- x
        for (ch in zero_width_chars) out <- gsub(ch, "", out, 
            fixed = TRUE)
        out <- gsub(ctrl_collapse, " ", out)
        for (ch in uni_space_chars) out <- gsub(ch, " ", out, 
            fixed = TRUE)
        trimws(gsub(" +", " ", out))
    }
    changed_cols <- character(0)
    cells_cleaned <- 0L
    retyped <- character(0)
    for (j in seq_along(df)) {
        col <- df[[j]]
        if (!is.character(col)) 
            next
        cleaned <- clean_text(col)
        n_changed <- sum(!is.na(col) & !is.na(cleaned) & col != 
            cleaned, na.rm = TRUE)
        if (n_changed > 0L) {
            changed_cols <- c(changed_cols, names(df)[j])
            cells_cleaned <- cells_cleaned + n_changed
        }
        df[[j]] <- cleaned
        non_blank <- cleaned[!is.na(cleaned) & nzchar(cleaned)]
        if (length(non_blank) && all(grepl("^[+-]?(0|[1-9][0-9]*)([.][0-9]+)?$", 
            non_blank))) {
            parsed <- suppressWarnings(as.numeric(cleaned))
            was_blank <- is.na(cleaned) | !nzchar(cleaned)
            lost <- (is.na(parsed) | is.infinite(parsed)) & !was_blank
            if (!any(lost)) {
                finite <- parsed[!is.na(parsed)]
                all_whole <- all(finite == floor(finite))
                in_range <- all(abs(finite) <= .Machine$integer.max)
                df[[j]] <- if (all_whole && in_range) 
                  as.integer(parsed)
                else parsed
                retyped <- c(retyped, names(df)[j])
            }
        }
    }
    names(df) <- clean_text(names(df))
    if (length(changed_cols)) {
        attr(df, "ingest_clean_columns") <- changed_cols
        attr(df, "ingest_clean_cells_cleaned") <- cells_cleaned
    }
    if (length(retyped)) 
        attr(df, "ingest_clean_retyped") <- retyped
    df
}
data <- clean_cells(data)
# Complete-case analysis: drop rows missing any analysis value.
.acols <- c("rt_ms", "group")
data <- data[stats::complete.cases(data[, .acols, drop = FALSE]), , drop = FALSE]
result <- t.test(`rt_ms` ~ `group`, data = data, var.equal = FALSE)
print(result)

# Sensitivity: minimum detectable effect at n=65 (power=0.8, alpha=0.05). NOT observed power.
power <- pwr::pwr.t2n.test(n1 = 40, n2 = 25, sig.level = 0.05, power = 0.8)
print(power)

Common questions

When should I use the Mann-Whitney U test instead of a t-test?

Use the Mann-Whitney U test when your question is about ranks, for example with an ordinal outcome or when you want to know which group tends to score higher. It also has a place when a small sample is badly skewed and a comparison of means is not meaningful. When you want a difference in means with a confidence interval, Welch's t-test is the better default.

Should I use a t-test or a Mann-Whitney U test for skewed data?

Skew alone is usually not a reason to switch. The t-test depends on the sampling distribution of the mean, which approaches normality as samples grow even when the raw data are skewed, so with moderate to large samples Welch's t-test holds up well. With a small sample and strong skew, consider whether the mean is the right summary at all, and use Mann-Whitney only if a rank-based question is the one you want answered.

What does the Mann-Whitney U test actually compare?

It asks whether a value drawn from one group tends to be larger than a value drawn from the other. U divided by the number of pairs estimates P(X > Y) + 0.5 x P(X = Y), the probability of superiority. Its exact null hypothesis is that both groups come from the same distribution, and it is a test of medians only under a shift model, where the two distributions have the same shape and spread.

Is Welch's t-test better than the Mann-Whitney U test?

They answer different questions, so pick by the question first. For a difference in means, Welch's t-test is the sensible default: it loses very little power when variances are equal and keeps the false-positive rate close to the nominal level when they are not. Mann-Whitney does not escape the unequal-variance problem, because groups with different spreads can produce a significant result on their own.

Which effect size goes with a Mann-Whitney U test?

Report the probability of superiority or a rank-biserial correlation, since both describe what the test examines: how often a value from one group exceeds a value from the other. The Hodges-Lehmann shift is a common accompanying estimate, but it equals the difference in medians only when the two distributions have the same shape. Do not describe the result as a comparison of medians or of means.

Is the Mann-Whitney U test the same as the Wilcoxon rank-sum test?

Yes, they are two names for the same test of two independent groups. It is a different test from the Wilcoxon signed-rank test, which is for paired measurements such as before and after values on the same units.

Sources

  1. Welch BL (1947). The generalization of 'Student's' problem when several different population variances are involved. Biometrika 34(1-2):28-35. doi:10.1093/biomet/34.1-2.28
  2. Mann HB, Whitney DR (1947). On a test of whether one of two random variables is stochastically larger than the other. Annals of Mathematical Statistics 18(1):50-60. doi:10.1214/aoms/1177730491
  3. Delacre M, Lakens D, Leys C (2017). Why psychologists should by default use Welch's t-test instead of Student's t-test. International Review of Social Psychology 30(1):92-101. doi:10.5334/irsp.82
  4. Fay MP, Proschan MA (2010). Wilcoxon-Mann-Whitney or t-test? On assumptions for hypothesis tests and multiple interpretations of decision rules. Statistics Surveys 4:1-39. doi:10.1214/09-SS051
  5. Divine GW, Norton HJ, Baron AE, Juarez-Colunga E (2018). The Wilcoxon-Mann-Whitney procedure fails as a test of medians. The American Statistician 72(3):278-286. doi:10.1080/00031305.2017.1305291

Methods discussed

Try it on your own data

Upload a dataset and Celeus suggests a method, checks its assumptions, runs it in R, and gives you the script to rerun it.

Try it in Celeus