Using the marginal survival causal curves from calculate_statistics to simulate the potential outcomes.

simulate_counterfactuals(bh, surv_cond, M, cpp, loadcpp = TRUE)

Arguments

bh

A data frame from the basehaz function. This is the baseline hazard for the coxph model.

surv_cond

A vector containing the marginal causal survival curves from calculate_statistics. Each number is the probability of the surviving the time window (t1,t2],... conditional on surviving the prior corresponding window.

M

Numeric. The number of simulated counterfactual patients. Suggest to set above 1,000,000 to get robust estimation but it is time comsuming,

cpp

Bool. True for using C++ optimization. False for not using C++ optimization. This requires cpp package installed.

loadcpp

Bool. True for loading C++ optimization functions. Default is TRUE. This is only used when cpp = TRUE.

Value

A list containing the simulated event time and simulated status indicator.

Details

The potential outcomes were simulated by using a Bernoulli distribution from rbinom() and marginal survival causal curves. If M is quite large, we suggest to use C++ optimization to speed up the calculation.

References

Daniel R, Zhang J, Farewell D. Making apples from oranges: Comparing noncollapsible effect estimators and their standard errors after adjustment for different covariate sets. Biom J. 2021;63(3):528-557. doi:10.1002/bimj.201900297

Examples

library(survival)
data("oak")

cox_event <- coxph(Surv(OS, os.status) ~ trt + btmb + pdl1, data = oak)
#
cox_censor <- coxph(Surv(OS, 1 - os.status) ~ trt + btmb + pdl1, data = oak)

bh <- basehaz(cox_event, centered = FALSE)
s_condi <- calculate_statistics(model = cox_event, trt = "trt")
sim_out_1d <- simulate_counterfactuals(
bh = bh, surv_cond = s_condi$surv_cond0, cpp = FALSE, M = 1000)