[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EBWXJBV4JCQR3VNX2Q514C":3,"skill-same:01M7EBWXJBV4JCQR3VNX2Q514C":62},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":14,"repositoryHtmlUrl":33,"repositoryHomepageUrl":33,"ownerHtmlUrl":34,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":35,"install":36,"resources":49},"01M7EBWXJBV4JCQR3VNX2Q514C","bio-clinical-biostatistics-categorical-tests",null,"Tests associations between categorical variables in clinical data using chi-square, Fisher's exact, Boschloo, Cochran-Mantel-Haenszel, and modern McNemar variants with calibrated confidence intervals (Wilson, Newcombe, Miettinen-Nurminen). Use when analyzing categorical outcomes, paired binary endpoints, or testing treatment-outcome independence in confirmatory or exploratory clinical trials.","Mr-Nobody-Anonymous\u002FAll-skills","Mr-Nobody-Anonymous","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184253119?v=4","01M7AEXFJHKTYQW5R0ZCQQTWFV","anonymous","01M7C00M3GQR4QKP9GZA42GFAK",0,"MIT","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-clinical-biostatistics-categorical-tests\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: bio-clinical-biostatistics-categorical-tests\ndescription: Tests associations between categorical variables in clinical data using chi-square, Fisher's exact, Boschloo, Cochran-Mantel-Haenszel, and modern McNemar variants with calibrated confidence intervals (Wilson, Newcombe, Miettinen-Nurminen). Use when analyzing categorical outcomes, paired binary endpoints, or testing treatment-outcome independence in confirmatory or exploratory clinical trials.\ntool_type: python\nprimary_tool: scipy\nsource: \"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills\"\nsource_repository: \"GPTomics\u002FbioSkills\"\nsource_path: \"clinical-biostatistics\u002Fcategorical-tests\u002FSKILL.md\"\nlicense: \"MIT\"\nimported_at: \"2026-09-20\"\n---\n\n## Version Compatibility\n\nReference examples tested with: scipy 1.12+ (Boschloo and Barnard added in 1.7), statsmodels 0.14+, pingouin 0.5+, exact2x2 (R) 1.6+, pandas 2.1+, numpy 1.26+.\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show \u003Cpackage>` then `help(module.function)` to check signatures\n- R packages cited for reference (exact2x2, Exact, ratesci): use `packageVersion()` then `?function_name` to verify parameters\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.\n\n# Categorical Association Tests for Clinical Data\n\n**\"Test association between categorical variables\"** -> Determine whether treatment and a categorical clinical outcome are statistically independent (or that marginal proportions agree, for paired data) using a test calibrated to the design, the sample size, and the regulatory question.\n\n## Algorithmic Taxonomy\n\n| Test | Design | Asymptotic \u002F exact | Conditioning | Strength | Fails when |\n|------|--------|--------------------|--------------|----------|------------|\n| Pearson chi-square (no continuity correction) | Independent groups, any RxC | Asymptotic | None | Standard for n>=40 with all expected counts >=5; matches Miettinen-Nurminen score CI | Any expected cell \u003C1; >20% of cells with expected \u003C5 (Cochran 1954) |\n| Fisher's exact (conditional) | Independent 2x2 | Exact | Conditions on BOTH margins | Exact small-sample guarantee on level | Conservative (true alpha \u003C\u003C nominal); discards information by double conditioning (Mehta-Senchaudhuri 2003) |\n| Boschloo's exact | Independent 2x2 | Exact unconditional | Conditions on ONE margin only | Uniformly more powerful than Fisher (Boschloo 1970; Mehta-Senchaudhuri 2003); preserves nominal alpha exactly | Computationally heavier; RxC extensions limited |\n| Barnard's exact | Independent 2x2 | Exact unconditional | Conditions on ONE margin only | Maximises nuisance parameter; well-calibrated | Slightly less powerful than Boschloo on average; compute scales O(n^2) |\n| CMH (Mantel-Haenszel) | Stratified independent groups | Asymptotic | Conditions within strata | Tests common-OR null across strata; pooled OR estimator | Assumes no qualitative interaction; misleading when ORs reverse direction across strata |\n| Breslow-Day | Stratified independent groups | Asymptotic | Within strata | Tests homogeneity of stratum ORs | Underpowered with few strata or sparse strata; non-significance does NOT prove homogeneity |\n| McNemar (asymptotic, no continuity correction) | Paired binary | Asymptotic | Conditions on discordant pairs | Fagerland 2013 default; outperforms exact conditional | Discordant pair count b+c \u003C 25 (chi-square approximation breaks) |\n| Mid-p McNemar | Paired binary | Quasi-exact | Discordant pairs | Fagerland-Lydersen-Laake 2013 recommended default; less conservative than exact conditional | Slight under-coverage tolerable at small b+c |\n| Exact conditional McNemar (Liddell 1983) | Paired binary | Exact | Discordant pairs only | Guaranteed coverage | Over-conservative; loses power vs mid-p or unconditional |\n| Suissa-Shuster exact unconditional | Paired binary | Exact unconditional | All N pairs | Uniformly more powerful than exact conditional McNemar; 20-40% smaller n for same power | Implementation only in R `exact2x2::mcnemarExactDP` and SAS macros |\n\n**Postdoc reading:** Lydersen, Fagerland & Laake 2009 *Stat Med* 28:1159 (\"Recommended tests for association in 2x2 tables\") argues **Fisher's exact should be retired from routine use** in favour of Boschloo or asymptotic Pearson; Fagerland-Lydersen-Laake 2013 *BMC Med Res Methodol* 13:91 makes the parallel case for mid-p or asymptotic McNemar over exact conditional. Regulatory practice (FDA reviewers) is moving in this direction but Fisher and exact conditional McNemar remain entrenched in many SAPs by inertia.\n\n## Decision Tree by Experimental Scenario\n\n| Scenario | Recommended test | Why |\n|----------|------------------|-----|\n| Independent 2x2, all expected >=5, n>=40 | Pearson chi-square, `correction=False` | Standard asymptotic; Yates' continuity correction is overly conservative and now discouraged |\n| Independent 2x2, expected \u003C5 in any cell OR n\u003C40 | Boschloo's exact (`scipy.stats.boschloo_exact`) | Uniformly more powerful than Fisher; preserves exact Type-I control |\n| Independent RxC, expected \u003C5 in >20% of cells | Permutation chi-square or Fisher-Freeman-Halton (R `coin::chisq_test(distribution = approximate())`) | Exact RxC asymptotic invalid; permutation preserves level |\n| Stratified design (multi-site, multi-stratum randomisation) | CMH for the pooled test + Breslow-Day for homogeneity + per-stratum ORs | Stratification factor in randomisation MUST appear in analysis (Kahan-Morris 2012 *Stat Med* 31:328: ignoring is over-conservative -- SE biased upward, power loss) |\n| Stratified with sign-reversing effect (Simpson's paradox suspected) | Always report stratum-specific ORs + visual diagnostic; consider logistic regression with interaction | CMH pooled OR can mask sign reversal; homogeneity test underpowered |\n| Paired binary (pre\u002Fpost on same subjects; matched case-control) | Asymptotic McNemar (`mcnemar(table, exact=False, correction=False)`) when b+c >= 25; mid-p when b+c \u003C 25 | Fagerland 2013 simulations show mid-p and asymptotic outperform exact conditional |\n| Matched-pair non-inferiority (especially diagnostics) | Suissa-Shuster exact unconditional via R `exact2x2` | 20-40% smaller n than exact conditional for same power |\n| Composite endpoint (any of several events) | Logistic regression with covariate adjustment, not chi-square | Composite changes the estimand under ICH E9(R1); see clinical-biostatistics\u002Feffect-measures |\n\n## Chi-Square Test (Pearson, no continuity correction)\n\n**Goal:** Test whether treatment group and outcome category are independent under asymptotic Type-I control.\n\n**Approach:** Construct a contingency table, verify expected cell counts, compute the Pearson chi-square statistic without Yates' continuity correction.\n\n```python\nfrom scipy.stats import chi2_contingency\nimport pandas as pd\n\ntable = pd.crosstab(df['treatment'], df['outcome'])\nchi2, p, dof, expected = chi2_contingency(table, correction=False)\nif (expected \u003C 5).any():\n    print('WARNING: switch to Boschloo (2x2) or permutation chi-square (RxC)')\n```\n\n**Cochran 1954 rule (the precise version, not the textbook caricature):** \"no expected cell should be \u003C1 AND no more than 20% of cells should have expected \u003C5.\" The textbook \"all >=5\" rule is the conservative simplification. With well-balanced 2x2 trials this rarely matters; with sparse RxC tables it materially expands the asymptotic range. The R `chisq.test` issues a warning under the strict Cochran rule; Python users must check manually.\n\n**Why Yates' correction is now discouraged:** continuity correction was introduced to approximate the exact distribution under H0 but inflates Type-II error by ~10% (D'Agostino, Chase & Belanger 1988 *Am Stat* 42:198). Modern computing makes Boschloo's exact test cheap; the correct fix for sparse 2x2 is Boschloo, not chi-square + continuity.\n\n## Fisher's Exact -- and why Boschloo is usually better\n\n**Goal:** Test 2x2 association with exact Type-I control.\n\n**Approach:** Use Fisher's exact only when historical SAP requires it; otherwise prefer Boschloo's test.\n\n```python\nfrom scipy.stats import fisher_exact, boschloo_exact\n\nodds_ratio, p_fisher = fisher_exact(table.values, alternative='two-sided')\n\n# Boschloo (uniformly more powerful than Fisher):\n# n= controls Sobol sampling resolution for the null distribution (scipy 1.12+; default 32);\n# higher = more precise p-value at higher CPU cost. NOT the sample size per arm.\nresult = boschloo_exact(table.values, alternative='two-sided', n=64)\np_boschloo = result.pvalue\n```\n\n**The conditioning critique (Mehta-Senchaudhuri 2003):** Fisher's exact conditions on both margins of the 2x2 table, discarding information about the marginal totals. Boschloo conditions on one margin only and treats the second as a nuisance to be maximised over -- recovering the discarded information. Power gain at n=10\u002Farm is 16-20 percentage points for moderate effects. Boschloo *uses Fisher's p-value as its test statistic*, then computes the exact unconditional null distribution of that p-value -- so it is automatically at least as powerful as Fisher.\n\n**Since scipy 1.10**, `fisher_exact` returns the sample (unconditional) odds ratio, not the conditional MLE. For the conditional MLE matching R's `fisher.test`, use `scipy.stats.contingency.odds_ratio(table, kind='conditional')`.\n\n## Cochran-Mantel-Haenszel (Stratified)\n\n**Goal:** Test treatment-outcome association while controlling for a stratification variable; quantify the common odds ratio across strata.\n\n**Approach:** Construct per-stratum 2x2 tables, compute MH pooled OR and CMH test of H0: common-OR = 1; test homogeneity via Breslow-Day.\n\n```python\nfrom statsmodels.stats.contingency_tables import StratifiedTable\nimport pandas as pd\n\ntables = []\nfor stratum in df['site'].unique():\n    stratum_data = df[df['site'] == stratum]\n    t = pd.crosstab(stratum_data['treatment'], stratum_data['outcome']).values\n    if t.shape == (2, 2) and t.min() > 0:\n        tables.append(t)\n\nst = StratifiedTable(tables)\nprint(st.test_null_odds())          # CMH H0: common OR = 1\nprint(st.oddsratio_pooled)          # MH pooled OR\nprint(st.oddsratio_pooled_confint(method='normal'))\nprint(st.test_equal_odds())         # Breslow-Day H0: equal stratum ORs\n```\n\n### Per-method failure modes\n\n**CMH -- Simpson's paradox masking**\n\n- **Trigger:** Stratum-specific ORs reverse direction across strata while the pooled MH OR appears null or modestly different from 1.\n- **Mechanism:** CMH pools weighted log-ORs; equal-magnitude opposite-sign ORs cancel.\n- **Symptom:** Breslow-Day p \u003C 0.05 with stratum ORs visually reversing.\n- **Fix:** Report stratum-specific ORs as primary; the MH pooled estimate is not a valid summary. Move to logistic regression with treatment-by-stratum interaction.\n\n**Breslow-Day -- low-power false reassurance**\n\n- **Trigger:** Few strata (k\u003C5) or sparse strata (mean cell count \u003C10).\n- **Mechanism:** Breslow-Day chi-square has k-1 df; with k=3 and modest heterogeneity, power can be \u003C40%.\n- **Symptom:** Breslow-Day p > 0.5 with stratum ORs visually heterogeneous on a forest plot.\n- **Fix:** Always supplement with a forest plot of stratum-specific ORs. Use likelihood-ratio interaction test from logistic regression as a second check.\n\n**CMH -- ignoring randomisation stratification factors**\n\n- **Trigger:** Randomisation was stratified (sex, region, baseline severity) but the primary analysis pools across strata.\n- **Mechanism:** Stratified randomisation removes between-stratum variability that the unstratified SE still counts.\n- **Symptom:** Over-conservative inference -- SE biased upward, CIs too wide, Type-I below nominal, power loss (Kahan-Morris 2012).\n- **Fix:** Strata variables from randomisation MUST appear in analysis -- either CMH, logistic regression with strata, or stratified log-rank.\n\n## McNemar's Test for Paired Binary Data\n\n**Goal:** Test the null of marginal homogeneity (P(positive at time 1) = P(positive at time 2)) for paired binary observations.\n\n**Approach:** Default to asymptotic McNemar without continuity correction when discordant pairs >=25; switch to mid-p when discordant pairs \u003C25; reserve exact conditional only when regulator-mandated.\n\n```python\nfrom statsmodels.stats.contingency_tables import mcnemar\nimport numpy as np\n\n# table[i,j] = count with outcome i at time 1 and j at time 2\ntable = np.array([[45, 15], [5, 35]])  # b=15, c=5 discordant\n\n# Asymptotic, no continuity correction -- the Fagerland 2013 recommended default\nresult = mcnemar(table, exact=False, correction=False)\nprint(result.statistic, result.pvalue)\n\n# Exact conditional (Liddell 1983) -- only when b+c is very small or required by SAP\nresult_exact = mcnemar(table, exact=True)\n```\n\n**Fagerland-Lydersen-Laake 2013 *BMC Med Res Methodol* 13:91 simulation findings:** mid-p McNemar and asymptotic McNemar (no continuity correction) outperform exact conditional McNemar across small-to-moderate samples. The exact conditional is *too conservative* because it conditions on a discrete margin (the discordant pair count). Their title is the methodological provocation -- \"The McNemar test: asymptotic and mid-p are better than exact conditional.\"\n\n**Suissa-Shuster 1991 *Biometrics* 47:361 exact unconditional** uses *all* N pairs (not just discordant) -- uniformly more powerful than exact conditional McNemar; sample sizes 20-40% smaller for the same power. Available in R `exact2x2::mcnemarExactDP`. Practically essential for matched-pair non-inferiority in diagnostic device trials.\n\n## Effect Sizes for Categorical Data\n\n**Goal:** Quantify association strength beyond p-values.\n\n**Approach:** Phi for 2x2, Cramer's V for RxC; bias-corrected variants in pingouin.\n\n```python\nimport numpy as np\nimport pingouin as pg\n\nn = table.values.sum()\nphi = np.sqrt(chi2 \u002F n)\nk = min(table.shape) - 1\ncramers_v = np.sqrt(chi2 \u002F (n * k))\n\n# Pingouin with multiple test variants and bias correction:\nexpected, observed, stats = pg.chi2_independence(df, x='treatment', y='outcome')\n# stats columns: test, lambda, chi2, dof, pval, cramer, power\n```\n\n**Cohen 1988 effect-size benchmarks:**\n\n| df | Small | Medium | Large |\n|----|-------|--------|-------|\n| 1 | 0.10 | 0.30 | 0.50 |\n| 2 | 0.07 | 0.21 | 0.35 |\n| 3 | 0.06 | 0.17 | 0.29 |\n\nPhi equals Cramer's V for 2x2 (k=1). For RxC, only Cramer's V is valid because phi can exceed 1.\n\n## Reconciliation: When Methods Disagree\n\n| Pattern | Likely cause | Action |\n|---------|--------------|--------|\n| Fisher exact p > 0.05 but Boschloo p \u003C 0.05 | Fisher over-conservative via double-margin conditioning (Mehta-Senchaudhuri 2003); Boschloo recovers power | Cite Boschloo as primary; provide Fisher in appendix for transparency |\n| Pearson chi-square p \u003C 0.05 but Fisher exact p > 0.05 | Asymptotic approximation breaking down at small expected counts (Cochran rule violation) | Use Boschloo (exact unconditional, more powerful than Fisher); document expected-count diagnostic in SAP |\n| CMH pooled OR not significant, stratum-specific ORs strongly differ | Simpson's paradox -- opposite-sign cancellation OR effect modification | Report stratum-specific ORs as primary; switch to logistic regression with treatment-by-stratum interaction; forest plot stratum ORs |\n| Breslow-Day non-significant but stratum-OR forest plot visually heterogeneous | Low power of Breslow-Day with few\u002Fsparse strata | Cite low-power caveat; report LR interaction test from logistic as secondary; do NOT claim homogeneity |\n| McNemar exact conditional p > 0.05 but mid-p McNemar p \u003C 0.05 | Exact conditional over-conservative due to discrete-margin conditioning | Cite Fagerland-Lydersen-Laake 2013; mid-p or asymptotic recommended; exact conditional only when SAP-mandated |\n| Suissa-Shuster unconditional p \u003C exact conditional McNemar p | Unconditional uses all N pairs; conditional discards concordant pairs | Suissa-Shuster preferred for matched-pair NI (esp. diagnostic devices) due to 20-40% smaller n |\n| Wald CI excludes null but Wilson\u002FNewcombe CI overlaps null | Wald has poor coverage near 0 and 1 (Brown-Cai-DasGupta 2001) | Wilson\u002FNewcombe\u002FMN preferred; cite as regulatory standard |\n| Multiple categorical secondary endpoints, correlation structure unclear | Bonferroni overly conservative; Hochberg requires PRDS (Sarkar 1998) | See clinical-biostatistics\u002Fmultiplicity-graphical for Bretz-Maurer graphical procedures and PRDS check |\n\n## Confidence Intervals for Proportions and Differences\n\nFor a single proportion, **Wald is bad** for small samples and extreme p (Brown-Cai-DasGupta 2001 *Stat Sci* 16:101 documents \"chaotic\" coverage with coverage dropping to 0.0 in extreme cells). Use Wilson score or Jeffreys.\n\nFor a 2x2 risk difference or risk ratio, the regulatory standard for CI is **Miettinen-Nurminen score-based** (1985 *Stat Med* 4:213) -- consistent with the Pearson chi-square test and accepted by FDA\u002FEMA for noninferiority margins.\n\n```python\nfrom statsmodels.stats.proportion import proportion_confint, proportions_ztest\n\n# Single proportion: Wilson is the modern default\nci = proportion_confint(45, 60, alpha=0.05, method='wilson')\n# Also available: 'jeffreys', 'agresti_coull', 'beta' (Clopper-Pearson exact)\n\n# Difference of proportions: Newcombe-Wilson hybrid \u002F MOVER\nfrom statsmodels.stats.proportion import confint_proportions_2indep\nci_diff = confint_proportions_2indep(45, 60, 30, 60, method='newcomb', alpha=0.05)\n# 'wald' is discouraged; 'newcomb' (Newcombe-Wilson hybrid) and 'agresti-caffo' are calibrated\n```\n\nFor Miettinen-Nurminen CIs (the regulatory standard for stratified RD or RR), use R `ratesci::scoreci(contrast='RD'|'RR', distrib='bin', stratified=TRUE)` -- there is no production-grade Python implementation as of 2026.\n\n## Post-Hoc Pairwise Comparisons\n\n```python\nfrom statsmodels.stats.multitest import multipletests\nfrom itertools import combinations\n\ncategories = df['outcome'].unique()\npvalues, comparisons = [], []\nfor cat1, cat2 in combinations(categories, 2):\n    subset = df[df['outcome'].isin([cat1, cat2])]\n    sub_table = pd.crosstab(subset['treatment'], subset['outcome'])\n    _, p_val, _, _ = chi2_contingency(sub_table, correction=False)\n    pvalues.append(p_val)\n    comparisons.append(f'{cat1} vs {cat2}')\n\nreject, adjusted_p, _, _ = multipletests(pvalues, method='holm')\n```\n\n`method='holm'` (FWER) for confirmatory; `method='fdr_bh'` for exploratory. **Critical bug:** `multipletests` default is `method='hs'` (Holm-Sidak), NOT Holm or Bonferroni -- always specify explicitly. The FDA Multiple Endpoints Final Guidance (October 2022) requires FWER control for key secondary endpoints in regulatory submissions; FDR is acceptable for exploratory subgroup screens only.\n\n## Quantitative Thresholds\n\n| Threshold | Source | Rationale |\n|-----------|--------|-----------|\n| n >= 40 for 2x2 chi-square | Cochran 1954 *Biometrics* 10:417 | Below this, asymptotic chi-square distribution approximation degrades regardless of expected counts |\n| All expected >=5 OR \u003C=20% with expected \u003C5 AND none \u003C1 | Cochran 1954 (strict) | Textbook \"all >=5\" is overconservative; the strict rule expands chi-square's valid range |\n| Yates' correction discouraged | D'Agostino, Chase & Belanger 1988 *Am Stat* 42:198 | Overly conservative; correct fix for sparse 2x2 is Boschloo's exact, not continuity-corrected chi-square |\n| Discordant pairs >=25 for asymptotic McNemar | Fagerland-Lydersen-Laake 2013 *BMC MRM* 13:91 | Below this, chi-square approximation breaks; switch to mid-p, not exact conditional |\n| Newcombe-Wilson \u002F Miettinen-Nurminen for RD CI | Newcombe 1998a *Stat Med* 17:873 | Wald CI for RD has poor coverage and can produce limits outside [-1, 1] |\n| Boschloo > Fisher for small 2x2 | Mehta-Senchaudhuri 2003; Lydersen-Fagerland-Laake 2009 *Stat Med* 28:1159 | Boschloo uniformly more powerful at same Type-I |\n\n## Common Errors\n\n| Error \u002F symptom | Cause | Solution |\n|-----------------|-------|----------|\n| `multipletests(p)` returns Holm-Sidak adjusted p | Default method is 'hs' not Holm\u002FBonferroni | Always specify `method='holm'` or `'bonferroni'` explicitly |\n| `Table2x2(crosstab.values)` gives reciprocal OR | `pd.crosstab` orders columns alphabetically; statsmodels expects event-positive column first | Reorder: `cross[[1, 0]]` or `cross[['Yes', 'No']]` |\n| Fisher's exact in published paper, Boschloo missing | SAP inertia; reviewers unfamiliar with Boschloo | Cite Mehta-Senchaudhuri 2003 in the SAP; use Boschloo as primary with Fisher in appendix |\n| `fisher_exact` returns \"wrong\" OR vs R | Since scipy 1.10, scipy returns sample (unconditional) OR; R returns conditional MLE | Use `scipy.stats.contingency.odds_ratio(table, kind='conditional')` to match R |\n| CMH significant but stratum ORs reverse direction | Simpson's paradox; Breslow-Day underpowered | Forest plot stratum ORs; report stratum-specific as primary; switch to logistic with interaction |\n| Yates' correction enabled by default in `chi2_contingency` | scipy default is `correction=True` for 2x2 | Always pass `correction=False` for Pearson chi-square |\n| McNemar p-value much larger than expected | Default may be exact conditional in some packages; over-conservative | Use asymptotic without continuity correction (Fagerland 2013) |\n| Stratified randomisation ignored in primary analysis | Common SAP error | Include strata in CMH, logistic, or stratified log-rank; ignoring is over-conservative -- SE biased upward, power loss (Kahan-Morris 2012) |\n\n## Anticipated Reviewer Pushback\n\n| Pushback | Response |\n|----------|----------|\n| \"Why not Fisher's exact?\" | Cite Lydersen-Fagerland-Laake 2009; Boschloo is uniformly more powerful at same alpha. Provide Fisher p in appendix for direct comparison. |\n| \"Why no continuity correction?\" | D'Agostino-Chase-Belanger 1988 -- Yates' inflates Type-II by ~10%. The correct fix for sparse 2x2 is Boschloo's exact, not Yates'. |\n| \"Are these ORs collapsible?\" | OR is non-collapsible (see clinical-biostatistics\u002Feffect-measures); marginal and conditional ORs differ even without confounding. Cite Permutt 2020. |\n| \"Why mid-p McNemar over exact conditional?\" | Fagerland-Lydersen-Laake 2013 simulations show exact conditional is over-conservative; mid-p and asymptotic maintain nominal Type-I with better power. |\n| \"Adjustment for stratification factors?\" | Per ICH E9 and FDA 2023 covariate adjustment guidance, strata from randomisation must appear in analysis. CMH or logistic with strata as covariates. |\n| \"What is the estimand?\" | Per ICH E9(R1), categorical-test analyses target a specific estimand (treatment policy is implicit if all randomised analysed). Articulate explicitly. |\n\n## References\n\n- Boschloo RD. 1970. Raised conditional level of significance for the 2x2 table when testing the equality of two probabilities. *Stat Neerl* 24:1.\n- Brown LD, Cai TT, DasGupta A. 2001. Interval estimation for a binomial proportion. *Stat Sci* 16:101-117.\n- Cochran WG. 1954. Some methods for strengthening the common chi-squared tests. *Biometrics* 10:417-451.\n- D'Agostino RB, Chase W, Belanger A. 1988. The appropriateness of some common procedures for testing the equality of two independent binomial populations. *Am Stat* 42:198-202.\n- Fagerland MW, Lydersen S, Laake P. 2013. The McNemar test for binary matched-pairs data: mid-p and asymptotic are better than exact conditional. *BMC Med Res Methodol* 13:91.\n- FDA. 2022. Multiple Endpoints in Clinical Trials -- Guidance for Industry. Federal Register Oct 2022.\n- Kahan BC, Morris TP. 2012. Improper analysis of trials randomised using stratified blocks or minimisation. *Stat Med* 31:328-340.\n- Liddell FDK. 1983. Simplified exact analysis of case-referent studies; matched pairs; dichotomous exposure. *J Epidemiol Community Health* 37:82-84.\n- Lydersen S, Fagerland MW, Laake P. 2009. Recommended tests for association in 2x2 tables. *Stat Med* 28:1159-1175.\n- Mehta CR, Senchaudhuri P. 2003. Conditional vs unconditional exact tests for comparing two binomials. (Cytel technical report; widely cited in subsequent literature.)\n- Miettinen O, Nurminen M. 1985. Comparative analysis of two rates. *Stat Med* 4:213-226.\n- Newcombe RG. 1998a. Interval estimation for the difference between independent proportions: comparison of eleven methods. *Stat Med* 17:873-890.\n- Newcombe RG. 1998b. Improved confidence intervals for the difference between binomial proportions based on paired data. *Stat Med* 17:2635-2650.\n- Permutt T. 2020. Do covariates change the estimand? *Stat Biopharm Res* 12:45-53.\n- Suissa S, Shuster JJ. 1991. The 2x2 matched-pairs trial: exact unconditional design and analysis. *Biometrics* 47:361-372.\n\n## Related Skills\n\n- clinical-biostatistics\u002Feffect-measures - Detailed OR\u002FRR\u002FRD with modern CI methods (Wilson, Newcombe, Miettinen-Nurminen)\n- clinical-biostatistics\u002Flogistic-regression - Regression alternative with covariate adjustment; modified Poisson for RR\n- clinical-biostatistics\u002Fsubgroup-analysis - Stratified analysis with interaction terms and HTE methods\n- clinical-biostatistics\u002Fmultiplicity-graphical - Bretz-Maurer graphical procedures for confirmatory multiplicity\n- clinical-biostatistics\u002Ftrial-reporting - CONSORT 2025 and ICH E9(R1) reporting of categorical analyses\n- experimental-design\u002Fmultiple-testing - General multiple testing correction methods\n","## Version Compatibility\n\nReference examples tested with: scipy 1.12+ (Boschloo and Barnard added in 1.7), statsmodels 0.14+, pingouin 0.5+, exact2x2 (R) 1.6+, pandas 2.1+, numpy 1.26+.\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show \u003Cpackage>` then `help(module.function)` to check signatures\n- R packages cited for reference (exact2x2, Exact, ratesci): use `packageVersion()` then `?function_name` to verify parameters\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.\n\n# Categorical Association Tests for Clinical Data\n\n**\"Test association between categorical variables\"** -> Determine whether treatment and a categorical clinical outcome are statistically independent (or that marginal proportions agree, for paired data) using a test calibrated to the design, the sample size, and the regulatory question.\n\n## Algorithmic Taxonomy\n\n| Test | Design | Asymptotic \u002F exact | Conditioning | Strength | Fails when |\n|------|--------|--------------------|--------------|----------|------------|\n| Pearson chi-square (no continuity correction) | Independent groups, any RxC | Asymptotic | None | Standard for n>=40 with all expected counts >=5; matches Miettinen-Nurminen score CI | Any expected cell \u003C1; >20% of cells with expected \u003C5 (Cochran 1954) |\n| Fisher's exact (conditional) | Independent 2x2 | Exact | Conditions on BOTH margins | Exact small-sample guarantee on level | Conservative (true alpha \u003C\u003C nominal); discards information by double conditioning (Mehta-Senchaudhuri 2003) |\n| Boschloo's exact | Independent 2x2 | Exact unconditional | Conditions on ONE margin only | Uniformly more powerful than Fisher (Boschloo 1970; Mehta-Senchaudhuri 2003); preserves nominal alpha exactly | Computationally heavier; RxC extensions limited |\n| Barnard's exact | Independent 2x2 | Exact unconditional | Conditions on ONE margin only | Maximises nuisance parameter; well-calibrated | Slightly less powerful than Boschloo on average; compute scales O(n^2) |\n| CMH (Mantel-Haenszel) | Stratified independent groups | Asymptotic | Conditions within strata | Tests common-OR null across strata; pooled OR estimator | Assumes no qualitative interaction; misleading when ORs reverse direction across strata |\n| Breslow-Day | Stratified independent groups | Asymptotic | Within strata | Tests homogeneity of stratum ORs | Underpowered with few strata or sparse strata; non-significance does NOT prove homogeneity |\n| McNemar (asymptotic, no continuity correction) | Paired binary | Asymptotic | Conditions on discordant pairs | Fagerland 2013 default; outperforms exact conditional | Discordant pair count b+c \u003C 25 (chi-square approximation breaks) |\n| Mid-p McNemar | Paired binary | Quasi-exact | Discordant pairs | Fagerland-Lydersen-Laake 2013 recommended default; less conservative than exact conditional | Slight under-coverage tolerable at small b+c |\n| Exact conditional McNemar (Liddell 1983) | Paired binary | Exact | Discordant pairs only | Guaranteed coverage | Over-conservative; loses power vs mid-p or unconditional |\n| Suissa-Shuster exact unconditional | Paired binary | Exact unconditional | All N pairs | Uniformly more powerful than exact conditional McNemar; 20-40% smaller n for same power | Implementation only in R `exact2x2::mcnemarExactDP` and SAS macros |\n\n**Postdoc reading:** Lydersen, Fagerland & Laake 2009 *Stat Med* 28:1159 (\"Recommended tests for association in 2x2 tables\") argues **Fisher's exact should be retired from routine use** in favour of Boschloo or asymptotic Pearson; Fagerland-Lydersen-Laake 2013 *BMC Med Res Methodol* 13:91 makes the parallel case for mid-p or asymptotic McNemar over exact conditional. Regulatory practice (FDA reviewers) is moving in this direction but Fisher and exact conditional McNemar remain entrenched in many SAPs by inertia.\n\n## Decision Tree by Experimental Scenario\n\n| Scenario | Recommended test | Why |\n|----------|------------------|-----|\n| Independent 2x2, all expected >=5, n>=40 | Pearson chi-square, `correction=False` | Standard asymptotic; Yates' continuity correction is overly conservative and now discouraged |\n| Independent 2x2, expected \u003C5 in any cell OR n\u003C40 | Boschloo's exact (`scipy.stats.boschloo_exact`) | Uniformly more powerful than Fisher; preserves exact Type-I control |\n| Independent RxC, expected \u003C5 in >20% of cells | Permutation chi-square or Fisher-Freeman-Halton (R `coin::chisq_test(distribution = approximate())`) | Exact RxC asymptotic invalid; permutation preserves level |\n| Stratified design (multi-site, multi-stratum randomisation) | CMH for the pooled test + Breslow-Day for homogeneity + per-stratum ORs | Stratification factor in randomisation MUST appear in analysis (Kahan-Morris 2012 *Stat Med* 31:328: ignoring is over-conservative -- SE biased upward, power loss) |\n| Stratified with sign-reversing effect (Simpson's paradox suspected) | Always report stratum-specific ORs + visual diagnostic; consider logistic regression with interaction | CMH pooled OR can mask sign reversal; homogeneity test underpowered |\n| Paired binary (pre\u002Fpost on same subjects; matched case-control) | Asymptotic McNemar (`mcnemar(table, exact=False, correction=False)`) when b+c >= 25; mid-p when b+c \u003C 25 | Fagerland 2013 simulations show mid-p and asymptotic outperform exact conditional |\n| Matched-pair non-inferiority (especially diagnostics) | Suissa-Shuster exact unconditional via R `exact2x2` | 20-40% smaller n than exact conditional for same power |\n| Composite endpoint (any of several events) | Logistic regression with covariate adjustment, not chi-square | Composite changes the estimand under ICH E9(R1); see clinical-biostatistics\u002Feffect-measures |\n\n## Chi-Square Test (Pearson, no continuity correction)\n\n**Goal:** Test whether treatment group and outcome category are independent under asymptotic Type-I control.\n\n**Approach:** Construct a contingency table, verify expected cell counts, compute the Pearson chi-square statistic without Yates' continuity correction.\n\n```python\nfrom scipy.stats import chi2_contingency\nimport pandas as pd\n\ntable = pd.crosstab(df['treatment'], df['outcome'])\nchi2, p, dof, expected = chi2_contingency(table, correction=False)\nif (expected \u003C 5).any():\n    print('WARNING: switch to Boschloo (2x2) or permutation chi-square (RxC)')\n```\n\n**Cochran 1954 rule (the precise version, not the textbook caricature):** \"no expected cell should be \u003C1 AND no more than 20% of cells should have expected \u003C5.\" The textbook \"all >=5\" rule is the conservative simplification. With well-balanced 2x2 trials this rarely matters; with sparse RxC tables it materially expands the asymptotic range. The R `chisq.test` issues a warning under the strict Cochran rule; Python users must check manually.\n\n**Why Yates' correction is now discouraged:** continuity correction was introduced to approximate the exact distribution under H0 but inflates Type-II error by ~10% (D'Agostino, Chase & Belanger 1988 *Am Stat* 42:198). Modern computing makes Boschloo's exact test cheap; the correct fix for sparse 2x2 is Boschloo, not chi-square + continuity.\n\n## Fisher's Exact -- and why Boschloo is usually better\n\n**Goal:** Test 2x2 association with exact Type-I control.\n\n**Approach:** Use Fisher's exact only when historical SAP requires it; otherwise prefer Boschloo's test.\n\n```python\nfrom scipy.stats import fisher_exact, boschloo_exact\n\nodds_ratio, p_fisher = fisher_exact(table.values, alternative='two-sided')\n\n# Boschloo (uniformly more powerful than Fisher):\n# n= controls Sobol sampling resolution for the null distribution (scipy 1.12+; default 32);\n# higher = more precise p-value at higher CPU cost. NOT the sample size per arm.\nresult = boschloo_exact(table.values, alternative='two-sided', n=64)\np_boschloo = result.pvalue\n```\n\n**The conditioning critique (Mehta-Senchaudhuri 2003):** Fisher's exact conditions on both margins of the 2x2 table, discarding information about the marginal totals. Boschloo conditions on one margin only and treats the second as a nuisance to be maximised over -- recovering the discarded information. Power gain at n=10\u002Farm is 16-20 percentage points for moderate effects. Boschloo *uses Fisher's p-value as its test statistic*, then computes the exact unconditional null distribution of that p-value -- so it is automatically at least as powerful as Fisher.\n\n**Since scipy 1.10**, `fisher_exact` returns the sample (unconditional) odds ratio, not the conditional MLE. For the conditional MLE matching R's `fisher.test`, use `scipy.stats.contingency.odds_ratio(table, kind='conditional')`.\n\n## Cochran-Mantel-Haenszel (Stratified)\n\n**Goal:** Test treatment-outcome association while controlling for a stratification variable; quantify the common odds ratio across strata.\n\n**Approach:** Construct per-stratum 2x2 tables, compute MH pooled OR and CMH test of H0: common-OR = 1; test homogeneity via Breslow-Day.\n\n```python\nfrom statsmodels.stats.contingency_tables import StratifiedTable\nimport pandas as pd\n\ntables = []\nfor stratum in df['site'].unique():\n    stratum_data = df[df['site'] == stratum]\n    t = pd.crosstab(stratum_data['treatment'], stratum_data['outcome']).values\n    if t.shape == (2, 2) and t.min() > 0:\n        tables.append(t)\n\nst = StratifiedTable(tables)\nprint(st.test_null_odds())          # CMH H0: common OR = 1\nprint(st.oddsratio_pooled)          # MH pooled OR\nprint(st.oddsratio_pooled_confint(method='normal'))\nprint(st.test_equal_odds())         # Breslow-Day H0: equal stratum ORs\n```\n\n### Per-method failure modes\n\n**CMH -- Simpson's paradox masking**\n\n- **Trigger:** Stratum-specific ORs reverse direction across strata while the pooled MH OR appears null or modestly different from 1.\n- **Mechanism:** CMH pools weighted log-ORs; equal-magnitude opposite-sign ORs cancel.\n- **Symptom:** Breslow-Day p \u003C 0.05 with stratum ORs visually reversing.\n- **Fix:** Report stratum-specific ORs as primary; the MH pooled estimate is not a valid summary. Move to logistic regression with treatment-by-stratum interaction.\n\n**Breslow-Day -- low-power false reassurance**\n\n- **Trigger:** Few strata (k\u003C5) or sparse strata (mean cell count \u003C10).\n- **Mechanism:** Breslow-Day chi-square has k-1 df; with k=3 and modest heterogeneity, power can be \u003C40%.\n- **Symptom:** Breslow-Day p > 0.5 with stratum ORs visually heterogeneous on a forest plot.\n- **Fix:** Always supplement with a forest plot of stratum-specific ORs. Use likelihood-ratio interaction test from logistic regression as a second check.\n\n**CMH -- ignoring randomisation stratification factors**\n\n- **Trigger:** Randomisation was stratified (sex, region, baseline severity) but the primary analysis pools across strata.\n- **Mechanism:** Stratified randomisation removes between-stratum variability that the unstratified SE still counts.\n- **Symptom:** Over-conservative inference -- SE biased upward, CIs too wide, Type-I below nominal, power loss (Kahan-Morris 2012).\n- **Fix:** Strata variables from randomisation MUST appear in analysis -- either CMH, logistic regression with strata, or stratified log-rank.\n\n## McNemar's Test for Paired Binary Data\n\n**Goal:** Test the null of marginal homogeneity (P(positive at time 1) = P(positive at time 2)) for paired binary observations.\n\n**Approach:** Default to asymptotic McNemar without continuity correction when discordant pairs >=25; switch to mid-p when discordant pairs \u003C25; reserve exact conditional only when regulator-mandated.\n\n```python\nfrom statsmodels.stats.contingency_tables import mcnemar\nimport numpy as np\n\n# table[i,j] = count with outcome i at time 1 and j at time 2\ntable = np.array([[45, 15], [5, 35]])  # b=15, c=5 discordant\n\n# Asymptotic, no continuity correction -- the Fagerland 2013 recommended default\nresult = mcnemar(table, exact=False, correction=False)\nprint(result.statistic, result.pvalue)\n\n# Exact conditional (Liddell 1983) -- only when b+c is very small or required by SAP\nresult_exact = mcnemar(table, exact=True)\n```\n\n**Fagerland-Lydersen-Laake 2013 *BMC Med Res Methodol* 13:91 simulation findings:** mid-p McNemar and asymptotic McNemar (no continuity correction) outperform exact conditional McNemar across small-to-moderate samples. The exact conditional is *too conservative* because it conditions on a discrete margin (the discordant pair count). Their title is the methodological provocation -- \"The McNemar test: asymptotic and mid-p are better than exact conditional.\"\n\n**Suissa-Shuster 1991 *Biometrics* 47:361 exact unconditional** uses *all* N pairs (not just discordant) -- uniformly more powerful than exact conditional McNemar; sample sizes 20-40% smaller for the same power. Available in R `exact2x2::mcnemarExactDP`. Practically essential for matched-pair non-inferiority in diagnostic device trials.\n\n## Effect Sizes for Categorical Data\n\n**Goal:** Quantify association strength beyond p-values.\n\n**Approach:** Phi for 2x2, Cramer's V for RxC; bias-corrected variants in pingouin.\n\n```python\nimport numpy as np\nimport pingouin as pg\n\nn = table.values.sum()\nphi = np.sqrt(chi2 \u002F n)\nk = min(table.shape) - 1\ncramers_v = np.sqrt(chi2 \u002F (n * k))\n\n# Pingouin with multiple test variants and bias correction:\nexpected, observed, stats = pg.chi2_independence(df, x='treatment', y='outcome')\n# stats columns: test, lambda, chi2, dof, pval, cramer, power\n```\n\n**Cohen 1988 effect-size benchmarks:**\n\n| df | Small | Medium | Large |\n|----|-------|--------|-------|\n| 1 | 0.10 | 0.30 | 0.50 |\n| 2 | 0.07 | 0.21 | 0.35 |\n| 3 | 0.06 | 0.17 | 0.29 |\n\nPhi equals Cramer's V for 2x2 (k=1). For RxC, only Cramer's V is valid because phi can exceed 1.\n\n## Reconciliation: When Methods Disagree\n\n| Pattern | Likely cause | Action |\n|---------|--------------|--------|\n| Fisher exact p > 0.05 but Boschloo p \u003C 0.05 | Fisher over-conservative via double-margin conditioning (Mehta-Senchaudhuri 2003); Boschloo recovers power | Cite Boschloo as primary; provide Fisher in appendix for transparency |\n| Pearson chi-square p \u003C 0.05 but Fisher exact p > 0.05 | Asymptotic approximation breaking down at small expected counts (Cochran rule violation) | Use Boschloo (exact unconditional, more powerful than Fisher); document expected-count diagnostic in SAP |\n| CMH pooled OR not significant, stratum-specific ORs strongly differ | Simpson's paradox -- opposite-sign cancellation OR effect modification | Report stratum-specific ORs as primary; switch to logistic regression with treatment-by-stratum interaction; forest plot stratum ORs |\n| Breslow-Day non-significant but stratum-OR forest plot visually heterogeneous | Low power of Breslow-Day with few\u002Fsparse strata | Cite low-power caveat; report LR interaction test from logistic as secondary; do NOT claim homogeneity |\n| McNemar exact conditional p > 0.05 but mid-p McNemar p \u003C 0.05 | Exact conditional over-conservative due to discrete-margin conditioning | Cite Fagerland-Lydersen-Laake 2013; mid-p or asymptotic recommended; exact conditional only when SAP-mandated |\n| Suissa-Shuster unconditional p \u003C exact conditional McNemar p | Unconditional uses all N pairs; conditional discards concordant pairs | Suissa-Shuster preferred for matched-pair NI (esp. diagnostic devices) due to 20-40% smaller n |\n| Wald CI excludes null but Wilson\u002FNewcombe CI overlaps null | Wald has poor coverage near 0 and 1 (Brown-Cai-DasGupta 2001) | Wilson\u002FNewcombe\u002FMN preferred; cite as regulatory standard |\n| Multiple categorical secondary endpoints, correlation structure unclear | Bonferroni overly conservative; Hochberg requires PRDS (Sarkar 1998) | See clinical-biostatistics\u002Fmultiplicity-graphical for Bretz-Maurer graphical procedures and PRDS check |\n\n## Confidence Intervals for Proportions and Differences\n\nFor a single proportion, **Wald is bad** for small samples and extreme p (Brown-Cai-DasGupta 2001 *Stat Sci* 16:101 documents \"chaotic\" coverage with coverage dropping to 0.0 in extreme cells). Use Wilson score or Jeffreys.\n\nFor a 2x2 risk difference or risk ratio, the regulatory standard for CI is **Miettinen-Nurminen score-based** (1985 *Stat Med* 4:213) -- consistent with the Pearson chi-square test and accepted by FDA\u002FEMA for noninferiority margins.\n\n```python\nfrom statsmodels.stats.proportion import proportion_confint, proportions_ztest\n\n# Single proportion: Wilson is the modern default\nci = proportion_confint(45, 60, alpha=0.05, method='wilson')\n# Also available: 'jeffreys', 'agresti_coull', 'beta' (Clopper-Pearson exact)\n\n# Difference of proportions: Newcombe-Wilson hybrid \u002F MOVER\nfrom statsmodels.stats.proportion import confint_proportions_2indep\nci_diff = confint_proportions_2indep(45, 60, 30, 60, method='newcomb', alpha=0.05)\n# 'wald' is discouraged; 'newcomb' (Newcombe-Wilson hybrid) and 'agresti-caffo' are calibrated\n```\n\nFor Miettinen-Nurminen CIs (the regulatory standard for stratified RD or RR), use R `ratesci::scoreci(contrast='RD'|'RR', distrib='bin', stratified=TRUE)` -- there is no production-grade Python implementation as of 2026.\n\n## Post-Hoc Pairwise Comparisons\n\n```python\nfrom statsmodels.stats.multitest import multipletests\nfrom itertools import combinations\n\ncategories = df['outcome'].unique()\npvalues, comparisons = [], []\nfor cat1, cat2 in combinations(categories, 2):\n    subset = df[df['outcome'].isin([cat1, cat2])]\n    sub_table = pd.crosstab(subset['treatment'], subset['outcome'])\n    _, p_val, _, _ = chi2_contingency(sub_table, correction=False)\n    pvalues.append(p_val)\n    comparisons.append(f'{cat1} vs {cat2}')\n\nreject, adjusted_p, _, _ = multipletests(pvalues, method='holm')\n```\n\n`method='holm'` (FWER) for confirmatory; `method='fdr_bh'` for exploratory. **Critical bug:** `multipletests` default is `method='hs'` (Holm-Sidak), NOT Holm or Bonferroni -- always specify explicitly. The FDA Multiple Endpoints Final Guidance (October 2022) requires FWER control for key secondary endpoints in regulatory submissions; FDR is acceptable for exploratory subgroup screens only.\n\n## Quantitative Thresholds\n\n| Threshold | Source | Rationale |\n|-----------|--------|-----------|\n| n >= 40 for 2x2 chi-square | Cochran 1954 *Biometrics* 10:417 | Below this, asymptotic chi-square distribution approximation degrades regardless of expected counts |\n| All expected >=5 OR \u003C=20% with expected \u003C5 AND none \u003C1 | Cochran 1954 (strict) | Textbook \"all >=5\" is overconservative; the strict rule expands chi-square's valid range |\n| Yates' correction discouraged | D'Agostino, Chase & Belanger 1988 *Am Stat* 42:198 | Overly conservative; correct fix for sparse 2x2 is Boschloo's exact, not continuity-corrected chi-square |\n| Discordant pairs >=25 for asymptotic McNemar | Fagerland-Lydersen-Laake 2013 *BMC MRM* 13:91 | Below this, chi-square approximation breaks; switch to mid-p, not exact conditional |\n| Newcombe-Wilson \u002F Miettinen-Nurminen for RD CI | Newcombe 1998a *Stat Med* 17:873 | Wald CI for RD has poor coverage and can produce limits outside [-1, 1] |\n| Boschloo > Fisher for small 2x2 | Mehta-Senchaudhuri 2003; Lydersen-Fagerland-Laake 2009 *Stat Med* 28:1159 | Boschloo uniformly more powerful at same Type-I |\n\n## Common Errors\n\n| Error \u002F symptom | Cause | Solution |\n|-----------------|-------|----------|\n| `multipletests(p)` returns Holm-Sidak adjusted p | Default method is 'hs' not Holm\u002FBonferroni | Always specify `method='holm'` or `'bonferroni'` explicitly |\n| `Table2x2(crosstab.values)` gives reciprocal OR | `pd.crosstab` orders columns alphabetically; statsmodels expects event-positive column first | Reorder: `cross[[1, 0]]` or `cross[['Yes', 'No']]` |\n| Fisher's exact in published paper, Boschloo missing | SAP inertia; reviewers unfamiliar with Boschloo | Cite Mehta-Senchaudhuri 2003 in the SAP; use Boschloo as primary with Fisher in appendix |\n| `fisher_exact` returns \"wrong\" OR vs R | Since scipy 1.10, scipy returns sample (unconditional) OR; R returns conditional MLE | Use `scipy.stats.contingency.odds_ratio(table, kind='conditional')` to match R |\n| CMH significant but stratum ORs reverse direction | Simpson's paradox; Breslow-Day underpowered | Forest plot stratum ORs; report stratum-specific as primary; switch to logistic with interaction |\n| Yates' correction enabled by default in `chi2_contingency` | scipy default is `correction=True` for 2x2 | Always pass `correction=False` for Pearson chi-square |\n| McNemar p-value much larger than expected | Default may be exact conditional in some packages; over-conservative | Use asymptotic without continuity correction (Fagerland 2013) |\n| Stratified randomisation ignored in primary analysis | Common SAP error | Include strata in CMH, logistic, or stratified log-rank; ignoring is over-conservative -- SE biased upward, power loss (Kahan-Morris 2012) |\n\n## Anticipated Reviewer Pushback\n\n| Pushback | Response |\n|----------|----------|\n| \"Why not Fisher's exact?\" | Cite Lydersen-Fagerland-Laake 2009; Boschloo is uniformly more powerful at same alpha. Provide Fisher p in appendix for direct comparison. |\n| \"Why no continuity correction?\" | D'Agostino-Chase-Belanger 1988 -- Yates' inflates Type-II by ~10%. The correct fix for sparse 2x2 is Boschloo's exact, not Yates'. |\n| \"Are these ORs collapsible?\" | OR is non-collapsible (see clinical-biostatistics\u002Feffect-measures); marginal and conditional ORs differ even without confounding. Cite Permutt 2020. |\n| \"Why mid-p McNemar over exact conditional?\" | Fagerland-Lydersen-Laake 2013 simulations show exact conditional is over-conservative; mid-p and asymptotic maintain nominal Type-I with better power. |\n| \"Adjustment for stratification factors?\" | Per ICH E9 and FDA 2023 covariate adjustment guidance, strata from randomisation must appear in analysis. CMH or logistic with strata as covariates. |\n| \"What is the estimand?\" | Per ICH E9(R1), categorical-test analyses target a specific estimand (treatment policy is implicit if all randomised analysed). Articulate explicitly. |\n\n## References\n\n- Boschloo RD. 1970. Raised conditional level of significance for the 2x2 table when testing the equality of two probabilities. *Stat Neerl* 24:1.\n- Brown LD, Cai TT, DasGupta A. 2001. Interval estimation for a binomial proportion. *Stat Sci* 16:101-117.\n- Cochran WG. 1954. Some methods for strengthening the common chi-squared tests. *Biometrics* 10:417-451.\n- D'Agostino RB, Chase W, Belanger A. 1988. The appropriateness of some common procedures for testing the equality of two independent binomial populations. *Am Stat* 42:198-202.\n- Fagerland MW, Lydersen S, Laake P. 2013. The McNemar test for binary matched-pairs data: mid-p and asymptotic are better than exact conditional. *BMC Med Res Methodol* 13:91.\n- FDA. 2022. Multiple Endpoints in Clinical Trials -- Guidance for Industry. Federal Register Oct 2022.\n- Kahan BC, Morris TP. 2012. Improper analysis of trials randomised using stratified blocks or minimisation. *Stat Med* 31:328-340.\n- Liddell FDK. 1983. Simplified exact analysis of case-referent studies; matched pairs; dichotomous exposure. *J Epidemiol Community Health* 37:82-84.\n- Lydersen S, Fagerland MW, Laake P. 2009. Recommended tests for association in 2x2 tables. *Stat Med* 28:1159-1175.\n- Mehta CR, Senchaudhuri P. 2003. Conditional vs unconditional exact tests for comparing two binomials. (Cytel technical report; widely cited in subsequent literature.)\n- Miettinen O, Nurminen M. 1985. Comparative analysis of two rates. *Stat Med* 4:213-226.\n- Newcombe RG. 1998a. Interval estimation for the difference between independent proportions: comparison of eleven methods. *Stat Med* 17:873-890.\n- Newcombe RG. 1998b. Improved confidence intervals for the difference between binomial proportions based on paired data. *Stat Med* 17:2635-2650.\n- Permutt T. 2020. Do covariates change the estimand? *Stat Biopharm Res* 12:45-53.\n- Suissa S, Shuster JJ. 1991. The 2x2 matched-pairs trial: exact unconditional design and analysis. *Biometrics* 47:361-372.\n\n## Related Skills\n\n- clinical-biostatistics\u002Feffect-measures - Detailed OR\u002FRR\u002FRD with modern CI methods (Wilson, Newcombe, Miettinen-Nurminen)\n- clinical-biostatistics\u002Flogistic-regression - Regression alternative with covariate adjustment; modified Poisson for RR\n- clinical-biostatistics\u002Fsubgroup-analysis - Stratified analysis with interaction terms and HTE methods\n- clinical-biostatistics\u002Fmultiplicity-graphical - Bretz-Maurer graphical procedures for confirmatory multiplicity\n- clinical-biostatistics\u002Ftrial-reporting - CONSORT 2025 and ICH E9(R1) reporting of categorical analyses\n- experimental-design\u002Fmultiple-testing - General multiple testing correction methods\n",{"name":5,"source":24,"license":15,"tool_type":25,"description":7,"imported_at":26,"source_path":27,"primary_tool":28,"source_repository":29},"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills","python","2026-09-20","clinical-biostatistics\u002Fcategorical-tests\u002FSKILL.md","scipy","GPTomics\u002FbioSkills","main","2d1750717747097b602acf30bd09a7cbd4b4c6ea","awesome_skills\u002Fbiology\u002Fbio-clinical-biostatistics-categorical-tests","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous","2026-11-09 11:45:36",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-clinical-biostatistics-categorical-tests",{"tool":42,"command":43},"bunx","bunx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-clinical-biostatistics-categorical-tests",{"tool":45,"command":46},"pnpm","pnpm dlx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-clinical-biostatistics-categorical-tests","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-clinical-biostatistics-categorical-tests\u002FSKILL.md",true,[50,56],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"examples\u002Fcategorical_tests_clinical.py","SCRIPT","脚本",3476,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-clinical-biostatistics-categorical-tests\u002Fexamples\u002Fcategorical_tests_clinical.py",{"path":57,"resourceType":58,"resourceTypeDesc":59,"sizeBytes":60,"sourceHtmlUrl":61},"usage-guide.md","REFERENCE","参考文档",6012,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-clinical-biostatistics-categorical-tests\u002Fusage-guide.md",[63,71,78,85,92,99],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":70},"01M7FFFZPC2025JQQHPHDX154J","dei-assessment","Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-assessment\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":70},"01M7FFFWN8H4WA7A6Y398QKB6J","dei-action-plan","Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-action-plan\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":70},"01M7FFFSHTM0QZRVZ2NRJTJ0PY","culture-fit-assessment","Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fculture-fit-assessment\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":70},"01M7FFFMA12RKEQA38KHJSXXPS","cowork-to-code-bridge","Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcowork-to-code-bridge\u002FSKILL.md",[],[],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":70},"01M7FFFH1F6M8YRGW5V487GH1K","counter-offer-response","Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcounter-offer-response\u002FSKILL.md",[],[],{"skillNo":100,"name":101,"nameZh":6,"description":102,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":70},"01M7FFFDGEHV8Y7J9N40HZXW52","continuous-feedback-system","Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcontinuous-feedback-system\u002FSKILL.md",[],[]]