Simulation of recurrent events data based on cumulative hazards

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

Arguments

n

number of id's

cumhaz

cumulative hazard of recurrent events

cumhaz2

cumulative hazard of recurrent events of type 2

death.cumhaz

cumulative hazard of death

r1

potential relative risk adjustment of rate

r2

potential relative risk adjustment of rate

rd

potential relative risk adjustment of rate

rc

potential relative risk adjustment of rate

gap.time

if true simulates gap-times with specified cumulative hazard

max.recurrent

limits number recurrent events to 100

dhaz

rate for death hazard if it is extended to time-range of first event

haz2

rate of second cause if it is extended to time-range of first event

dependence

0:independence; 1:all share same random effect with variance var.z; 2:random effect exp(normal) with correlation structure from cor.mat; 3:additive gamma distributed random effects, z1= (z11+ z12)/2 such that mean is 1 , z2= (z11^cor.mat(1,2)+ z13)/2, z3= (z12^(cor.mat(2,3)+z13^cor.mat(1,3))/2, with z11 z12 z13 are gamma with mean and variance 1 , first random effect is z1 and for N1 second random effect is z2 and for N2 third random effect is for death

var.z

variance of random effects

cor.mat

correlation matrix for var.z variance of random effects

cens

rate of censoring exponential distribution

...

Additional arguments to lower level funtions

Details

Must give hazard of death and two recurrent events. Possible with two event types and their dependence can be specified but the two recurrent events need to share random effect. Based on drawing the from cumhaz and cumhaz2 and taking the first event rather the cumulative and then distributing it out. Key advantage of this is that there is more flexibility wrt random effects

Author

Thomas Scheike

Examples

########################################
## getting some rates to mimick 
########################################

data(base1cumhaz)
data(base4cumhaz)
data(drcumhaz)
dr <- drcumhaz
base1 <- base1cumhaz
base4 <- base4cumhaz

cor.mat <- corM <- rbind(c(1.0, 0.6, 0.9), c(0.6, 1.0, 0.5), c(0.9, 0.5, 1.0))

######################################################################
### simulating simple model that mimicks data 
######################################################################
rr <- simRecurrent(5,base1,death.cumhaz=dr)
dlist(rr,.~id,n=0)
#> id: 1
#>        entry      time status rr rr2    dtime fdeath death     start      stop
#> 1     0.0000  136.1547      1  1   1 4228.637      1     0    0.0000  136.1547
#> 6   136.1547 1067.9961      1  1   1 4228.637      1     0  136.1547 1067.9961
#> 11 1067.9961 1637.9417      1  1   1 4228.637      1     0 1067.9961 1637.9417
#> 16 1637.9417 2063.6863      1  1   1 4228.637      1     0 1637.9417 2063.6863
#> 20 2063.6863 2265.6707      1  1   1 4228.637      1     0 2063.6863 2265.6707
#> 24 2265.6707 2686.8992      1  1   1 4228.637      1     0 2265.6707 2686.8992
#> 27 2686.8992 3554.8018      1  1   1 4228.637      1     0 2686.8992 3554.8018
#> 29 3554.8018 4228.6367      0  1   1 4228.637      1     1 3554.8018 4228.6367
#> ------------------------------------------------------------ 
#> id: 2
#>         entry       time status rr rr2 dtime fdeath death      start       stop
#> 2     0.00000   46.29699      1  1   1  5110      0     0    0.00000   46.29699
#> 7    46.29699  251.49166      1  1   1  5110      0     0   46.29699  251.49166
#> 12  251.49166  445.20831      1  1   1  5110      0     0  251.49166  445.20831
#> 17  445.20831 1216.85609      1  1   1  5110      0     0  445.20831 1216.85609
#> 21 1216.85609 1500.60616      1  1   1  5110      0     0 1216.85609 1500.60616
#> 25 1500.60616 2514.41422      1  1   1  5110      0     0 1500.60616 2514.41422
#> 28 2514.41422 2577.52247      1  1   1  5110      0     0 2514.41422 2577.52247
#> 30 2577.52247 2984.54042      1  1   1  5110      0     0 2577.52247 2984.54042
#> 31 2984.54042 3990.51506      1  1   1  5110      0     0 2984.54042 3990.51506
#> 32 3990.51506 4726.57351      1  1   1  5110      0     0 3990.51506 4726.57351
#> 33 4726.57351 5110.00000      0  1   1  5110      0     0 4726.57351 5110.00000
#> ------------------------------------------------------------ 
#> id: 3
#>       entry     time status rr rr2    dtime fdeath death    start     stop
#> 3     0.000 1353.162      1  1   1 1472.609      1     0    0.000 1353.162
#> 8  1353.162 1435.495      1  1   1 1472.609      1     0 1353.162 1435.495
#> 13 1435.495 1472.609      0  1   1 1472.609      1     1 1435.495 1472.609
#> ------------------------------------------------------------ 
#> id: 4
#>         entry       time status rr rr2    dtime fdeath death      start
#> 4     0.00000   82.54944      1  1   1 2007.163      1     0    0.00000
#> 9    82.54944  140.71176      1  1   1 2007.163      1     0   82.54944
#> 14  140.71176  156.85523      1  1   1 2007.163      1     0  140.71176
#> 18  156.85523  520.76443      1  1   1 2007.163      1     0  156.85523
#> 22  520.76443 1890.81079      1  1   1 2007.163      1     0  520.76443
#> 26 1890.81079 2007.16317      0  1   1 2007.163      1     1 1890.81079
#>          stop
#> 4    82.54944
#> 9   140.71176
#> 14  156.85523
#> 18  520.76443
#> 22 1890.81079
#> 26 2007.16317
#> ------------------------------------------------------------ 
#> id: 5
#>        entry      time status rr rr2    dtime fdeath death     start      stop
#> 5     0.0000  407.6795      1  1   1 1726.288      1     0    0.0000  407.6795
#> 10  407.6795  688.8398      1  1   1 1726.288      1     0  407.6795  688.8398
#> 15  688.8398  836.1697      1  1   1 1726.288      1     0  688.8398  836.1697
#> 19  836.1697 1420.3291      1  1   1 1726.288      1     0  836.1697 1420.3291
#> 23 1420.3291 1726.2880      0  1   1 1726.288      1     1 1420.3291 1726.2880

rr <- simRecurrent(100,base1,death.cumhaz=dr)
par(mfrow=c(1,3))
showfitsim(causes=1,rr,dr,base1,base1)
######################################################################
### simulating simple model 
### random effect for all causes (Z shared for death and recurrent) 
######################################################################
rr <- simRecurrent(100,base1,death.cumhaz=dr,dependence=1,var.gamma=0.4)

######################################################################
### simulating simple model that mimicks data 
### now with two event types and second type has same rate as death rate
######################################################################
set.seed(100)
rr <- simRecurrentII(100,base1,base4,death.cumhaz=dr)
dtable(rr,~death+status)
#> 
#>       status   0   1   2
#> death                   
#> 0             10 295  39
#> 1             90   0   0
par(mfrow=c(2,2))

showfitsim(causes=2,rr,dr,base1,base4)