greenwood greenwood
  • User Guide
  • Reference
  • Changelog

Skills

A skill is a package of structured files that teaches an AI coding agent how to work with a specific tool or framework. The skill below was generated by Great Docs from this project’s documentation. Install it in your agent and it will be able to run commands, edit configuration, write content, and troubleshoot problems without step-by-step guidance from you.

Any agent — install with npx:

npx skills add https://rich-iannone.github.io/greenwood/

Codex / OpenCode

Tell the agent:
Fetch the skill file at https://rich-iannone.github.io/greenwood/skill.md and follow the instructions.

Manual — download the skill file:

curl -O https://rich-iannone.github.io/greenwood/skill.md

Or browse the SKILL.md file.

SKILL.md

---
name: greenwood
description: >
  Modern survival analysis for Python: Narwhals-native, R-validated, beautifully visualized. Use when writing Python code that uses the greenwood package.
license: MIT
compatibility: Requires Python >=3.10.
---

# greenwood

Modern survival analysis for Python: Narwhals-native, R-validated, beautifully visualized.

## Installation

```bash
pip install greenwood
```

## API overview

### The response

The Surv object, the spine of every analysis.

- `Surv`: A validated time-to-event response for survival analysis
- `CensoringType`: The censoring mechanism of a `Surv` response

### Non-parametric estimators

Kaplan-Meier survival, Nelson-Aalen cumulative hazard, and Turnbull's NPMLE for interval-censored data.

- `KaplanMeier`: Kaplan-Meier product-limit estimator of the survival function
- `NelsonAalen`: Nelson-Aalen estimator of the cumulative hazard
- `Turnbull`: Turnbull's self-consistent NPMLE for interval-censored survival data

### Univariate parametric models

Standalone parametric distributions for data exploration and model selection.

- `Parametric`: Univariate parametric survival distribution
- `compare_distributions`: Fit multiple parametric distributions and return an AIC/BIC comparison table

### Regression

Cox proportional hazards, parametric AFT models, rank-based Buckley-James regression, and time-varying covariate utilities.

- `split_episodes`: Convert repeated-measurement data into counting-process (episode-split) format
- `CoxPH`: Cox proportional hazards model
- `CoxNetCVResult`: Result of cross-validated penalizer selection for `CoxNet`
- `cv_coxnet`: Select the `CoxNet` penalizer by k-fold cross-validation
- `CoxNet`: Elastic-net penalized Cox proportional hazards model
- `ZPHResult`: Proportional-hazards test results (Grambsch-Therneau)
- `ZPHWindowResult`: Test results for a single time window within a windowed proportional-hazards test
- `SmoothHRResult`: Smooth non-linear hazard ratio curve for a continuous covariate
- `AFT`: Parametric accelerated failure time model
- `BuckleyJames`: Buckley-James rank-based accelerated failure time regression
- `PiecewiseExponential`: Piecewise exponential survival model
- `RoystonParmar`: Royston-Parmar flexible parametric survival model (hazard or odds scale)

### Machine learning

Tree-based ensemble survival models grown with the log-rank splitting rule, producing per-subject survival and cumulative-hazard functions.

- `SurvivalTree`: A survival decision tree grown with the log-rank splitting rule
- `RandomSurvivalForest`: A random survival forest: a bagged ensemble of log-rank survival trees
- `ExtraSurvivalTrees`: An extremely-randomized survival forest (extra survival trees)
- `GradientBoostingSurvivalAnalysis`: Gradient-boosted survival model minimizing the Cox partial-likelihood loss

### Competing risks & multi-state

Cumulative incidence, the Fine-Gray model, and multi-state transition probabilities.

- `AalenJohansen`: Aalen-Johansen estimator of cumulative incidence functions for competing risks
- `FineGray`: Fine-Gray subdistribution hazard model for a competing-risks endpoint
- `MultiState`: Aalen-Johansen estimator of multi-state transition and occupancy probabilities

### Group comparisons

The log-rank test, MaxCombo test for non-proportional hazards, trend tests for ordered groups, the G-rho (Fleming-Harrington) family, Gray's test for cumulative incidence, and restricted mean survival time (RMST) comparisons.

