If two groups of ratings have differently shaped distributions, can we still say which group has the larger values? The Brunner–Munzel test offers one answer: draw one number independently from each group, and compare the chance that the second group's number is larger with the chance that the first group's is larger. It allows the two groups to have different distributions, and the sample sizes can differ as well. [1]

First, Be Clear About the Direction of "Larger"

Let X and Y denote single numbers drawn independently from two populations. The relative effect used in this article is p = P(X < Y) + 0.5P(X = Y): Y greater than X scores 1, a tie scores one half, and X greater than Y scores 0. p is the population average of this scoring; p = 0.5 means the probabilities of winning in the two directions are the same, with ties split equally between the two sides.

The null hypothesis of the two-sided Brunner–Munzel test is p = 0.5, and the alternative is p ≠ 0.5. When p is greater than 0.5, under the scoring rule above Y tends to be larger; when it is less than 0.5, X tends to be larger. The test targets this relative effect directly, rather than taking "the two distributions are exactly identical" or "the medians are equal" as the target of testing. [1]

Compare Every Pair in the Official Example Once

The SciPy documentation gives an example with 14 X values and 11 Y values. [1] Comparing each X with each Y gives 14 × 11 = 154 cross-group comparisons: 103 pairs satisfy X < Y, 37 are ties, and 14 satisfy X > Y. The sample estimate of the relative effect is therefore

p̂ = (103 + 0.5 × 37) / 154 ≈ 0.789.

In other words, if one observation is drawn at random from each of these two samples, and scoring is 1 for Y larger and one half for a tie, the average score is about 0.789. This number includes the half-points for ties, so it is not the proportion in which Y is strictly larger than X; that proportion is 103/154, about 0.669.

Left: the empirical cumulative distribution curves of the two groups. Right: the matrix of cross-group comparison scores.

Actually recomputed with the two-group example numbers from the official SciPy documentation. The left panel shows the empirical cumulative distributions; the right panel shows the 14 × 11 cross-group comparisons, with X less than Y scoring 1 and ties scoring 0.5; the mean is the relative effect estimate. The figure recomputes the documentation's example data and is not a new survey or clinical measurement. [1]

Why Do We Still Need a Test?

0.789 describes the comparison result in the sample; with another batch of independent observations, the estimate could change. The Brunner–Munzel test divides the difference between p̂ and the null value of 0.5 by a standard error estimated separately from the observations of the two groups, obtaining a studentized statistic, and then computes the p-value from an approximate distribution. This brings each group's own variability into the estimate of uncertainty. [1]

154 comparisons do not amount to 154 independent draws: the same X is compared repeatedly with 11 Y values, and the same Y is compared repeatedly with 14 X values. In computing the uncertainty, the dependence created by these shared observations must be retained, and the 154 scores cannot be treated as 154 independent Bernoulli trials.

Recomputing in Python

The code below first scores each pair, then uses SciPy to compute the two-sided test. The arrays match the official example; distribution="t" specifies that the p-value be computed with a t-distribution approximation. [1]

import numpy as np
from scipy import stats

x = np.array([1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 1, 1])
y = np.array([3, 3, 4, 3, 1, 2, 3, 1, 1, 5, 4])

scores = (x[:, None] < y[None, :]).astype(float)
scores += 0.5 * (x[:, None] == y[None, :])
p_hat = scores.mean()
result = stats.brunnermunzel(
    x, y, alternative="two-sided", distribution="t"
)
print(f"relative effect = {p_hat:.6f}")
print(f"W = {result.statistic:.6f}")
print(f"p-value = {result.pvalue:.6f}")

The output is approximately:

relative effect = 0.788961
W = 3.137467
p-value = 0.005786

Reading the Result Through Three Questions

First, look at the direction: what is defined here is the score for "X less than Y," so p̂ of about 0.789 points to Y being larger; in this example the W given by SciPy is positive, which also corresponds to this direction. Second, look at the ties: the 37 tied pairs each score one half, so the effect cannot be read as the probability that Y strictly wins. Third, report the effect and the test result together: p̂ about 0.789, W about 3.137, and two-sided p about 0.0058. This p-value is the probability, under the null hypothesis p = 0.5 and the approximation used, of obtaining a statistic at least this extreme; it is not the probability that the null hypothesis is true.

What Data Suit This Kind of Comparison?

The two groups should consist of independent individuals, and the observations must lie on an ordered scale on which they can be compared across groups. The two groups may have different degrees of dispersion or distribution shapes; the test relies on studentization and an approximate distribution to handle sampling variability, which does not mean that any sample will yield a reliable approximation. Paired before-and-after measurements have a different dependence structure and cannot be treated directly as these two independent samples. [1]

When writing a report, put next to the result how the two groups are defined, what a larger value means, how ties are scored, and the direction of the effect. Writing only "the difference is significant" would lose the most intuitive information this test provides: when a pair of observations is drawn at random and scored in the chosen direction, which group more often comes out ahead.

References

  1. [1] SciPy community. scipy.stats.brunnermunzel. SciPy Manual. https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.brunnermunzel.html