Performs time-to-event analysis for clinical trials with calibration to whether proportional hazards holds, whether competing events exist, whether censoring is informative, and which ICH E9(R1) estimand the trial targets. Covers Cox PH with Therneau-Grambsch diagnostics, restricted mean survival time (RMST) as a hazard-free alternative, Fine-Gray vs cause-specific Cox for competing risks, MaxCombo and weighted log-rank for non-proportional hazards, recurrent events (Andersen-Gill, PWP, WLW), and interval-censored data.
pip install lifelines scikit-survival statsmodels pandas numpy matplotlib
R is strongly recommended for production survival analysis:
install.packages(c('survival', 'survRM2', 'cmprsk', 'riskRegression', 'mstate',
'flexsurv', 'icenReg', 'rpsftm'))
Tell your AI agent what you want to do: - "Run a Cox proportional hazards regression for OS in my oncology trial; check the PH assumption" - "Estimate the restricted mean survival time difference at 36 months as the primary endpoint because hazards cross" - "I have a competing risk: cardiac death and non-cardiac death. Fit cause-specific Cox for both and report the cumulative incidence function" - "Apply MaxCombo for a delayed-effect immunotherapy trial with pre-specified directional constraint" - "Convert ADTTE CNSR=0/1/2 to the standard event indicator for lifelines"
"Fit a Cox model for OS in my trial with treatment, age, and ECOG performance status. Run cox.zph and report the global PH test. Stratify on randomisation strata (region)."
"Compute the hazard ratio for treatment vs placebo with 95% CI. If PH is violated, switch to RMST."
"PH is clearly violated in my immunotherapy trial. Compute the RMST difference at 36 months as the primary endpoint with delta-method CI. Pre-specified tau is 36 from the SAP."
"Compare the time-to-RMST tradeoff at tau=12, 24, 36, and 60 months for sensitivity."
"I have a cardiovascular outcome trial with cardiac death (event of interest) and non-cardiac death (competing). Fit cause-specific Cox for cardiac death AND for non-cardiac death. Report both cause-specific HRs and the cumulative incidence functions via Aalen-Johansen."
"My oncology trial has progression and death. Compute the CIF for both via Aalen-Johansen and report PFS event-free survival treating either as event."
"Run MaxCombo with G(0,0), G(0,1), G(1,0), G(1,1) family for the late-effect immunotherapy. Pre-specified directional constraint: require positive z-statistic at the late-emphasis G(0,1) weight before claiming superiority."
"Fit a Royston-Parmar flexible parametric model with 5-knot cubic spline for log cumulative hazard. Report HR(t) curves over follow-up."
"Subjects have multiple hospitalisations during follow-up. Fit Andersen-Gill with robust SE clustered on USUBJID. Report rate ratio."
"Hospitalisations may differ by event order (first vs recurrent). Fit PWP gap-time with stratum-specific baseline hazards."
"PFS scans were every 12 weeks but the actual progression date is unknown. Fit interval-censored Cox via icenReg::ic_par to avoid the midpoint imputation bias."
"Load my ADTTE.csv with CNSR per CDISC convention (0=event, 1+=censoring reasons). Convert to event/time for lifelines and fit Cox."
strata() in Cox, or include as covariates.