- `logrank_test`: Compare survival across groups using the weighted log-rank (G-rho) test
- `maxcombo_test`: MaxCombo test: maximum of multiple weighted log-rank Z-statistics
- `trend_test`: Test for linear trend across ordered groups using the log-rank test family
- `pairwise_logrank_test`: Pairwise log-rank tests for all group pairs with multiple-comparison correction
- `grays_test`: Compare cumulative incidence functions across groups using Gray's test
- `TestResult`: The outcome of a log-rank group comparison test
- `rmst_test`: Test for equality of RMST across two or more groups
- `rmst_diff`: Compute the RMST difference between two groups and return a tidy DataFrame
- `pairwise_rmst_test`: Pairwise RMST tests for all group pairs with multiple-comparison correction
- `RMSTResult`: Results of an RMST comparison test or difference calculation
- `logrank_n_events`: Number of events needed for the log-rank test to reach a target power
- `logrank_power`: Power of the log-rank test given the number of observed events
- `logrank_sample_size`: Total sample size needed for the log-rank test to reach a target power

### Resampling & bootstrap

Bootstrap confidence intervals and k-fold cross-validation for survival models.

- `bootstrap`: Bootstrap confidence interval for a Kaplan-Meier summary statistic
- `BootstrapResult`: Result of a bootstrap confidence interval computation
- `cross_validate`: Evaluate a survival model's out-of-sample performance using k-fold cross-validation

### Prediction performance

Concordance, IPCW Brier score, time-dependent AUC, and calibration.

- `concordance_index`: Harrell's concordance index: discrimination of risk scores against observed survival
- `concordance_index_ipcw`: IPCW concordance index (Uno et al., 2011) for right-censored survival data
- `brier_score`: IPCW (Graf) Brier score of predicted survival probabilities at specified times
- `integrated_brier_score`: Integrated (time-averaged) Brier score across multiple time points
- `time_dependent_auc`: IPCW (Uno) time-dependent AUC at specified times
- `integrated_auc`: Time-averaged IPCW AUC across multiple time points
- `calibration`: Assess calibration of predicted survival probabilities at a fixed time

### Visualization

Interactive survival curves, forest plots, and cumulative incidence visualizations with aligned numbers-at-risk tables.

- `plot_survival`: Plot Kaplan-Meier survival curve(s)
- `plot_predicted_survival`: Plot per-subject predicted survival or cumulative-hazard curves
- `plot_forest`: Forest plot of hazard ratios (or other contrasts) with confidence intervals
- `plot_cif`: Plot cumulative incidence functions from a fitted Aalen-Johansen estimator
- `plot_influence`: Diagnostic scatter plots for identifying influential observations in a Cox model
- `plot_smooth_hr`: Plot a smooth hazard ratio curve for a continuous covariate
- `risk_table`: Return the numbers-at-risk table as a Great Tables object

### Core kernel

The risk-set / event-table tabulation shared by KM, log-rank, and Cox.

- `EventTable`: Per-time risk-set tabulation (optionally within strata)
- `event_table`: Tabulate the event history: risk sets and events at each observed time

### Data access

Built-in datasets and dataset discovery helpers.

- `load_dataset`: Load a bundled dataset by name
- `available_datasets`: Return the names of all bundled datasets

### Tidy summaries

Broom-style model summaries and extension points.

- `tidy`: Return a standardised term-level DataFrame for a fitted model
- `glance`: Return a one-row model-summary DataFrame for a fitted model
- `augment`: Return an observation-level DataFrame for a fitted model

### Visualization helpers

Low-level plotting helpers exported at the top level.

- `get_risk_table_frame`: Return a tidy frame of the number at risk per stratum at each of `times`
- `theme_forest`: A minimal plotnine theme for forest plots

## Resources

- [Full documentation](https://rich-iannone.github.io/greenwood/)
- [llms.txt](llms.txt) — Indexed API reference for LLMs
- [llms-full.txt](llms-full.txt) — Comprehensive documentation for LLMs
- [Source code](https://github.com/rich-iannone/greenwood)

Developed by Richard Iannone.
Site created with Great Docs.