tssim: Simulate Data for Treatment Switching

View source: R/RcppExports.R

tssimR Documentation

Simulate Data for Treatment Switching

Description

Simulates data for studies involving treatment switching, incorporating time-dependent confounding. The generated data can be used to evaluate methods for handling treatment switching in survival analysis.

Usage

tssim(
  tdxo = 0L,
  coxo = 1L,
  p_R = 0.5,
  p_X_1 = NA_real_,
  p_X_0 = NA_real_,
  rate_T = NA_real_,
  beta1 = NA_real_,
  beta2 = NA_real_,
  gamma0 = NA_real_,
  gamma1 = NA_real_,
  gamma2 = NA_real_,
  gamma3 = NA_real_,
  gamma4 = NA_real_,
  zeta0 = NA_real_,
  zeta1 = NA_real_,
  zeta2 = NA_real_,
  zeta3 = NA_real_,
  alpha0 = NA_real_,
  alpha1 = NA_real_,
  alpha2 = NA_real_,
  theta1_1 = NA_real_,
  theta1_0 = NA_real_,
  theta2 = NA_real_,
  rate_C = NA_real_,
  followup = NA_integer_,
  days = NA_integer_,
  n = NA_integer_,
  NSim = 1000L,
  seed = NA_integer_
)

Arguments

tdxo

Logical indicator for timing of treatment switching:

  • 1: Treatment switching can occur at or after disease progression.

  • 0: Treatment switching is restricted to the time of disease progression.

coxo

Logical indicator for arm-specific treatment switching:

  • 1: Treatment switching occurs only in the control arm.

  • 0: Treatment switching is allowed in both arms.

p_R

Probability of randomization to the experimental arm.

p_X_1

Probability of poor baseline prognosis in the experimental arm.

p_X_0

Probability of poor baseline prognosis in the control arm.

rate_T

Baseline hazard rate for time to death.

beta1

Log hazard ratio for randomized treatment (R).

beta2

Log hazard ratio for baseline covariate (X).

gamma0

Intercept for the time-dependent covariate model (L).

gamma1

Coefficient for lagged treatment switching (Alag) in the L model.

gamma2

Coefficient for lagged L in the L model.

gamma3

Coefficient for baseline covariate (X) in the L model.

gamma4

Coefficient for randomized treatment (R) in the L model.

zeta0

Intercept for the disease progression model (Z).

zeta1

Coefficient for L in the Z model.

zeta2

Coefficient for baseline covariate (X) in the Z model.

zeta3

Coefficient for randomized treatment (R) in the Z model.

alpha0

Intercept for the treatment switching model (A).

alpha1

Coefficient for L in the A model.

alpha2

Coefficient for baseline covariate (X) in the A model.

theta1_1

Negative log time ratio for A (experimental arm).

theta1_0

Negative log time ratio for A (control arm).

theta2

Negative log time ratio for L.

rate_C

Hazard rate for random (dropout) censoring.

followup

Number of treatment cycles per subject.

days

Number of days in each treatment cycle.

n

Number of subjects per simulation.

NSim

Number of simulated datasets.

seed

Random seed for reproducibility.

Value

A list of data frames, each containing simulated longitudinal and event history data with the following variables:

  • id: Subject identifier.

  • trtrand: Randomized treatment assignment (0 = control, 1 = experimental)

  • bprog: Baseline prognosis (0 = good, 1 = poor).

  • tpoint: Treatment cycle index.

  • tstart: Start day of the treatment cycle.

  • tstop: End day of the treatment cycle.

  • L: Time-dependent covariate predicting survival and switching; affected by treatment switching.

  • Llag: Lagged value of L.

  • Z: Disease progression status at tstop.

  • A: Treatment switching status at tstop.

  • Alag: Lagged value of A.

  • Y: Death indicator at tstop.

  • timeOS: Observed time to death or censoring.

  • died: Indicator of death by end of follow-up.

  • progressed: Indicator of disease progression by end of follow-up.

  • timePD: Observed time to progression or censoring.

  • xo: Indicator for whether treatment switching occurred.

  • xotime: Time of treatment switching (if applicable).

  • censor_time: Administrative censoring time.

Author(s)

Kaifeng Lu, kaifenglu@gmail.com

References

Jessica G. Young, and Eric J. Tchetgen Tchetgen. Simulation from a known Cox MSM using standard parametric models for the g-formula. Statistics in Medicine. 2014;33(6):1001-1014.

NR Latimer, IR White, K Tilling, and U Siebert. Improved two-stage estimation to adjust for treatment switching in randomised trials: g-estimation to address time-dependent confounding. Statistical Methods in Medical Research. 2020;29(10):2900-2918.

Jing Xu, Guohui Liu, and Bingxia Wang. Bias and type I error control in correcting treatment effect for treatment switching using marginal structural models in Phse III oncology trials. Journal of Biopharmaceutical Statistics. 2022;32(6):897-914.

Examples


simulated.data <- tssim(
  tdxo = 0, coxo = 0, p_R = 0.5, p_X_1 = 0.3, p_X_0 = 0.3, 
  rate_T = 0.002, beta1 = -0.5, beta2 = 0.3, 
  gamma0 = 0.3, gamma1 = -0.9, gamma2 = 0.7, gamma3 = 1.1, gamma4 = -0.8,
  zeta0 = -3.5, zeta1 = 0.5, zeta2 = 0.2, zeta3 = -0.4, 
  alpha0 = 0.5, alpha1 = 0.5, alpha2 = 0.4, 
  theta1_1 = -0.4, theta1_0 = -0.4, theta2 = 0.2,
  rate_C = 0.0000855, followup = 20, days = 30,
  n = 500, NSim = 100, seed = 314159)


trtswitch documentation built on June 8, 2025, 1:45 p.m.