Tests associations between categorical variables in clinical trial data with calibration to design (independent vs paired), sample size (asymptotic vs exact), and regulatory expectation. Covers Pearson chi-square (no continuity correction), Boschloo's exact (uniformly more powerful than Fisher per Mehta-Senchaudhuri 2003), CMH/Breslow-Day stratified analysis with Simpson's-paradox detection, modern McNemar variants (mid-p per Fagerland 2013), and calibrated CIs (Wilson, Newcombe, Miettinen-Nurminen).
pip install scipy statsmodels pingouin pandas numpy
R for production NI/regulatory work with Miettinen-Nurminen stratified CIs:
install.packages(c('ratesci', 'exact2x2', 'Exact'))
Tell your AI agent what you want to do: - "Test treatment-outcome association using Pearson chi-square (no Yates) with expected count check" - "Boschloo's exact test for small 2x2 -- more powerful than Fisher's" - "CMH stratified analysis with Breslow-Day homogeneity + stratum-specific forest plot to detect Simpson's paradox" - "Mid-p McNemar's for paired binary endpoint (Fagerland 2013 recommended over exact conditional)" - "Miettinen-Nurminen score CI for RD as the regulatory-standard alternative to Wald"
"I have a 2x2 table with 100 patients per arm. Expected counts all > 5. Run Pearson chi-square with correction=False and report the effect size (phi/Cramer's V)."
"My 2x2 has 12 patients per arm. Run Boschloo's exact test in scipy (more powerful than Fisher's; cite Mehta-Senchaudhuri 2003). Compare to Fisher's exact for transparency."
"I have 8 stratification sites in my RCT. Run CMH for the pooled OR with Breslow-Day homogeneity. Plot stratum-specific ORs in a forest plot to detect Simpson's paradox."
"If Breslow-Day is non-significant, that doesn't mean homogeneity (low power). Add an LR interaction test from logistic regression as a second check."
"Pre/post treatment binary outcome on n=80 subjects. Discordant pairs = 18. Use asymptotic McNemar without continuity correction per Fagerland-Lydersen-Laake 2013."
"Matched-pair NI trial for diagnostic device. Use Suissa-Shuster exact unconditional (R exact2x2) for 20-40% smaller sample size than exact conditional."
"Compute Wilson score CI for a single proportion (60/100 responders) -- better coverage than Wald, especially for extreme p."
"Newcombe-Wilson hybrid CI for the difference of proportions (45/60 vs 30/60) -- preferred over Wald."
"Miettinen-Nurminen score CI for RD in my stratified NI margin assessment -- the regulatory standard."
"Compute Cramer's V with bias correction via pingouin's chi2_independence."
"Post-hoc pairwise comparisons across 4 outcome categories with Holm correction; explicit method='holm' (NOT default 'hs' = Holm-Sidak)."
scipy.stats.fisher_exact since 1.10 returns SAMPLE (unconditional) OR, not conditional MLE. For R-matching conditional MLE, use scipy.stats.contingency.odds_ratio(table, kind='conditional').statsmodels.stats.multitest.multipletests default method='hs' is Holm-Sidak, NOT Holm or Bonferroni. Always specify explicitly.pd.crosstab orders columns alphabetically. If outcome is 0/1, the OR will be reciprocal. Reorder: cross[[1, 0]].