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

Logistic Regression - Usage Guide

Overview

Performs logistic regression for binary and ordinal clinical trial endpoints with explicit declaration of marginal vs conditional estimand per FDA 2023 Final Guidance "Adjusting for Covariates in Randomized Clinical Trials." Covers covariate adjustment, g-computation/standardisation for marginal effects, modified Poisson regression for direct RR estimation when prevalence > 10%, Brant test for proportional odds, Firth penalty for separation/rare events, and Hauck-Donner detection.

Prerequisites

pip install statsmodels scipy numpy pandas scikit-learn firthmodels

R is recommended for production marginal effects:

install.packages(c('marginaleffects', 'RobinCar', 'riskCommunicator', 'brant', 'VGAM', 'MASS'))

Quick Start

Tell your AI agent what you want to do: - "Logistic regression with treatment + covariates; report BOTH conditional OR and marginal RD via g-computation per FDA 2023" - "Modified Poisson with HC3 sandwich SE to estimate RR directly when prevalence > 10%" - "Brant test for proportional-odds assumption in ordinal model; partial PO model if violated" - "Firth penalised logistic regression with penalised LR test (NOT Wald) when separation detected" - "Detect Hauck-Donner pathology and switch to profile-likelihood CI"

Example Prompts

Standard adjusted analysis

"Fit a logistic regression for response from treatment, age, sex, baseline_severity. Use Placebo as the reference category explicitly (do NOT rely on alphabetical default which gives 'Active' as reference)."

"Extract conditional ORs for each predictor and the marginal RD via g-computation. Report HC3 sandwich SE for the marginal estimand per FDA 2023."

Marginal vs conditional (FDA 2023)

"Per FDA 2023 covariate adjustment guidance, my primary estimand is marginal RD. The model-fit OR is the CONDITIONAL log-OR (a different parameter). Compute marginal RD via g-computation in marginaleffects (R) or manual standardisation (Python)."

"Explain to my reviewer why the conditional OR and marginal RD differ -- cite Permutt 2020 non-collapsibility."

Common outcomes -- direct RR

"Outcome prevalence is 32%, so OR will substantially overstate RR. Switch to modified Poisson regression with cov_type='HC1' (Zou 2004) to estimate RR directly."

Ordinal outcomes

"Fit a proportional-odds cumulative-logit model for severity (mild/moderate/severe). Then run the Brant test (R brant::brant) to verify PO holds per predictor. If PO fails for one predictor, fit a partial PO model in VGAM."

Separation and Firth

"My binary outcome has only 3% events -- separation likely. Detect with firthmodels.detect_separation. Apply Firth penalty; use penalised LR test (firth.pvalues_lrt_) NOT Wald p-values for inference."

Hauck-Donner

"Small cell count; coefficient is large but Wald p > 0.05. Hauck-Donner suspected. Switch to profile-likelihood CI (R MASS::confint.glm); detect with VGAM::hdeff."

Stratified randomisation

"My trial used stratified randomisation by site and baseline severity. Include both as model covariates per Kahan-Morris 2012 -- ignoring is over-conservative (SE biased upward, power loss)."

What the Agent Will Do

  1. Verify the binary/ordinal outcome and explicitly set reference category for treatment
  2. Include pre-specified covariates from the SAP (including all randomisation strata)
  3. Fit logistic regression and extract conditional ORs with CIs
  4. Compute marginal RD via g-computation per FDA 2023 (HC3 sandwich SE)
  5. For prevalence > 10%, fit modified Poisson with sandwich SE for direct RR
  6. For ordinal outcomes, run Brant test for PO; fall back to partial PO or multinomial as needed
  7. Detect separation/rare events and apply Firth penalty with penalised LR inference
  8. Run model diagnostics: ROC-AUC, calibration plot (primary), Hosmer-Lemeshow (supplementary), pseudo R-squared

Tips