EProportions · Guide test 071
Woolf homogeneity test
Uses estimated log odds ratios and variances to test their equality across strata.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Cochran–Mantel–Haenszel test (stratified 2 × 2) — Are group and outcome associated after adjusting for a stratifying variable?
In Cochran–Mantel–Haenszel test (stratified 2 × 2), choose Homogeneity test = Woolf.
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 · Woolf homogeneity test
Your data
Edit the counts| Event | No event | Total | |
|---|---|---|---|
| Stratum 1: exposed | 16E = 29.0 | 44E = 31.0 | 60 |
| Stratum 1: unexposed | 13E = 29.0 | 47E = 31.0 | 60 |
| Stratum 2: exposed | 37E = 29.0 | 23E = 31.0 | 60 |
| Stratum 2: unexposed | 23E = 29.0 | 37E = 31.0 | 60 |
| Stratum 3: exposed | 54E = 29.0 | 6E = 31.0 | 60 |
| Stratum 3: unexposed | 31E = 29.0 | 29E = 31.0 | 60 |
| Total | 174 | 186 | 360 |
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 = .019).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- stratum odds ratio
- inverse variance of its log
The verdict
χ²(2) = 7.97, p = .019
p ≤ α = .050: reject H₀
Simple and transparent, but unstable with small cells (½ is added when any cell is zero); Breslow–Day is preferred.
- Statistic
- 7.965
- p-value
- 0.0186
Woolf homogeneity test on a 6 × 2 table of 360 counts: χ²(2) = 7.97, p = .019. The p-value is below α = .050, so the data are hard to reconcile with H₀.
Question and hypotheses
H0: stratum log odds ratios are equal.
Assumptions
Independent strata with sufficiently large nonzero cells for normal log odds ratio approximations.
Formula
Parameters and notation
ȳw=Σwsy_s/Σws; S strata.
Structure of the method
Compute each stratum log odds ratio and its approximate inverse variance, form the precision-weighted common log effect, and sum weighted squared deviations from that mean. The chi-square heterogeneity reference has S-1 degrees of freedom under regular large-cell conditions.
Estimated and nuisance parameters
Estimated quantities are four-cell log odds ratios, reciprocal-cell variance estimates, and their weighted mean. Weights are random because they depend on observed cells. Sample sizes and stratum definitions are design quantities; the common log odds ratio is fitted under the null.
Settings and design choices
Fix the strata, effect orientation, and any zero-cell correction before comparing results. State whether a correction is added to every cell or only affected tables. Different corrections can change both each effect and its weight, especially in small studies.
Fitting and adaptation
New observations require recomputing effects, weights, and the weighted mean. A null bootstrap must regenerate whole strata under a shared odds ratio and refit weights rather than treating observed weights as immutable. Classical refitting, not neural fine-tuning, describes this adaptation.
Sensitivity and robustness
A single sparse cell can dominate the approximation or force an arbitrary correction. Large differences with imprecise estimates can produce weak evidence, while many precise strata can detect minor heterogeneity. This is a homogeneity test; it does not test whether the pooled odds ratio equals one.
How to use and calibrate
Use χ²S−1 approximately. If continuity corrections are used, disclose their amount and scope.
Example application
Assess odds ratio heterogeneity across several 2×2 studies.
Interpretation and pitfalls
Watch out
Arbitrary zero-cell corrections can materially alter results. This is a heterogeneity test, not a test of pooled association.
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
Three independent 2×2 strata; maintain the same category ordering in every stratum. Homogeneity tests assess whether a common odds ratio is tenable.
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 <- array(c(18,9,12,21,15,7,15,23,20,12,10,18),dim=c(2,2,3))
print(DescTools::WoolfTest(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 <- array(c(18,9,12,21,15,7,15,23,20,12,10,18),dim=c(2,2,3))
print(DescTools::WoolfTest(tab))
Sources
- DescTools — DescTools · WoolfTestAuthor documentation/source reviewed: DescTools 0.99.60.search.r-project.org
- WoolfTestsearch.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 071, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT071.