R/recurrent.marginal.R
simRecurrentII.Rd
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,
...
)
number of id's
cumulative hazard of recurrent events
cumulative hazard of recurrent events of type 2
cumulative hazard of death
potential relative risk adjustment of rate
potential relative risk adjustment of rate
potential relative risk adjustment of rate
potential relative risk adjustment of rate
if true simulates gap-times with specified cumulative hazard
limits number recurrent events to 100
rate for death hazard if it is extended to time-range of first event
rate of second cause if it is extended to time-range of first event
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
variance of random effects
correlation matrix for var.z variance of random effects
rate of censoring exponential distribution
Additional arguments to lower level funtions
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
########################################
## 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 rr2 dtime fdeath death start stop rr1
#> 1 0 135.9861 0 1 135.9861 1 1 0 135.9861 1
#> ------------------------------------------------------------
#> id: 2
#> entry time status rr2 dtime fdeath death start stop rr1
#> 2 0.0000 166.9412 1 1 3109.734 1 0 0.0000 166.9412 1
#> 6 166.9412 301.3736 1 1 3109.734 1 0 166.9412 301.3736 1
#> 9 301.3736 986.0779 1 1 3109.734 1 0 301.3736 986.0779 1
#> 11 986.0779 1821.3682 1 1 3109.734 1 0 986.0779 1821.3682 1
#> 13 1821.3682 2971.3924 1 1 3109.734 1 0 1821.3682 2971.3924 1
#> 15 2971.3924 3109.7343 0 1 3109.734 1 1 2971.3924 3109.7343 1
#> ------------------------------------------------------------
#> id: 3
#> entry time status rr2 dtime fdeath death start stop rr1
#> 3 0.0000 797.5815 1 1 3559.969 1 0 0.0000 797.5815 1
#> 7 797.5815 1216.2149 1 1 3559.969 1 0 797.5815 1216.2149 1
#> 10 1216.2149 1817.8489 1 1 3559.969 1 0 1216.2149 1817.8489 1
#> 12 1817.8489 2142.2093 1 1 3559.969 1 0 1817.8489 2142.2093 1
#> 14 2142.2093 2398.7708 1 1 3559.969 1 0 2142.2093 2398.7708 1
#> 16 2398.7708 2624.8463 1 1 3559.969 1 0 2398.7708 2624.8463 1
#> 17 2624.8463 2771.7648 1 1 3559.969 1 0 2624.8463 2771.7648 1
#> 18 2771.7648 2984.2139 1 1 3559.969 1 0 2771.7648 2984.2139 1
#> 19 2984.2139 2997.9952 1 1 3559.969 1 0 2984.2139 2997.9952 1
#> 20 2997.9952 3559.9692 0 1 3559.969 1 1 2997.9952 3559.9692 1
#> ------------------------------------------------------------
#> id: 4
#> entry time status rr2 dtime fdeath death start stop rr1
#> 4 0.000000 3.423451 1 1 1176.08 1 0 0.000000 3.423451 1
#> 8 3.423451 1176.080236 0 1 1176.08 1 1 3.423451 1176.080236 1
#> ------------------------------------------------------------
#> id: 5
#> entry time status rr2 dtime fdeath death start stop rr1
#> 5 0 132.0781 0 1 132.0781 1 1 0 132.0781 1
rr <- simRecurrent(10000,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(10000,base1,base4,death.cumhaz=dr)
dtable(rr,~death+status)
#>
#> status 0 1 2
#> death
#> 0 1237 28668 3819
#> 1 8763 0 0
par(mfrow=c(2,2))
showfitsim(causes=2,rr,dr,base1,base4)
set.seed(100)
cumhaz <- list(base1,base1,base4)
drl <- list(dr,base4)
rr <- simRecurrentIII(100,cumhaz,death.cumhaz=drl,dep=0)
dtable(rr,~death+status)
#>
#> status 0 1 2 3
#> death
#> 0 4 232 268 33
#> 1 70 0 0 0
#> 2 26 0 0 0
showfitsimIII(rr,cumhaz,drl)