When shapes differ: Brunner–Munzel and Fligner–Policello
Mann–Whitney assumes the two distributions behave alike under the null. These two tests drop that assumption, as Welch does for means.
What runs in CodeSplash
- STAT022Brunner–Munzel test Runs in CodeSplash
- STAT023Fligner–Policello test Runs in CodeSplash
- Brunner–Munzel test (stochastic equality) Verified in Python and R
You will be able to
- State the hypothesis of stochastic equality
- Explain why Mann–Whitney can mislead when spreads differ
- Read a Brunner–Munzel result and its interval for the relative effect
The Welch of rank tests
ReadMann–Whitney's null says the two groups have the same distribution. If the groups differ in spread but neither tends to beat the other, its p-value can reject too often.
Brunner–MunzelBrunner–Munzel testA rank test of stochastic equality that, unlike Mann–Whitney, stays valid when the groups differ in spread or shape. tests a narrower null, stochastic equalityStochastic equalityA value from one group is as likely to beat a value from the other as to lose to it; the relative effect equals ½.:
It estimates that relative effect and its standard error separately for each group, then uses a t approximation with fractional degrees of freedom.
Predict the estimate
PredictPredict first
On ToothGrowth, Mann–Whitney's probability of superiority for OJ over VC was about two in three. What will Brunner–Munzel's relative effect be?
Reveal
The same quantity: = 0.639. The tests share an estimate. They differ in how they judge its uncertainty.
Read the result
Readt(54.68) = 1.90, p = .063, p̂ = .64
- t (Brunner–Munzel)
- 1.897
- df
- 54.677
- p
- .063
Effect size
- Probability of superiority p̂ 0.6394 95% CI [0.4921, 0.7868]
Plots
View data
| supp | len |
|---|---|
| VC | 4.200 |
| VC | 11.500 |
| VC | 7.300 |
| VC | 5.800 |
| VC | 6.400 |
| VC | 10 |
| VC | 11.200 |
| VC | 11.200 |
| VC | 5.200 |
| VC | 7 |
| VC | 16.500 |
| VC | 16.500 |
| VC | 15.200 |
| VC | 17.300 |
| VC | 22.500 |
| VC | 17.300 |
| VC | 13.600 |
| VC | 14.500 |
| VC | 18.800 |
| VC | 15.500 |
| VC | 23.600 |
| VC | 18.500 |
| VC | 33.900 |
| VC | 25.500 |
| VC | 26.400 |
| VC | 32.500 |
| VC | 26.700 |
| VC | 21.500 |
| VC | 23.300 |
| VC | 29.500 |
| OJ | 15.200 |
| OJ | 21.500 |
| OJ | 17.600 |
| OJ | 9.700 |
| OJ | 14.500 |
| OJ | 10 |
| OJ | 8.200 |
| OJ | 9.400 |
| OJ | 16.500 |
| OJ | 9.700 |
| OJ | 19.700 |
| OJ | 23.300 |
| OJ | 23.600 |
| OJ | 26.400 |
| OJ | 20 |
| OJ | 25.200 |
| OJ | 25.800 |
| OJ | 21.200 |
| OJ | 14.500 |
| OJ | 27.300 |
| OJ | 25.500 |
| OJ | 26.400 |
| OJ | 22.400 |
| OJ | 24.500 |
| OJ | 24.800 |
| OJ | 30.900 |
| OJ | 26.400 |
| OJ | 27.300 |
| OJ | 29.400 |
| OJ | 23 |
Assumptions
- Group sizes — 30 and 30 values.
- Independent observations — Each subject appears once, in one group.
Descriptives
| supp | n | Median | Mean rank (pooled) |
|---|---|---|---|
| OJ | 30 | 22.700 | 34.683 |
| VC | 30 | 16.500 | 26.317 |
- p̂ = P(OJ > VC) + ½P(tie); 0.5 means stochastic equality. Alternative: two-sided.
The exact R script · R R version 4.5.1 (2025-06-13)
# Brunner–Munzel test (stochastic equality)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method nonparam.brunner_munzel 1.1.1 · spec 02022c25e142a982
# Dataset: toothgrowth (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/toothgrowth.parquet", col_select = c("len", "supp")))
n_input <- nrow(df)
df[["supp"]] <- factor(df[["supp"]], levels = c("OJ", "VC")) # stored level order
df <- df[stats::complete.cases(df[c("len", "supp")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("len", "supp")) # infinite values stop the run (registry/errors.yaml)
# %% Two samples (independent groups or paired measurements, from the bound roles)
y <- "len"
g <- "supp"
levels_g <- levels(df[[g]])
if (length(levels_g) != 2) cs_error("CS_E_GROUP_COUNT", column = g, expected = 2, k = length(levels_g))
x1 <- df[[y]][df[[g]] == levels_g[1]]
x2 <- df[[y]][df[[g]] == levels_g[2]]
design <- "independent"
label_1 <- levels_g[1]
label_2 <- levels_g[2]
# %% Test
conf <- 0.95
alternative <- "two-sided"
test <- "brunner_munzel"
if (is.null(test)) test <- "brunner_munzel"
n1 <- length(x1)
n2 <- length(x2)
for (i in 1:2) { # the variance estimates need two values per group
lab <- c(label_1, label_2)[i]
if (c(n1, n2)[i] < 2) cs_error("CS_E_SMALL_GROUP", min = 2, group = if (design == "independent") paste0(g, " = ", lab) else lab, n = c(n1, n2)[i])
}
# Brunner-Munzel t test (brunnermunzel::brunnermunzel.test; statistic positive = first group higher)
r <- cs_brunner_munzel(x1, x2, conf, alternative)
label <- "Brunner–Munzel test"
if (test == "fligner_policello") {
# Fligner-Policello robust rank-order test (normal reference; ties 1/2); p-hat keeps the Brunner-Munzel interval
fp <- cs_fligner_policello(x1, x2, alternative)
r$statistic <- fp$statistic
r["df"] <- list(NULL)
r$p <- fp$p
label <- "Fligner–Policello test"
}
# %% Assumptions
assumptions <- list(
list(key = "sample_size", label = "Group sizes", status = if (min(n1, n2) < 10) "warn" else "pass",
detail = paste0(sprintf("%d and %d values", n1, n2), if (min(n1, n2) < 10) "; with fewer than 10 per group consider a permutation test." else ".")),
list(key = "independence", label = "Independent observations", status = "info", detail = "Each subject appears once, in one group.")
)
# %% Result
values <- list(statistic = r$statistic, df = r$df, p = r$p, phat = r$phat, ci_low = r$ci_low, ci_high = r$ci_high,
n_1 = n1, n_2 = n2, median_1 = median(x1), median_2 = median(x2), level_1 = label_1, level_2 = label_2,
test = test, test_label = label)
rk <- rank(c(x1, x2))
values$missing_share <- if (n_input > 0) n_dropped / n_input else 0 # consult-a-statistician input
chart_rows <- unique(round(seq(1, nrow(df), length.out = min(nrow(df), 5000))))
cs_publish(list(
method = "nonparam.brunner_munzel",
methodVersion = "1.1.1",
title = label,
engine = cs_engine_info("stats", "nanoparquet"),
n = n1 + n2,
summary = sprintf("%s: P(%s > %s) + ½P(tie) = %.3f, %.0f%% CI [%.3f, %.3f]; %s.", label, label_1, label_2, r$phat, conf * 100, r$ci_low, r$ci_high, cs_fmt_p(r$p)),
apa = if (test == "fligner_policello") {
sprintf("z = %s, %s, p̂ = %s", cs_fmt_num(r$statistic), cs_fmt_p(r$p), cs_fmt_num(r$phat, leading_zero = FALSE))
} else {
sprintf("t(%s) = %s, %s, p̂ = %s", cs_fmt_num(r$df), cs_fmt_num(r$statistic), cs_fmt_p(r$p), cs_fmt_num(r$phat, leading_zero = FALSE))
},
statistics = c(if (test == "fligner_policello") {
list(list(key = "statistic", label = "z (Fligner–Policello)", value = r$statistic))
} else {
list(list(key = "statistic", label = "t (Brunner–Munzel)", value = r$statistic), list(key = "df", label = "df", value = r$df))
}, list(list(key = "p", label = "p", value = r$p, format = "p"))),
tables = list(list(key = "descriptives", title = "Descriptives",
columns = list(list(key = "group", label = g, type = "string"), list(key = "n", label = "n", type = "integer"),
list(key = "median", label = "Median", type = "number"), list(key = "mean_rank", label = "Mean rank (pooled)", type = "number")),
rows = data.frame(group = c(label_1, label_2), n = c(n1, n2), median = c(median(x1), median(x2)),
mean_rank = c(mean(rk[seq_len(n1)]), mean(rk[n1 + seq_len(n2)])), stringsAsFactors = FALSE))),
effectSizes = list(list(key = "phat", label = "Probability of superiority p̂", value = r$phat, ciLow = r$ci_low, ciHigh = r$ci_high,
ciLevel = conf, method = "P(X > Y) + ½P(X = Y), t interval (Brunner & Munzel 2000)")),
assumptions = assumptions,
warnings = warnings,
notes = c(list(sprintf("p̂ = P(%s > %s) + ½P(tie); 0.5 means stochastic equality. Alternative: %s.", label_1, label_2, alternative)),
if (test == "fligner_policello") list(paste("Fligner–Policello: placement counts with ties ½, standard normal reference; assumes symmetric distributions",
"(it then compares medians). The p̂ interval is Brunner–Munzel's.")) else list()),
values = values,
charts = list(cs_chart("distribution", "raincloud", sprintf("%s by %s", y, g),
list(y = cs_col(y, df[[y]][chart_rows]), group = cs_col(g, as.character(df[[g]][chart_rows]), levels = levels_g))))
))
t(54.68) = 1.90, p = .063, p̂ = .64
- t (Brunner–Munzel)
- 1.897
- df
- 54.677
- p
- .063
Effect size
- Probability of superiority p̂ 0.6394 95% CI [0.4921, 0.7868]
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Group sizes — 30 and 30 values.
- Independent observations — Each subject appears once, in one group.
Descriptives
| supp | n | Median | Mean rank (pooled) |
|---|---|---|---|
| OJ | 30 | 22.700 | 34.683 |
| VC | 30 | 16.500 | 26.317 |
- p̂ = P(OJ > VC) + ½P(tie); 0.5 means stochastic equality. Alternative: two-sided.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Brunner–Munzel test (stochastic equality)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method nonparam.brunner_munzel 1.1.1 · spec 02022c25e142a982
# Dataset: toothgrowth (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
from scipy import stats
import codesplash as cs
from codesplash.stats import rank_tests, robust
# %% Data
df = pd.read_parquet("tests/parity/fixtures/toothgrowth.parquet", columns=["len", "supp"])
n_input = len(df)
df["supp"] = pd.Categorical(df["supp"], categories=["OJ", "VC"]) # stored level order
df = df.dropna(subset=["len", "supp"]) # listwise deletion over the analysis columns
df["supp"] = df["supp"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["len", "supp"]) # infinite values stop the run (registry/errors.yaml)
# %% Two samples (independent groups or paired measurements, from the bound roles)
y = "len"
g = "supp"
levels = [str(x) for x in df[g].cat.categories]
if len(levels) != 2:
cs.cs_error("CS_E_GROUP_COUNT", column=g, expected=2, k=len(levels))
x1 = df.loc[df[g] == df[g].cat.categories[0], y].to_numpy(dtype=float)
x2 = df.loc[df[g] == df[g].cat.categories[1], y].to_numpy(dtype=float)
design, label_1, label_2 = "independent", levels[0], levels[1]
# %% Test
conf = 0.95
alternative = "two-sided"
test = "brunner_munzel" or "brunner_munzel"
n1, n2 = len(x1), len(x2)
for lab, n_g in ((label_1, n1), (label_2, n2)): # the variance estimates need two values per group
if n_g < 2:
cs.cs_error("CS_E_SMALL_GROUP", min=2, group=f"{g} = {lab}" if design == "independent" else lab, n=n_g)
# Brunner–Munzel t test (scipy.stats.brunnermunzel; statistic sign: positive = first group higher)
r = robust.brunner_munzel(x1, x2, conf, alternative)
label = "Brunner–Munzel test"
if test == "fligner_policello":
# Fligner–Policello robust rank-order test (normal reference; ties ½); p̂ keeps the Brunner–Munzel interval
fp = rank_tests.fligner_policello(x1, x2, alternative)
r = dict(r, statistic=fp["statistic"], df=None, p=fp["p"])
label = "Fligner–Policello test"
# %% Assumptions
assumptions = [
{"key": "sample_size", "label": "Group sizes", "status": "warn" if min(n1, n2) < 10 else "pass",
"detail": f"{n1} and {n2} values" + ("; with fewer than 10 per group consider a permutation test." if min(n1, n2) < 10 else ".")},
{"key": "independence", "label": "Independent observations", "status": "info", "detail": "Each subject appears once, in one group."},
]
# %% Result
values = {"statistic": r["statistic"], "df": r["df"], "p": r["p"], "phat": r["phat"], "ci_low": r["ci_low"], "ci_high": r["ci_high"],
"n_1": n1, "n_2": n2, "median_1": float(np.median(x1)), "median_2": float(np.median(x2)), "level_1": label_1, "level_2": label_2,
"test": test, "test_label": label}
rk = stats.rankdata(np.concatenate([x1, x2]))
values["missing_share"] = n_dropped / n_input if n_input else 0.0 # consult-a-statistician input
chart_rows = np.unique(np.round(np.linspace(0, len(df) - 1, min(len(df), 5000))).astype(int))
cs.publish({
"method": "nonparam.brunner_munzel",
"methodVersion": "1.1.1",
"title": label,
"engine": cs.engine_info("pandas", "numpy", "scipy"),
"n": n1 + n2,
"summary": f"{label}: P({label_1} > {label_2}) + ½P(tie) = {r['phat']:.3f}, {conf:.0%} CI [{r['ci_low']:.3f}, {r['ci_high']:.3f}]; {cs.fmt_p(r['p'])}.",
"apa": (f"z = {cs.fmt_num(r['statistic'])}, {cs.fmt_p(r['p'])}, p̂ = {cs.fmt_num(r['phat'], leading_zero=False)}" if test == "fligner_policello"
else f"t({cs.fmt_num(r['df'])}) = {cs.fmt_num(r['statistic'])}, {cs.fmt_p(r['p'])}, p̂ = {cs.fmt_num(r['phat'], leading_zero=False)}"),
"statistics": ([{"key": "statistic", "label": "z (Fligner–Policello)", "value": r["statistic"]}] if test == "fligner_policello" else
[{"key": "statistic", "label": "t (Brunner–Munzel)", "value": r["statistic"]}, {"key": "df", "label": "df", "value": r["df"]}])
+ [{"key": "p", "label": "p", "value": r["p"], "format": "p"}],
"tables": [{"key": "descriptives", "title": "Descriptives", "columns": [
{"key": "group", "label": g, "type": "string"}, {"key": "n", "label": "n", "type": "integer"},
{"key": "median", "label": "Median", "type": "number"}, {"key": "mean_rank", "label": "Mean rank (pooled)", "type": "number"}],
"rows": [{"group": label_1, "n": n1, "median": values["median_1"], "mean_rank": float(rk[:n1].mean())},
{"group": label_2, "n": n2, "median": values["median_2"], "mean_rank": float(rk[n1:].mean())}]}],
"effectSizes": [{"key": "phat", "label": "Probability of superiority p̂", "value": r["phat"], "ciLow": r["ci_low"], "ciHigh": r["ci_high"],
"ciLevel": conf, "method": "P(X > Y) + ½P(X = Y), t interval (Brunner & Munzel 2000)"}],
"assumptions": assumptions,
"warnings": warnings,
"notes": [f"p̂ = P({label_1} > {label_2}) + ½P(tie); 0.5 means stochastic equality. Alternative: {alternative}."]
+ (["Fligner–Policello: placement counts with ties ½, standard normal reference; assumes symmetric distributions "
"(it then compares medians). The p̂ interval is Brunner–Munzel's."] if test == "fligner_policello" else []),
"values": values,
"charts": [cs.chart("distribution", "raincloud", f"{y} by {g}", {
"y": cs.col(y, df[y].to_numpy(dtype=float)[chart_rows]),
"group": cs.col(g, df[g].astype(str).to_numpy()[chart_rows], levels=levels)})],
})
= 0.64 (95% CI 0.49 to 0.79), t(54.7) = 1.90, p = .063.
The interval is on a scale people can read. It dips slightly below one half, so the data are compatible with no tendency and with OJ winning nearly four times out of five.
Fligner–Policello
ReadThe Fligner–Policello robust rank-order test asks the same question using each value's "placement": how many values in the other group it beats. It assumes both distributions are symmetric.
On ToothGrowth it gives z = 1.88, p = .060, close to Brunner–Munzel. With heavy skew, prefer Brunner–Munzel.
Very small samples
ReflectTwo sections of six students give = 0.056 and p < .001. The groups barely overlap, yet the t approximation is doing a lot of work with only 8.4 degrees of freedom.
With fewer than about ten per group, would you trust an approximate p this small? A permutation version of the test, or the exact Mann–Whitney count, is a useful second opinion.
Check your understanding
CheckpointCheck yourself
Two groups have very different spreads, and you want a rank-based comparison. Which is the better default?
Show the answer
Answer: a
Rank tests still have assumptions. Mann–Whitney's null is equal distributions, so a spread difference alone can move its p-value. Pre-testing doesn't fix that.
Check yourself
A Brunner–Munzel interval for runs from 0.55 to 0.72. What does that say?
Show the answer
Answer: b
is the chance a random value from one group exceeds one from the other, counting ties as half. The interval excludes one half, so no-tendency is not compatible with these data.
Check yourself
You'd like to use Fligner–Policello, but one group's distribution is strongly skewed. What should you do?
Show the answer
Answer: a
Fligner–Policello relaxes equal spreads but keeps symmetry. Brunner–Munzel needs neither, and it reports the same relative effect.
Do it in CodeSplash
In the appThe method's Test option offers Brunner–Munzel (t approximation) and Fligner–Policello (robust rank-order). Both report the same relative effect with an interval.
import pandas as pd
from scipy import stats
df = pd.read_csv("toothgrowth.csv")
oj = df.loc[df["supp"] == "OJ", "len"]
vc = df.loc[df["supp"] == "VC", "len"]
print(stats.brunnermunzel(oj, vc, distribution="t"))# install.packages("brunnermunzel")
df <- read.csv("toothgrowth.csv")
oj <- df$len[df$supp == "OJ"]
vc <- df$len[df$supp == "VC"]
brunnermunzel::brunnermunzel.test(oj, vc)SciPy and the R package may flip the sign of the statistic, depending on which group they call first. Check the direction against .
Recap
Recap- Brunner–Munzel tests whether one group tends to exceed the other, allowing different shapes.
- Fligner–Policello asks the same question and assumes symmetry.
- Report with its interval: it reads directly as a chance of winning.
Concepts in this lesson