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.0000 675.6366 1 1 4301.163 1 0 0.0000 675.6366 1
#> 6 675.6366 990.5305 1 1 4301.163 1 0 675.6366 990.5305 1
#> 8 990.5305 1162.2117 1 1 4301.163 1 0 990.5305 1162.2117 1
#> 10 1162.2117 1162.7501 1 1 4301.163 1 0 1162.2117 1162.7501 1
#> 12 1162.7501 1884.7551 1 1 4301.163 1 0 1162.7501 1884.7551 1
#> 14 1884.7551 2303.3070 1 1 4301.163 1 0 1884.7551 2303.3070 1
#> 16 2303.3070 3389.6601 1 1 4301.163 1 0 2303.3070 3389.6601 1
#> 18 3389.6601 4301.1626 0 1 4301.163 1 1 3389.6601 4301.1626 1
#> ------------------------------------------------------------
#> id: 2
#> entry time status rr2 dtime fdeath death start stop rr1
#> 2 0 261.667 0 1 261.667 1 1 0 261.667 1
#> ------------------------------------------------------------
#> id: 3
#> entry time status rr2 dtime fdeath death start stop rr1
#> 3 0 118.8737 0 1 118.8737 1 1 0 118.8737 1
#> ------------------------------------------------------------
#> id: 4
#> entry time status rr2 dtime fdeath death start stop rr1
#> 4 0 329.9093 0 1 329.9093 1 1 0 329.9093 1
#> ------------------------------------------------------------
#> id: 5
#> entry time status rr2 dtime fdeath death start stop rr1
#> 5 0.0000 514.6201 1 1 5110 0 0 0.0000 514.6201 1
#> 7 514.6201 725.4856 1 1 5110 0 0 514.6201 725.4856 1
#> 9 725.4856 1998.7437 1 1 5110 0 0 725.4856 1998.7437 1
#> 11 1998.7437 2446.4343 1 1 5110 0 0 1998.7437 2446.4343 1
#> 13 2446.4343 2936.4415 1 1 5110 0 0 2446.4343 2936.4415 1
#> 15 2936.4415 3421.6532 1 1 5110 0 0 2936.4415 3421.6532 1
#> 17 3421.6532 4494.5024 1 1 5110 0 0 3421.6532 4494.5024 1
#> 19 4494.5024 5110.0000 0 1 5110 0 0 4494.5024 5110.0000 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)