Learn R Programming

PSsurvival

Propensity score methods for survival analysis.

Overview

PSsurvival implements propensity score methods for observational studies with time-to-event outcomes. The package provides three main functions:

Counterfactual survival functions (surveff): Estimates group-specific survival curves and survival differences over time, adjusting for confounding via propensity score weighting and for censoring via inverse probability of censoring weighting.

Marginal hazard ratios (marCoxph): Fits weighted marginal Cox proportional hazards models to estimate marginal hazard ratios between treatment groups.

Weighted Kaplan-Meier curves (weightedKM): Estimates weighted Kaplan-Meier (KM) and cumulative risk (CR) curves with propensity score weights.

All functions support:

  • Binary and multiple (>2) treatment groups
  • Weighting schemes: inverse probability weighting (IPW), overlap weighting (OW), and average treatment effect on the treated (ATT)
  • Propensity score trimming: symmetric trimming (Crump extension for multiple treatments)
  • Variance estimation: analytical M-estimation (binary treatment with Weibull censoring) or bootstrap

Installation

# Install from GitHub (requires devtools)
devtools::install_github("cxinyang/PSsurvival")

# Install from R CRAN
install.package("PSsurvival")

Usage

library(PSsurvival)

# Counterfactual survival curves with overlap weighting
result <- surveff(
  data = mydata,
  ps_formula = treatment ~ X1 + X2 + X3,
  censoring_formula = Surv(time, event) ~ X1 + X2,
  weight_method = "OW",
  censoring_method = "weibull"
)

summary(result)
plot(result)

# Marginal hazard ratio with IPW
hr_result <- marCoxph(
  data = mydata,
  ps_formula = treatment ~ X1 + X2 + X3,
  time_var = "time",
  event_var = "event",
  reference_level = "control",
  weight_method = "IPW"
)

summary(hr_result)

# Weighted Kaplan-Meier with risk table
km_result <- weightedKM(
  data = mydata,
  treatment_var = "treatment",
  ps_formula = treatment ~ X1 + X2 + X3,
  time_var = "time",
  event_var = "event",
  weight_method = "OW"
)

plot(km_result, risk_table = TRUE)
summary(km_result)

Details

Propensity score estimation: Uses logistic regression for binary treatments and multinomial logistic regression (via nnet::multinom) for multiple treatments.

Censoring adjustment (surveff only): Models the censoring distribution within each treatment group using either Weibull accelerated failure time models or Cox proportional hazards models.

Variance estimation: For binary treatments with Weibull censoring, analytical variance based on M-estimation theory is available. Bootstrap variance (resampling the full estimation pipeline) is supported for all configurations.

References

Li, F., Morgan, K. L., & Zaslavsky, A. M. (2018). Balancing covariates via propensity score weighting. Journal of the American Statistical Association, 113(521), 390-400.

Li, F., & Li, F. (2019). Propensity score weighting for causal inference with multiple treatments. The Annals of Applied Statistics, 13(4), 2389-2415.

Cheng, C., Li, F., Thomas, L. E., & Li, F. (2022). Addressing extreme propensity scores in estimating counterfactual survival functions via the overlap weights. American Journal of Epidemiology, 191(6), 1140-1151.

Copy Link

Version

Install

install.packages('PSsurvival')

Version

0.2.0

License

GPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Chengxin Yang

Last Published

January 10th, 2026

Functions in PSsurvival (0.2.0)

summary.surveff

Summary Method for surveff Objects
summary.marCoxph

Summary Method for marCoxph Objects
surveff_weibull

Wrapper for Weibull Survival Effect Estimation with Variance
surveff

Survival Effect Estimation with Propensity Score Weighting
summary.weightedKM

Summary Method for Weighted Kaplan-Meier Estimates
surv_weibull

Estimate Counterfactual Survival Functions Using Weibull Censoring Scores
trim_weights_asymmetric

Asymmetric Propensity Score Trimming (Sturmer Extension)
surveff_cox

Wrapper for Cox Survival Effect Estimation with Variance
surv_cox

Survival Effect Estimation with Cox Censoring Scores
trim_weights_symmetric

Symmetric Propensity Score Trimming (Crump Extension)
validate_data_variables

Validate Data Variables
var_surv_weibull_analytical

Compute Analytical M-Estimation Variance for Binary Treatment Survival Functions
validate_PSsurvdiff_inputs

Validate All Inputs for PSsurvdiff
var_surv_weibull_bootstrap

Bootstrap Variance Estimation for Weibull Survival Functions
var_marginalcox_bootstrap

Bootstrap Variance Estimation for Marginal Cox Model
validate_method_arguments

Validate Method Arguments
validate_censor_formula

Validate Censoring Formula
var_surv_cox_bootstrap

Bootstrap Variance Estimation for Cox Survival Functions
weightedKM

Weighted Kaplan-Meier Estimation with Propensity Score Weights
validate_ps_formula

Data Validation Functions for PSsurvival Package
estimate_censoring_score_weibull

Censoring Score Estimation
check_variables_exist

Check if Variables Exist in Data
estimate_weights

Estimate Propensity Score Weights
check_data_structure

Check Data Structure
estimate_ps

Propensity Score Estimation for PSsurvival Package
estimate_censoring_score_cox

Estimate Censoring Scores Using Cox Regression
estimate_weighted_km

Weighted Kaplan-Meier Estimation with Classic Greenwood Variance
calculate_ipw_weights

Propensity Score Weighting for PSsurvival Package
compute_etau

Survival Effect Estimation with Weibull Censoring Scores
calculate_overlap_weights

Calculate Overlap Weights
marCoxph

Marginal Cox Model with Propensity Score Weighting
print.weightedKM

Print Method for Weighted Kaplan-Meier Estimates
print.marCoxph

Print Method for marCoxph Objects
print.surveff

Print Method for surveff Objects
plot.surveff

Plot Method for surveff Objects
plot.weightedKM

Plot Method for Weighted Kaplan-Meier Estimates
generate_boot_indices

Generate Bootstrap Sample Indices
fit_marginal_cox

Marginal Cox Model Estimation with Propensity Score Weighting
simdata_bin

Simulated Survival Data with Binary Treatment
simdata_multi

Simulated Survival Data with Multiple Treatments