sim_id_weib {icmstate} | R Documentation |
Simulate panel data from an illness-death model with Weibull transition hazards
Description
An illness-death model has 3 transitions:
1
:State 1 (Healthy) to State 2 (Illness);
2
:State 1 (Healthy) to State 3 (Death);
3
:State 2 (Illness) to State 3 (Death);
Using this function, it is possible to simulate data from an illness-death model with Weibull transition intensities. Requires the use of an external (self-written) function to generate observation times.
Usage
sim_id_weib(
n,
n_obs,
stop_time,
eval_times,
start_state = c("stable", "equalprob"),
shape,
scale,
...
)
Arguments
n |
Number of subjects to generate paths for. |
n_obs |
Number of observations in time period for each subject. |
stop_time |
Largest time at which the model is considered. |
eval_times |
A function which returns the evaluation times for a subject.
Must have as arguments at least |
start_state |
In which states can subjects start? Either everyone starts in state 1 ("stable") or equal probability to start in state 1 or 2 ("equalprob"). |
shape |
Vector of shape parameters for the 3 transitions. See |
scale |
Vector of scale parameters for the 3 transitions. See |
... |
Further parameters to |
Details
Taking shape = 1
we get an exponential distribution with rate
1/scale
Value
Panel data in the form of a data.frame
with 3 named columns
id, time and state. These represent the subject identifier, the observation
time and the state at the
observation time.
Examples
#Function to generate evaluation times: at 0 and uniform inter-observation
eval_times <- function(n_obs, stop_time){
cumsum( c( 0, runif( n_obs-1, 0, 2*(stop_time-4)/(n_obs-1) ) ) )
}
#Simulate illness-death model data with Weibull transitions
sim_dat <- sim_id_weib(n = 20, n_obs = 6, stop_time = 15, eval_times = eval_times,
start_state = "stable", shape = c(0.5, 0.5, 2), scale = c(5, 10, 10/gamma(1.5)))
visualise_msm(sim_dat)