Skip to main content

iptw-survival

iptw-survival is a Python package for performing weight-based causal survival analysis. It includes functionality for estimating inverse probability of treatment weights (IPTW) and overlap weights (OW), visualizing propensity score overlap, assessing covariate balance, and computing bootstrapped, non-parametric survival metrics derived from Kaplan–Meier estimators.

Features

  • Calculate IPTW and overlap weights using logistic regression
  • Visualize propensity score distributions for treatment groups
  • Assess covariate balance using standardized mean differences, including Love plots
  • Generate weighted Kaplan-Meier survival summaries with point estimates and bootstrapped 95% CIs using parallel processing
  • Compute non-parametric survival metrics (no Cox modeling), including:
    • Probability of survival at fixed timepoints
    • Restricted mean survival time (RMST)
    • Median survival

Installation

pip install iptw-survival

Quick Start

from iptw_survival import IPTWSurvivalEstimator

# Instantiate and fit model
estimator = IPTWSurvivalEstimator()
iptw_df = estimator.fit_transform(df,
                                  treatment_col = 'treatment',
                                  cat_var = ['stage', 'ecog'],
                                  cont_var = ['age', 'creatinine'],
                                  binary_var = ['surgery', 'medicaid'],
                                  lr_kwargs = {
                                    'class_weight': 'balanced',
                                    'random_state': 42},
                                  clip_bounds = (0.01, 0.99),
                                  stabilized = True)

# Plot propensity score distribution
estimator.propensity_score_plot()

# Assess covariate balance
smd_df, fig = estimator.standardized_mean_differences(return_fig = True)

# Kaplan-Meier plot with bootstrapped CIs
km_df = estimator.km_confidence_interval(df = iptw_df
                                         event_col='event', 
                                         duration_col = 'duration',
                                         n_bootstrap = 500
                                         random_state = 42,
                                         n_jobs = -1)

# Use km_df to plot survival curves 
import matplotlib.pyplot as plt

plt.plot(km_df['time'], km_df['treatment_estimate'], label = 'Treatment')
plt.fill_between(km_df['time'], km_df['treatment_lower_ci'], km_df['treatment_upper_ci'], alpha = 0.1)
plt.xlabel('Time (months)')
plt.ylabel('Survival probability')
plt.legend()
plt.title('IPTW-adjusted Kaplan-Meier Curve')
plt.show()

# Calculate survival metrics
results = estimator.survival_metrics(df = iptw_df
                                     event_col='event', 
                                     duration_col = 'duration',
                                     psurv_time_points = [24, 36],
                                     rmst_time_points = [12],
                                     median_time = True
                                     n_bootstrap = 500
                                     random_state = 42,
                                     n_jobs = -1)

Example Tutorial

A full walkthrough using the Flatiron Health advanced urothelial cancer dataset is available in tutorial/tutorial.ipynb.

Requirements

Built and tested in python 3.13

Core dependencies:

  • pandas
  • numpy
  • scikit-learn
  • lifelines
  • matplotlib

Contact

Contributions and feedback are welcome. Contact: xavierorcutt@gmail.com

Metadata

Release files for iptw-survival 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iptw-survival 0.1.9
File Size Uploaded Provenance
iptw_survival-0.1.9.tar.gz 16.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for iptw-survival 0.1.9
File Interpreter ABI Platform
iptw_survival-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 32.6 kB

Release files / iptw_survival-0.1.9.tar.gz

Download URL iptw_survival-0.1.9.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b96e502a4e104824ebdc461d65abc72641c8d543a3185b64115e635091a800fd
BLAKE2b-256 checksum
How to use checksums
df899486e9472ff8932820ac6dc6d8aa67a6ccf1d3789ff0fa88bf6452320e95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / iptw_survival-0.1.9-py3-none-any.whl

Download URL iptw_survival-0.1.9-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b66b9a7a81e110485ce24325bf84448365faf9423cea55a27a508a6c3f5f567
BLAKE2b-256 checksum
How to use checksums
51b1122186e60292502cf7923e0204830d33883aad1f86f54109be5eea42843b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Security for iptw-survival 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page