EProportions · Guide test 066
Stuart–Maxwell test
Tests marginal homogeneity in a square table of paired multicategory outcomes.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Symmetry and marginal homogeneity (Stuart–Maxwell, Bhapkar, Bowker) — Did the distribution of a categorical rating change between two paired measurements?
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 · Stuart–Maxwell test
Your data
Edit the counts| Rater 2: low | mid | high | Total | |
|---|---|---|---|---|
| Rater 1: low | 27E = 11.2 | 8E = 15.0 | 6E = 14.8 | 41 |
| Rater 1: mid | 11E = 16.4 | 35E = 22.0 | 14E = 21.6 | 60 |
| Rater 1: high | 3E = 13.4 | 12E = 18.0 | 34E = 17.6 | 49 |
| Total | 41 | 55 | 54 | 150 |
E is the count expected if rows and columns were unrelated.
If H₀ were true
- The reference: how χ² varies across samples when H₀ is true.
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .678).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- row total minus column total for category i
- covariance of d under marginal homogeneity
The verdict
χ²(2) = 0.78, p = .678
p > α = .050: compatible with H₀
Marginal homogeneity: the generalization of McNemar to more than two categories.
- Statistic
- 0.779
- p-value
- 0.6775
Stuart–Maxwell test on a 3 × 3 table of 150 counts: χ²(2) = 0.78, p = .678. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: row and column marginal distributions of a paired k-category response are equal.
Assumptions
Independent paired units; the same k categories in both measurements; adequate discordant counts.
Formula
Parameters and notation
Use k−1 independent marginal differences and the corresponding covariance submatrix; use estimable rank if singular.
Structure of the method
Form the vector of row-minus-column marginal differences in a square paired-category table. Estimate their covariance from opposite off-diagonal transitions, remove redundant directions, and compute a covariance-weighted quadratic form. The asymptotic reference dimension is the estimable contrast rank.
Estimated and nuisance parameters
Estimated quantities are the marginal differences and their covariance matrix. One linear constraint makes the full k-component difference vector redundant. Transition probabilities are nuisance features of the paired joint distribution; the null constrains margins, not each opposite cell pair.
Settings and design choices
Fix the common category dictionary, category ordering for presentation, singularity tolerance, and excluded uninformative categories. Pooling categories changes the tested margins and should have substantive justification. Do not select categories to improve invertibility or significance without documenting the resulting target.
Fitting and adaptation
Refit the marginal contrasts and covariance for each dataset. A bootstrap under the marginal-homogeneity null needs a constrained paired-table model; arbitrary within-pair swapping instead enforces symmetry and tests a stronger null. No neural fine-tuning or independent-sample recoding is appropriate.
Sensitivity and robustness
Sparse transition networks or perfectly agreeing categories can make covariance singular and reduce effective degrees of freedom. Marginal homogeneity can hold while opposing transitions are asymmetric. The current original entry correctly distinguishes it from Bowker; some brief software descriptions blur that distinction.
How to use and calibrate
Compare Q with χ²k−1 under regularity. This generalizes McNemar to multiple categories.
Example application
Assess whether a three-category rating distribution changed after training.
Interpretation and pitfalls
Watch out
Marginal homogeneity is weaker than full table symmetry. Sparse or disconnected transitions can make covariance singular.
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.
Python and R
Square table of paired categorical observations. Marginal homogeneity and full symmetry are different null hypotheses.
Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: DescTools
# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
tab <- matrix(c(20,5,3,7,25,4,2,6,22),3,byrow=TRUE)
print(DescTools::StuartMaxwellTest(tab))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
text=True, capture_output=True)
print(result.stdout)
if result.stderr:
print(result.stderr)
result.check_returncode()
Not run — Syntax checked; runtime not verified in the final environment · needs DescTools
tab <- matrix(c(20,5,3,7,25,4,2,6,22),3,byrow=TRUE)
print(DescTools::StuartMaxwellTest(tab))
Sources
- DescTools — DescTools · StuartMaxwellTestAuthor documentation/source reviewed: DescTools 0.99.60.search.r-project.org
- StuartMaxwellTestsearch.r-project.org
- Statistics guide v4 (historical):
- Python: Python launcher syntax checked; R backend runtime not verified · R: Syntax checked; runtime not verified in the final environment
- Reference's record:
- Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 066, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT066.