This function allows simulation of time-to-event-data that follow a multistate-model with recurrent events of one type and a competing event. The baseline hazard for the cause-specific hazards are here functions of the total/calendar time. To induce between-subject-heterogeneity a random effect covariate (frailty term) can be incorporated for the recurrent and the competing event. Data for the recurrent events of the individual \(i\) are generated according to the cause-specific hazards $$\lambda_{0r}(t)* Z_{ri} *exp(\beta_r^t X_i),$$ where \(X_i\) defines the covariate vector and \(\beta_r\) the regression coefficient vector. \(\lambda_{0r}(t)\) denotes the baseline hazard, being a function of the total/calendar time \(t\) and \(Z_{ri}\) denotes the frailty variables with \((Z_{ri})_i\) iid with \(E(Z_{ri})=1\) and \(Var(Z_{ri})=\theta_r\). The parameter \(\theta_r\) describes the degree of between-subject-heterogeneity for the recurrent event. Analougously the competing event is generated according to the cause-specific hazard conditionally on the frailty variable and covariates: $$\lambda_{0c}(t)* Z_{ci} *exp(\beta_c^t X_i)$$ Data output is in the counting process format.
simreccomp(
N,
fu.min,
fu.max,
cens.prob = 0,
dist.x = "binomial",
par.x = 0,
beta.xr = 0,
beta.xc = 0,
dist.zr = "gamma",
par.zr = 0,
a = NULL,
dist.zc = NULL,
par.zc = NULL,
dist.rec,
par.rec,
dist.comp,
par.comp,
pfree = 0,
dfree = 0
)
Number of individuals
Minimum length of follow-up.
Maximum length of follow-up. Individuals length of follow-up is
generated from a uniform distribution on
[fu.min, fu.max]
. If fu.min=fu.max
, then all individuals have a common
follow-up.
Gives the probability of being censored due to loss to follow-up before
fu.max
. For a random set of individuals defined by a B(N,cens.prob
)-distribution,
the time to censoring is generated from a uniform
distribution on [0, fu.max]
. Default is cens.prob=0
, i.e. no censoring
due to loss to follow-up.
Distribution of the covariate(s) \(X\). If there is more than one covariate,
dist.x
must be a vector of distributions with one entry for each covariate. Possible
values are "binomial"
and "normal"
, default is dist.x="binomial"
.
Parameters of the covariate distribution(s). For "binomial", par.x
is
the probability for \(x=1\). For "normal"
, par.x=c(
\(\mu, \sigma\))
where \(\mu\) is the mean and \(\sigma\) is the standard deviation of a normal distribution.
If one of the covariates is defined to be normally distributed, par.x
must be a list,
e.g. dist.x <- c("binomial", "normal")
and par.x <- list(0.5, c(1,2))
.
Default is par.x=0
, i.e. \(x=0\) for all individuals.
Regression coefficient(s) for the covariate(s) \(x\) corresponding to the
recurrent events. If there is more than one covariate,
beta.xr
must be a vector of coefficients with one entry for each covariate.
simreccomp
generates as many covariates as there are entries in beta.xr
. Default is
beta.xr=0
, corresponding to no effect of the covariate \(x\) on the recurrent events.
Regression coefficient(s) for the covariate(s) \(x\) corresponding to the
competing event. If there is more than one covariate, beta.xc
must be a vector of coefficients with one entry for each covariate. Default is
beta.xc=0
, corresponding to no effect of the covariate \(x\) on the competing event.
Distribution of the frailty variable \(Z_r\) for the recurent events with \(E(Z_r)=1\) and
\(Var(Z_r)=\theta_r\). Possible values are "gamma"
for a Gamma distributed frailty
and "lognormal"
for a lognormal distributed frailty.
Default is dist.zr="gamma"
.
Parameter \(\theta_r\) for the frailty distribution: this parameter gives
the variance of the frailty variable \(Z_r\).
Default is par.zr=0
, which causes \(Z_r=1\), i.e. no frailty effect for the recurrent events.
Alternatively, the frailty distribution for the competing event can be computed through the distribution
of the frailty variable \(Z_r\) by \(Z_c=Z_r**a\).
Default is a=NULL
.
Distribution of the frailty variable \(Z_c\) for the competing event with \(E(Z_c)=1\) and
\(Var(Z_c)=\theta_c\). Possible values are "gamma"
for a Gamma distributed frailty
and "lognormal"
for a lognormal distributed frailty.
Default is dist.zc=NULL
.
Parameter \(\theta_c\) for the frailty distribution: this parameter gives
the variance of the frailty variable \(Z_c\).
Default is par.zc=NULL
.
Form of the baseline hazard function for the recurrent events.
Possible values are "weibull"
or
"gompertz"
or "lognormal"
or "step"
.
Parameters for the distribution of the recurrent event data.
If dist.rec="weibull"
the hazard function is $$\lambda_0(t)=\lambda*\nu* t^{\nu - 1},$$
where \(\lambda>0\) is the scale and \(\nu>0\) is the shape parameter. Then
par.rec=c(
\(\lambda, \nu\))
. A special case
of this is the exponential distribution for \(\nu=1\).
If dist.rec="gompertz"
, the hazard function is $$\lambda_0(t)=\lambda*exp(\alpha t),$$
where \(\lambda>0\) is the scale and \(\alpha\in(-\infty,+\infty)\) is the shape parameter.
Then par.rec=c(
\(\lambda, \alpha\))
.
If dist.rec="lognormal"
, the hazard function is
$$\lambda_0(t)=[(1/(\sigma t))*\phi((ln(t)-\mu)/\sigma)]/[\Phi((-ln(t)-\mu)/\sigma)],$$
where \(\phi\) is the probability density function and \(\Phi\) is the cumulative
distribution function of the standard normal distribution, \(\mu\in(-\infty,+\infty)\) is a
location parameter and \(\sigma>0\) is a shape parameter. Then par.rec=c(
\(\mu,\sigma\))
.
Please note, that specifying dist.rec="lognormal"
together with some covariates does not
specify the usual lognormal model (with covariates specified as effects on the parameters of the
lognormal distribution resulting in non-proportional hazards), but only defines the baseline
hazard and incorporates covariate effects using the proportional hazard assumption.
If dist.rec="step"
the hazard function is $$\lambda_0(t)=a, t<=t_1, and \lambda_0(t)=b, t>t_1$$.
Then par.rec=c(
\(a,b,t_1\))
.
Form of the baseline hazard function for the competing event.
Possible values are "weibull"
or
"gompertz"
or "lognormal"
or "step"
.
Parameters for the distribution of the competing event data.
For more details see par.rec
.
Probability that after experiencing an event the individual is not at risk
for experiencing further events for a length of dfree
time units.
Default is pfree=0
.
Length of the risk-free interval. Must be in the same time unit as fu.max
.
Default is dfree=0
, i.e. the individual is continously at risk for experiencing
events until end of follow-up.
The output is a data.frame consisting of the columns:
An integer number for identification of each individual
or x.V1, x.V2, ...
- depending on the covariate matrix. Contains the
randomly generated value of the covariate(s) \(X\) for each individual.
Contains the randomly generated value of the frailty variable \(Z_r\) for each individual.
Contains the randomly generated value of the frailty variable \(Z_c\) for each individual.
The start of interval [start, stop]
, when the individual
starts to be at risk for a next event.
The time of an event or censoring, i.e. the end of interval [start, stop]
.
An indicator of whether an event occured at time stop
(status=1
),
the individual is censored at time stop
(status=0
) or the competing event occured at time
stop
(status=2
).
Length of follow-up period [0,fu]
for each individual.
For each individual there are as many lines as it experiences events, plus one line if being censored. The data format corresponds to the counting process format.
simrec
### Example:
### A sample of 10 individuals
N <- 10
### with a binomially distributed covariate and a standard normally distributed covariate
### with regression coefficients of beta.xr=0.3 and beta.xr=0.2, respectively,
### for the recurrent events,
### as well as regression coefficients of beta.xc=0.5 and beta.xc=0.25, respectively,
### for the competing event.
dist.x <- c("binomial", "normal")
par.x <- list(0.5, c(0, 1))
beta.xr <- c(0.3, 0.2)
beta.xc <- c(0.5, 0.25)
### a gamma distributed frailty variable for the recurrent event with variance 0.25
### and for the competing event with variance 0.3,
dist.zr <- "gamma"
par.zr <- 0.25
dist.zc <- "gamma"
par.zc <- 0.3
### alternatively the frailty variable for the competing event can be computed via a:
a <- 0.5
### Furthermore a Weibull-shaped baseline hazard for the recurrent event with shape parameter
### lambda=1 and scale parameter nu=2,
dist.rec <- "weibull"
par.rec <- c(1, 2)
### and a Weibull-shaped baseline hazard for the competing event with shape parameter lambda=1
### and scale parameter nu=2
dist.comp <- "weibull"
par.comp <- c(1, 2)
### Subjects are to be followed for two years with 20% of the subjects
### being censored according to a uniformly distributed censoring time
### within [0,2] (in years).
fu.min <- 2
fu.max <- 2
cens.prob <- 0.2
### After each event a subject is not at risk for experiencing further events
### for a period of 30 days with a probability of 50%.
dfree <- 30 / 365
pfree <- 0.5
simdata1 <- simreccomp(
N = N, fu.min = fu.min, fu.max = fu.max, cens.prob = cens.prob,
dist.x = dist.x, par.x = par.x, beta.xr = beta.xr, beta.xc = beta.xc,
dist.zr = dist.zr, par.zr = par.zr, a = a,
dist.rec = dist.rec, par.rec = par.rec, dist.comp = dist.comp, par.comp = par.comp,
pfree = pfree, dfree = dfree
)
simdata2 <- simreccomp(
N = N, fu.min = fu.min, fu.max = fu.max, cens.prob = cens.prob,
dist.x = dist.x, par.x = par.x, beta.xr = beta.xr, beta.xc = beta.xc,
dist.zr = dist.zr, par.zr = par.zr, dist.zc = dist.zc, par.zc = par.zc,
dist.rec = dist.rec, par.rec = par.rec, dist.comp = dist.comp, par.comp = par.comp,
pfree = pfree, dfree = dfree
)
simdata1
#> id x.V1 x.V2 zr zc start stop status
#> 1 1 0 0.112294787 1.0323272 1.0160350 0.0000000 0.6644770 2
#> 4 2 1 0.007886198 1.0548994 1.0270829 0.0000000 0.3188520 2
#> 12 3 1 1.877743872 1.4832150 1.2178731 0.0000000 0.5608202 2
#> 20 4 1 2.158756554 0.4900558 0.7000398 0.0000000 0.4889408 2
#> 24 5 1 0.709714522 1.4287358 1.1952974 0.0000000 0.3081751 1
#> 25 5 1 0.709714522 1.4287358 1.1952974 0.3903669 0.4042269 1
#> 26 5 1 0.709714522 1.4287358 1.1952974 0.4864187 0.5738317 2
#> 33 6 0 0.766983379 1.1010617 1.0493148 0.0000000 0.6727332 1
#> 34 6 0 0.766983379 1.1010617 1.0493148 0.7549250 1.1937865 2
#> 37 7 0 -0.308211421 0.1158947 0.3404331 0.0000000 1.4533993 2
#> 40 8 1 1.012001849 0.7743617 0.8799782 0.0000000 0.1163513 0
#> 42 9 0 -0.919051597 0.2562348 0.5061964 0.0000000 0.2863560 1
#> 43 9 0 -0.919051597 0.2562348 0.5061964 0.3685478 1.0342616 2
#> 44 10 1 0.563380077 1.7862755 1.3365162 0.0000000 0.5756780 1
#> 45 10 1 0.563380077 1.7862755 1.3365162 0.6578697 0.8426681 1
#> 46 10 1 0.563380077 1.7862755 1.3365162 0.8426681 0.8568313 2
#> fu
#> 1 0.6644770
#> 4 0.3188520
#> 12 0.5608202
#> 20 0.4889408
#> 24 0.5738317
#> 25 0.5738317
#> 26 0.5738317
#> 33 1.1937865
#> 34 1.1937865
#> 37 1.4533993
#> 40 0.1163513
#> 42 1.0342616
#> 43 1.0342616
#> 44 0.8568313
#> 45 0.8568313
#> 46 0.8568313
simdata2
#> id x.V1 x.V2 zr zc start stop status
#> 1 1 1 -1.3416861 1.1945898 1.5479373 0.00000000 0.41497436 2
#> 8 2 0 1.1589792 2.1337248 1.7948531 0.00000000 0.07861212 1
#> 9 2 0 1.1589792 2.1337248 1.7948531 0.07861212 0.59840312 2
#> 17 3 1 -0.2032090 0.6114929 0.5888167 0.00000000 1.19404046 2
#> 20 4 0 -0.3780286 2.4510196 0.7881004 0.00000000 0.60517375 2
#> 27 5 0 1.7361110 0.5898716 0.9435114 0.00000000 0.60449326 2
#> 29 6 1 -0.8452478 1.6756066 1.1200140 0.00000000 0.26748367 2
#> 37 7 1 -0.9615715 0.3638910 0.3224063 0.00000000 0.57644701 2
#> 39 8 0 1.0174911 1.1320881 0.4094289 0.00000000 0.28077918 1
#> 40 8 0 1.0174911 1.1320881 0.4094289 0.28077918 0.90005516 1
#> 41 8 0 1.0174911 1.1320881 0.4094289 0.98224695 1.31856656 2
#> 43 9 1 -1.4960537 0.2475765 1.2051548 0.00000000 0.16116030 2
#> 45 10 1 -1.1848187 0.9551871 0.6523226 0.00000000 0.39827554 1
#> 46 10 1 -1.1848187 0.9551871 0.6523226 0.48046732 0.57462007 1
#> 47 10 1 -1.1848187 0.9551871 0.6523226 0.65681185 0.81835914 1
#> 48 10 1 -1.1848187 0.9551871 0.6523226 0.81835914 0.93634381 2
#> fu
#> 1 0.4149744
#> 8 0.5984031
#> 9 0.5984031
#> 17 1.1940405
#> 20 0.6051738
#> 27 0.6044933
#> 29 0.2674837
#> 37 0.5764470
#> 39 1.3185666
#> 40 1.3185666
#> 41 1.3185666
#> 43 0.1611603
#> 45 0.9363438
#> 46 0.9363438
#> 47 0.9363438
#> 48 0.9363438