Skip to content

BCompare groups · Guide test 025

Mood median test

Compares groups using counts above and below their pooled median.

Runs in CodeSplashPython example validatedR example validated Corrected in edition 2

Do it in CodeSplash

In the app, set it up in Analyze with this method:

  • Kruskal–Wallis test — Do three or more independent groups differ in location (without assuming normality)?

In Kruskal–Wallis test, choose Rank scores = Above / below the pooled median (Mood's median test).

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Mood median test

3
12
0.80

Group i has true mean (i − 1) × spread.

1.00
0.050

Your data

Drag a point or use ↑/↓ to change it
Group 1 · n = 12 · mean 0.39Group 2 · n = 12 · mean 0.86Group 3 · n = 12 · mean 1.67

If H₀ were true

χ² = 4.67
  1. The reference: how χ² varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .097).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

χ2=∑cells(O−E)2E on the 2×k table above vs. not above the pooled median\chi^2 = \sum_{\text{cells}}\dfrac{(O-E)^2}{E}\ \text{on the }2\times k\text{ table above vs. not above the pooled median}

With your numbers

χ2=4.67,x~=1.06\chi^2 = 4.67,\quad \tilde x = 1.06
x~\tilde x
pooled median

The verdict

χ²(2) = 4.67, p = .097

p > α = .050: compatible with H₀

Only counts which side of the median each value falls, so it is very robust but low powered.

Statistic
4.667
p-value
0.0970
Mood median test on Group 1: n = 12; Group 2: n = 12; Group 3: n = 12: χ²(2) = 4.67, p = .097. The p-value is above α = .050, so the data are compatible with H0.

Mood median test on Group 1: n = 12; Group 2: n = 12; Group 3: n = 12: χ²(2) = 4.67, p = .097. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: independent groups have the same population median under the usual continuous model.

Assumptions

Independent observations and independent groups; ordinal or quantitative measurements. The permutation null is identical group distributions. A location or median interpretation additionally needs comparable distribution shapes.

Formula

X2=∑j=1k∑r=12(Orj−Erj)2ErjX^2=\sum_{j=1}^{k}\sum_{r=1}^{2}\frac{(O_{rj}-E_{rj})^2}{E_{rj}}

Parameters and notation

Form a 2×k table counting observations above versus below the pooled median; E is the independence expectation. Specify how values equal to the median are treated.

Structure of the method

Estimate the pooled median, classify each group into counts above and below it, and test the resulting two-by-k contingency table. Pearson chi-square is the standard large-sample statistic, with optional continuity correction in the two-group case; a conditional permutation calibration instead imposes exchangeability of group labels.

Estimated and nuisance parameters

The pooled median is estimated from all observations and determines the dichotomization. Cell counts, row/column margins, and independence expectations are computed quantities. Population medians are the target, while the observed percentage above a sample-derived threshold is not itself an independently specified population parameter.

Settings and design choices

Prespecify treatment of observations equal to the pooled median, Pearson versus another divergence statistic, continuity correction, alpha, and handling of sparse counts. SciPy defaults put ties below and apply Yates correction when there are two groups. These conventions are consequential for discrete outcomes and should be aligned with any R implementation.

Fitting and adaptation

Recompute the pooled threshold and full table whenever groups or rows change. If the median is instead an externally fixed clinical threshold, describe the resulting analysis as a threshold-proportion comparison. Conditional exact/permutation inference is exact for the relevant exchangeability null, not automatically for every weak equal-median model with different distributions.

Sensitivity and robustness

Dichotomization loses magnitude information and often power. Many observations exactly at the median can dominate the answer through the tie rule. Sparse expected cells undermine ordinary chi-square tails. The generic identical-shape requirement used for rank-sum median interpretations should not be presented as the definition of Mood's equal-median target.

How to use and calibrate

Use the χ²k−1 reference when table counts support it, or a conditional exact/permutation calculation.

Example application

Compare typical waiting times across services with strongly skewed observations.

Interpretation and pitfalls

Watch out

Dichotomization loses information and power. Many ties at the pooled median make conventions consequential.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
  • Rewritten in the review: assumptions.
  • Assumptionsdocs.scipy.org

    The baseline borrowed a rank-sum equal-shape statement instead of describing the median-test target and calibration distinction.

    Corrected text

    Independent groups and independent observations are required. Mood's procedure targets equality of population medians in its usual continuous-data setting; many ties at the pooled median require an explicit convention. Adequate expected table counts support the ordinary chi-square approximation. A conditional exact label-permutation argument requires exchangeability under the corresponding common-distribution null, which is stronger than a general equal-median statement.

Python and R

Ranks/scores use all observations pooled across independent groups; the omnibus p-value is not a pairwise conclusion.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
groups = [rng.normal(m,1,20) for m in (0,.4,.8)]
print(stats.median_test(*groups))
Output
MedianTestResult(statistic=np.float64(8.4), pvalue=np.float64(0.014995576820477707), median=np.float64(0.43343733675337626), table=array([[ 5, 11, 14],
       [15,  9,  6]]))
R

Validated — Executed successfully in the validation environment · needs coin

set.seed(2026)
d <- data.frame(value=c(rnorm(20),rnorm(20,.4),rnorm(20,.8)), group=factor(rep(c("A","B","C"),each=20)))
print(coin::median_test(value~group,data=d))
Output
	Asymptotic K-Sample Brown-Mood Median Test

data:  value by group (A, B, C)
chi-squared = 8.26, df = 2, p-value = 0.01608

Sources

Statistics guide v4 (historical):
R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 025, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT025.