TwoSample.generate.sequential: Function to simulate two-sample composite endpoint data under...

View source: R/TwoSample.generate.sequential.R

TwoSample.generate.sequentialR Documentation

Function to simulate two-sample composite endpoint data under staggered entry.

Description

Simulate two-sample composite endpoints data with recurrent events and a terminal event under two time scales: event time t and calendar time s. A uniform recruitment period is assumed, and the function returns all observed data available at a specified calendar time. Recurrent event occurrences are generated from an underlying Poisson process with subject-specific Gamma frailty.

Usage

TwoSample.generate.sequential(
  lambda_0vec = c(1.15, 1.15),
  sizevec,
  beta.trt,
  calendar = 5,
  recruitment = 3,
  random.censor.rate,
  seed
)

Arguments

lambda_0vec

Numeric vector of length 2 giving the baseline recurrent event rate parameters for two arms, default is c(1.15, 1.15).

sizevec

Integer vector of size 2 giving the group sizes.

beta.trt

Numeric value giving the treatment effect coefficient applied to the treatment indicator (Z1) in the proportional mean model (arm 2 vs arm 1).

calendar

Calendar time of the end of the trial (in years), default is 5.

recruitment

Length of the recruitment period (in years), default is 3.

random.censor.rate

Rate parameter for independent random right censoring.

seed

Seed for reproducibility.

Value

A data frame in long format containing simulated composite endpoint data. Each subject may contributing multiple rows corresponding to recurrent events, a terminal event (death), or censoring. The data include:

  • group: Arm indicator (1 = control, 2= treatment).

  • id: Subject identifier (unique across both arms).

  • e: Enrollment time on the calendar scale.

  • event_time_cal: Cumulative event time on the calendar scale.

  • status: Event indicator with values 2=recurrent event, 1=death, and 0=censoring.

  • Z1, Z2: Simulated covariates, where Z1 is the treatment indicator (0 for arm 1, 1 for arm 2).

  • tau_star: Subject-specific stopping time, the last event observed in [0, tau_star] is classified as death.

  • death: Binary indicator for death.

  • recurrent: Binary indicator for recurrent events.

  • event: Binary event indicator, event = death + recurrent.

  • calendar: Calendar time cutoff used to generate the returned data.

  • lambda_0: Baseline Poisson process rate parameter.

  • lambda_star: Rate parameter of an exponential distribution in generating tau_star.

  • gamma_scale, gamma_shape: Parameters of the Gamma distribution used to generate subject-specific frailty terms.

References

Mao L, Lin DY. Semiparametric regression for the weighted composite endpoint of recurrent and terminal events. Biostatistics. 2016 Apr; 17(2) :390-403.

Examples

# Generate two-sample composite endpoint data
df <- TwoSample.generate.sequential(sizevec = c(200, 200),
beta.trt = 0.8, calendar = 5, recruitment = 3,
random.censor.rate = 0.05, seed = 2026)


gsMeanFreq documentation built on Feb. 17, 2026, 1:07 a.m.