← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / OpenAI4S / skills / bioskills / bio-clinical-biostatistics-categorical-tests / references / usage-guide.md

Categorical Association Tests - Usage Guide

Overview

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).

Prerequisites

pip install scipy statsmodels pingouin pandas numpy

R for production NI/regulatory work with Miettinen-Nurminen stratified CIs:

install.packages(c('ratesci', 'exact2x2', 'Exact'))

Quick Start

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"

Example Prompts

Independent 2x2 testing

"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."

Stratified analysis

"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."

McNemar's paired binary

"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."

Calibrated CIs

"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."

Effect sizes and multiplicity

"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)."

What the Agent Will Do

  1. Inspect the contingency table; verify expected counts; decide chi-square vs Boschloo
  2. For stratified designs, include stratification factors via CMH or logistic regression
  3. For paired designs, choose asymptotic vs mid-p McNemar based on discordant pair count
  4. Compute appropriate CI (Wilson for single proportion; MN/Newcombe for differences/ratios)
  5. Compute effect sizes (phi, Cramer's V with bias correction)
  6. Apply multiplicity correction (Holm/Bonferroni for confirmatory; BH-FDR for exploratory) with explicit method specification

Tips