EProportions · Guide test 067
Bhapkar test
Provides an alternative large sample test of marginal homogeneity in paired multicategory tables.
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 · Bhapkar 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 = .676).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- Stuart–Maxwell statistic
- total count
The verdict
χ²(2) = 0.78, p = .676
p > α = .050: compatible with H₀
Asymptotically equivalent to Stuart–Maxwell but slightly more powerful; the two differ only in small samples.
- Statistic
- 0.783
- p-value
- 0.6761
Bhapkar test on a 3 × 3 table of 150 counts: χ²(2) = 0.78, p = .676. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: paired categorical margins are homogeneous.
Assumptions
Independent paired observations with matching categories and large enough discordant counts.
Formula
Parameters and notation
d,V are the marginal difference vector and Stuart–Maxwell covariance from entry 66; N is paired sample size; remove one redundant category.
Structure of the method
Use the same paired marginal difference vector as Stuart–Maxwell but subtract the outer-product correction dd-transpose/N from its covariance estimate. The resulting quadratic form tests marginal homogeneity with an asymptotic chi-square reference in the estimable subspace.
Estimated and nuisance parameters
Estimate paired marginal differences, total pairs, and the corrected covariance matrix. The correction uses observed departure from the null, so finite-sample statistics differ even when both tests share the same large-sample target. Category-specific transition probabilities remain nuisance quantities.
Settings and design choices
Prespecify Bhapkar rather than choosing between it and Stuart–Maxwell after seeing p-values. Record the treatment of redundant categories, numerical rank, and any zero-transition categories. The conventional k-1 degrees of freedom require a full-rank reduced covariance matrix.
Fitting and adaptation
Recompute the corrected covariance after every new sample or bootstrap replicate. A constrained null simulation should preserve the paired multinomial model and marginal-homogeneity constraints. Refitting and recalibration replace any notion of fine-tuning; the procedure does not learn a reusable prediction function.
Sensitivity and robustness
Near-singular covariance can inflate numerical instability, particularly with sparse off-diagonal transitions or very strong marginal changes. Asymptotic equivalence does not promise equal small-sample error or universal power dominance. Review the unaggregated transition table as well as the omnibus p-value.
How to use and calibrate
Use χ²k−1 asymptotically. The empirical covariance correction distinguishes Bhapkar from Stuart–Maxwell.
Example application
Compare pre/post distributions of an ordered or unordered categorical assessment.
Interpretation and pitfalls
Watch out
Asymptotic equivalence does not imply identical small sample p values. Covariance singularity needs explicit handling.
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::BhapkarTest(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::BhapkarTest(tab))
Sources
- DescTools — DescTools · BhapkarTestAuthor documentation/source reviewed: DescTools 0.99.60.search.r-project.org
- BhapkarTestsearch.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 067, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT067.