Initial release : modern survival analysis for Python which is Narwhals-native, R-validated, and beautifully visualized.
Highlights
Greenwood brings production-ready survival analysis to the Python data ecosystem. It works with whatever dataframe library you use (Pandas, Polars, PyArrow, or any Narwhals-compatible frame), every statistic is validated to tolerance against R's survival package, and interactive publication-quality plots come out of the box. From a single Kaplan-Meier curve to competing-risks regression and penalized Cox models, everything lives under a unified API.
Core Statistical Methods
Survresponse object — Represents survival data in right-, left-, and interval-censored form, counting-process form, left truncation, case weights, and multi-state endpoints, with built-in validation.- Kaplan-Meier estimation (
KaplanMeier) — Survival curves with Greenwood variance, multiple confidence interval types, median/quantile survival, restricted mean survival time (RMST), and step-function predictions at arbitrary times. - Nelson-Aalen estimator (
NelsonAalen) — Cumulative hazard curves with the same tidy output conventions asKaplanMeier. - Log-rank tests (
logrank_test(),pairwise_logrank_test()) — Standard log-rank and the full G-rho (Fleming-Harrington) family for two or more groups, plus pairwise comparisons with p-value adjustment. - Cox proportional hazards (
CoxPH) — Hazard-ratio regression with stratification, robust/sandwich variance, cluster-robust standard errors, baseline hazard prediction, and full model diagnostics (Schoenfeld residuals, proportional-hazards test viacox_zph(), concordance index). - Penalized Cox regression (
CoxNet) — Lasso, ridge, and elastic-net penalized Cox models for high-dimensional covariates. - Accelerated failure time models (
AFT) — Parametric survival regression with Weibull, exponential, log-normal, and log-logistic distributions, validated against R'ssurvreg. - Flexible parametric models (
RoystonParmar) — Royston-Parmar spline-based survival models. - Competing risks (
AalenJohansen,FineGray) — Cumulative incidence functions via Aalen-Johansen, subdistribution hazard regression via Fine-Gray, and multi-state transition probabilities (MultiState). - Event table (
EventTable,event_table()) — Raw risk-set and event counts at each unique time point.
Model Performance & Validation
- Concordance index — Harrell's C-statistic for evaluating discriminative ability.
- Brier score & integrated Brier score — IPCW-weighted calibration metrics at arbitrary time points.
- Calibration — Graphical and numeric calibration assessment.
- Cross-validation (
cross_validate()) — K-fold cross-validation pipeline for any Greenwood model. - Power analysis (
logrank_power(),logrank_sample_size(),logrank_n_events()) — Prospective sample size and power calculations for log-rank tests.
Visualization
plot_survival()— Interactive survival curves with confidence bands, censoring tick marks, and optional aligned at-risk tables; choose between Altair and plotnine backends.risk_table()— Standalone aligned at-risk table, composable with any plot.
Tidy & Reproducible Output
- Tidy summaries (
tidy(),glance(),augment()) — Broom-compatible model summaries that return tidy DataFrames with consistent column names across all estimators. - Built-in datasets —
lung,veteran,ovarian,pbc,colon,mgus2, and more, loadable in any supported backend viagw.load_dataset(name, backend=...). - R-parity test harness — Every statistic ships with fixtures validated against R's
survivalpackage.
Dataframe Compatibility
Greenwood is built on Narwhals, so all methods accept and return Pandas DataFrames, Polars DataFrames, PyArrow Tables, or any other Narwhals-compatible frame. Use the format= argument on output methods to control which type of table you get back.
Requirements
- Python >= 3.10
- Core dependencies:
narwhals>=2.0,numpy>=1.24,scipy>=1.11