Learn R Programming

icmstate (version 0.2.0)

sim_id_weib: 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,
  ...
)

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.

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 n_obs and stop_time.

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 rweibull. The first entry will be used for the first transition and so on.

scale

Vector of scale parameters for the 3 transitions. See rweibull The first entry will be used for the first transition and so on.

...

Further parameters to eval_times function.

Details

Taking shape = 1 we get an exponential distribution with rate 1/scale

Examples

Run this code
#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)

Run the code above in your browser using DataLab