| IndivCtstmTrans {hesim} | R Documentation |
Transitions for an individual-level continuous time state transition model
Description
Simulate health state transitions in an individual-level continuous time state transition model using parameters from a multi-state model.
Format
An R6::R6Class object.
Super class
hesim::CtstmTrans -> IndivCtstmTrans
Public fields
paramsAn object of class
params_survorparams_surv_list.input_dataInput data used to simulate health state transitions by sample from the probabilistic sensitivity analysis (PSA), treatment strategy and patient. Must be an object of class
input_mats. Ifparamscontains parameters from a list of models (i.e., of classparams_surv_list), theninput_datamust contain a unique row for each treatment strategy and patient; ifparamscontains parameters from a joint model (i.e., of classparams_surv), theninput_datamust contain a unique row for each treatment strategy, patient, and transition.trans_matA transition matrix describing the states and transitions in a multi-state model in the format from the
mstatepackage. See the documentation for the argument"trans"inmstate::msprep.start_stateA scalar or vector denoting the starting health state. Default is the first health state. If a vector, must be equal to the number of simulated patients.
start_ageA scalar or vector denoting the starting age of each patient in the simulation. Default is 38. If a vector, must be equal to the number of simulated patients.
death_stateThe death state in
trans_mat. Used withmax_ageinsim_diseaseas patients transition to this state upon reaching maximum age. By default, it is set to the final absorbing state (i.e., a row intrans_matwith all NAs).clock"reset" for a clock-reset model, "forward" for a clock-forward model, "mix" for a mixture of clock-reset and clock-forward models by state, and "mixt" for a mixture of clock-reset and clock-forward models by transition. A clock-reset model is a semi-Markov model in which transition rates depend on time since entering a state. A clock-forward model is a Markov model in which transition rates depend on time since entering the initial state. If
"mix"is used, thenreset_statesmust be specified. If"mixt"is used, thentransition_typesmust be specified.reset_statesA vector denoting the states in which time resets. Hazard functions are always a function of elapsed time since either the start of the model or from when time was previously reset. Only used if
clock = "mix".transition_typesA vector denoting the type of transition. The vector is of the same length as the number of transitions and takes values
"reset","time"or"age"for hazards that are functions of reset time, time since study entry or age, respectively. Only used ifclock = "mixt".
Methods
Public methods
Inherited methods
Method new()
Create a new IndivCtstmTrans object.
Usage
IndivCtstmTrans$new(
params,
input_data,
trans_mat,
start_state = 1,
start_age = 38,
death_state = NULL,
clock = c("reset", "forward", "mix", "mixt"),
reset_states = NULL,
transition_types = NULL
)Arguments
paramsThe
paramsfield.input_dataThe
input_datafield.trans_matThe
trans_matfield.start_stateThe
start_statefield.start_ageThe
start_agefield.death_stateThe
death_statefield.clockThe
clockfield.reset_statesThe
reset_statesfield.transition_typesThe
transition_typesfield.
Returns
A new IndivCtstmTrans object.
Method sim_disease()
Simulate disease progression (i.e., individual trajectories through a multi-state model using an individual patient simulation).
Usage
IndivCtstmTrans$sim_disease(max_t = 100, max_age = 100, progress = NULL)
Arguments
max_tA scalar or vector denoting the length of time to simulate the model. If a vector, must be equal to the number of simulated patients.
max_ageA scalar or vector denoting the maximum age to simulate each patient until. If a vector, must be equal to the number of simulated patients.
progressAn integer, specifying the PSA iteration (i.e., sample) that should be printed every progress PSA iterations. For example, if progress = 2, then every second PSA iteration is printed. Default is NULL, in which case no output is printed.
Returns
An object of class disprog.
Method sim_stateprobs()
Simulate health state probabilities from a disprog object.
Usage
IndivCtstmTrans$sim_stateprobs(t, disprog = NULL, ...)
Arguments
tA numeric vector of times.
disprogA disprog object. If
NULL, then this will be simulated prior to computing state probabilities usingIndivCtstm$sim_disease()....Additional arguments to pass to
IndivCtstm$sim_disease()ifdisprog = NULL.
Returns
An object of class stateprobs.
Method check()
Input validation for class. Checks that fields are the correct type.
Usage
IndivCtstmTrans$check()
Method clone()
The objects of this class are cloneable with this method.
Usage
IndivCtstmTrans$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
IndivCtstmTrans objects are conveniently created from either
fitted models or parameter objects with create_IndivCtstmTrans().
A complete economic model can be implemented with the IndivCtstm class.
Examples
library("flexsurv")
# Simulation data
strategies <- data.frame(strategy_id = c(1, 2, 3))
patients <- data.frame(patient_id = seq(1, 3),
age = c(45, 50, 60),
female = c(0, 0, 1))
# Multi-state model with transition specific models
tmat <- rbind(c(NA, 1, 2),
c(NA, NA, 3),
c(NA, NA, NA))
fits <- vector(length = max(tmat, na.rm = TRUE), mode = "list")
for (i in 1:length(fits)){
fits[[i]] <- flexsurvreg(Surv(years, status) ~ 1,
data = bosms3[bosms3$trans == i, ],
dist = "exp")
}
fits <- flexsurvreg_list(fits)
# Simulation model
hesim_dat <- hesim_data(strategies = strategies,
patients = patients)
fits_data <- expand(hesim_dat)
transmod <- create_IndivCtstmTrans(fits, input_data = fits_data,
trans_mat = tmat,
n = 2)
head(transmod$hazard(c(1, 2, 3)))
head(transmod$cumhazard(c(1, 2, 3)))
## Simulate disease progression and state probabilities together
transmod$sim_stateprobs(t = c(0, 5, 10))[t == 5]
## Simulate disease progression and state probabilities separately
disprog <- transmod$sim_disease(max_t = 10)
transmod$sim_stateprobs(t = c(0, 5, 10), disprog = disprog)[t == 5]