Learn R Programming

mets (version 1.3.11)

sim_recurrentII: Simulate recurrent events with two event types and a terminal event

Description

Simulates recurrent event data with up to two distinct event types and an optional terminal event (death), based on user-supplied cumulative hazard functions. Dependence between processes can be introduced via shared or correlated gamma-distributed frailties.

Usage

sim_recurrentII(
  n,
  cumhaz,
  cumhaz2,
  death.cumhaz = NULL,
  r1 = NULL,
  r2 = NULL,
  rd = NULL,
  rc = NULL,
  dependence = 0,
  var.z = 1,
  cor.mat = NULL,
  cens = NULL,
  gap.time = FALSE,
  max.recurrent = 100,
  ...
)

Value

A data frame in counting-process format (one row per event interval per subject) with columns:

id

Subject identifier.

start, entry

Interval start time.

stop, time

Interval end time (event or censoring time).

status

Event type at stop: 1 or 2 for a recurrent event of the corresponding type, 0 for censoring.

death

Indicator for a terminal event (1) or censoring/survival (0).

Attributes "cumhaz", "death.cumhaz", "rr", and

"rd" store the inputs used for simulation.

Arguments

n

Number of subjects to simulate.

cumhaz

Two-column matrix (time, cumhaz) giving the cumulative hazard of the first type of recurrent event.

cumhaz2

Two-column matrix (time, cumhaz) giving the cumulative hazard of the second type of recurrent event.

death.cumhaz

Two-column matrix (time, cumhaz) giving the cumulative hazard of the terminal event. If NULL, no terminal event is simulated and follow-up ends at the end of cumhaz.

r1

Optional numeric vector of length n with subject-specific relative risk multipliers for the first event type.

r2

Optional numeric vector of length n with subject-specific relative risk multipliers for the second event type.

rd

Optional numeric vector of length n with subject-specific relative risk multipliers for the terminal event.

rc

Optional numeric vector of length n with subject-specific multipliers for the exponential censoring rate.

dependence

Integer specifying the frailty structure. One of 0 (independence), 1 (shared gamma frailty), or 4 (shared frailty for recurrent events only). See Details.

var.z

Variance of the gamma-distributed frailty. Default is 1.

cor.mat

Correlation matrix for the random effects. Used when dependence = 2 (in sim_recurrent_list).

cens

Rate of exponential censoring. If NULL (default), no additional censoring is applied.

gap.time

Logical. If TRUE, event times are drawn as gap times (time since the last event) rather than calendar times. Default is FALSE.

max.recurrent

Maximum number of recurrent events allowed per subject. Default is 100.

...

Further arguments passed to sim_recurrent_list.

Author

Thomas Scheike

Details

The simulation proceeds by sequentially drawing the next event time from the specified cumulative hazards, taking the minimum of the two recurrent event times, and stopping each subject at death or administrative censoring.

Dependence between processes is controlled by dependence:

0

Independence: all subjects have frailty fixed at 1.

1

Shared frailty: all processes share a single gamma-distributed random effect with mean 1 and variance var.z.

4

Recurrent-event frailty only: the two recurrent event processes share a gamma frailty but the terminal event is independent.

For more complex correlation structures across two event types and death, use sim_recurrentTS.

See Also

sim_recurrent, sim_recurrent_list, sim_recurrentTS

Examples

Run this code
data(CPH_HPN_CRBSI)
dr    <- CPH_HPN_CRBSI$terminal
base1 <- CPH_HPN_CRBSI$crbsi
base4 <- CPH_HPN_CRBSI$mechanical

## Single recurrent event type, with and without terminal event
rr <- sim_recurrent(5, base1)
dlist(rr, . ~ id, n = 0)

rr <- sim_recurrent(5, base1, death.cumhaz = dr)
dlist(rr, . ~ id, n = 0)

## Verify that estimated rates recover the true baselines (increase n for precision)
rr <- sim_recurrent(100, base1, death.cumhaz = dr)
par(mfrow = c(1, 3))
mets:::showfitsim(causes = 1, rr, dr, base1, base1)

## Shared frailty across all processes
rr <- sim_recurrent(100, base1, death.cumhaz = dr, dependence = 1, var.z = 0.4)
dtable(rr, ~death + status)

## Two event types; second type uses the mechanical complication rate
set.seed(100)
rr <- sim_recurrentII(100, base1, base4, death.cumhaz = dr)
dtable(rr, ~death + status)
par(mfrow = c(2, 2))
mets:::showfitsim(causes = 2, rr, dr, base1, base4)

## Three event types and two causes of death via sim_recurrent_list
set.seed(100)
cumhaz <- list(base1, base1, base4)
drl    <- list(dr, base4)
rr     <- sim_recurrent_list(100, cumhaz, death.cumhaz = drl, dependence = 0)
dtable(rr, ~death + status)
mets:::showfitsimList(rr, cumhaz, drl)

Run the code above in your browser using DataLab