
Simulate recurrent events from a two-stage Cox or Ghosh-Lin model
Source:R/recurrent.marginal.R
sim_recurrent_ts.RdSimulates recurrent event data from a fitted two-stage model, where the
recurrent event process and the terminal event are each described by a
separate fitted model. The recurrent event model may be either a Cox
proportional hazards model (phreg) or a Ghosh-Lin marginal rate model
(recreg); the terminal event model must be a Cox model (phreg).
Usage
sim_recurrent_ts(
cox1,
coxd = NULL,
n = 1,
data = NULL,
type = c("default", "cox-cox", "gl-cox"),
id = "id",
varz = 1,
share = 1,
cens = 0.001,
scale1 = 1,
scaled = 1,
dependence = NULL,
r1 = NULL,
rd = NULL,
rc = NULL,
strata1 = NULL,
stratad = NULL,
death.code = 3,
...
)Arguments
- cox1
A fitted
phregobject for the recurrent event rate, or a fittedrecreg(Ghosh-Lin) object. The model type is detected automatically from the class.- coxd
A fitted
phregobject for the terminal event. May beNULLif no terminal event is modelled.- n
Number of subjects to simulate. Default is
1.- data
The data frame on which
cox1andcoxdwere fitted, used to draw covariate values for the simulated subjects. IfNULL, covariates must be supplied viar1,rd,strata1, andstratad.- type
Simulation type:
"default"(auto-detected from class ofcox1),"cox-cox", or"gl-cox".- id
Name of the subject identifier variable in
data. Default is"id".- varz
Variance of the frailty distribution in the two-stage model. Default is
1.Proportion of the shared frailty assigned to the recurrent event process in the partial-sharing model. Default is
1.- cens
Rate of exponential censoring. Default is
0.001.- scale1
Scalar multiplier for the baseline cumulative hazard of the recurrent event process. Default is
1.- scaled
Scalar multiplier for the baseline cumulative hazard of the terminal event. Default is
1.- dependence
If non-
NULL, falls back tosim_recurrent_listwith this frailty structure (seesim_recurrentIIfor valid values). Default isNULL.- r1
Optional numeric vector of length
nof subject-specific relative risks for the recurrent event, used whendata = NULL.- rd
Optional numeric vector of length
nof subject-specific relative risks for the terminal event, used whendata = NULL.- rc
Optional numeric vector of length
nof subject-specific censoring rate multipliers.- strata1
Optional integer vector of length
nspecifying the stratum index (0-based) for the recurrent event model, used whendata = NULL.- stratad
Optional integer vector of length
nspecifying the stratum index (0-based) for the terminal event model, used whendata = NULL.- death.code
Integer status code used for the terminal event in the output
statuscolumn. Default is3.- ...
Further arguments passed to
sim_GLcox, includingnminandnmaxfor the linear approximation grid.
Value
A data frame in counting-process format with one row per event
interval per subject. Column names match those in the original model
formula (entry, exit, and status variables). Additional columns include
id and the covariates drawn from data (if supplied). The
terminal event is coded as death.code in the status variable;
recurrent events are coded as 1.
Details
Covariates are drawn by bootstrap from data (if supplied), and
subject-specific relative risks and strata are derived from the fitted
model objects. Stratified baselines are fully supported. When
dependence is NULL (default), the simulation uses the
two-stage structure from sim_GLcox; setting dependence
to an integer falls back to sim_recurrent_list with the
corresponding frailty model.
References
Scheike, T. H. (2026). Two-stage recurrent events random effects models. Lifetime Data Analysis.
Examples
data(hfactioncpx12)
hf <- hfactioncpx12
hf$x <- as.numeric(hf$treatment)
n <- 100
## Cox-Cox two-stage model
xr <- phreg(Surv(entry, time, status == 1) ~ x + cluster(id), data = hf)
dr <- phreg(Surv(entry, time, status == 2) ~ x + cluster(id), data = hf)
simcoxcox <- sim_recurrent_ts(xr, dr, n = n, data = hf, death.code = 2)
## Ghosh-Lin/Cox two-stage model
recGL <- recreg(Event(entry, time, status) ~ x + cluster(id), hf, death.code = 2)
simglcox <- sim_recurrent_ts(recGL, dr, n = n, data = hf, death.code = 2)