Learn R Programming

hesim (version 0.2.3)

IndivCtstmTrans: Transitions for an individual-level continuous time state transition model

Description

Summarize health state transitions in an individual-level continuous time state transition model with parameters that were estimated using a multi-state model.

Usage

IndivCtstmTrans

Arguments

Format

R6Class object.

Fields

input_mats

Input matrices used to simulate health state transitions by treatment strategy and patient. Must be an object of class input_mats. If params is a list of models, then input_mats must contain a unique row for each treatment strategy and patient; if params is a joint model, then input_mats must contain a unique row for each treatment strategy, patient, and transition.

params

An object of class params_surv or params_surv_list.

trans_mat

A transition matrix describing the states and transitions in a multi-state model in the format from the mstate package. See the documentation for the argument "trans" in msprep.

start_state

A 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.

clock

"reset" for a clock-reset model, "forward" for a clock-forward model, and "mix" for a mixture of clock-reset and clock-forward models. 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, then reset_states must be specified.

reset_states

A 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".

start_age

A 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_state

The death state in trans_mat. Used with max_age in sim_disease as patients transition to this state upon reaching maximum age. By default, it is set to the final absorbing state (i.e., a row in trans_mat with all NAs).

Methods

new(input_mats, params, trans_mat, start_state = 1, start_age = 38, death_state = NULL, clock = c("reset", "forward", "mix"), reset_states = NULL))

Constructor for the class.

hazard(t)

Predict the hazard functions for each health state transition.

  • t: A numeric vector of times.

cumhazard(t)

Predict the cumulative hazard functions for each health state transition.

  • t: A numeric vector of times.

,

sim_stateprobs(t, ...)

Simulate health state probabilities at distinct times.

  • t: A numeric vector of times.

  • ...: Additional arguments to pass to sim_disease.

Returns a data.table with the following columns:

sample

A random sample from the PSA.

strategy_id

The treatment strategy ID.

state_id

The health state ID.

t

The time at which a state probability is computed.

prob

The probability of being in a given health state.

check()

Input validation for class. Checks that fields are the correct type.

See Also

create_IndivCtstmTrans, IndivCtstm

Examples

Run this code
# NOT RUN {
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,
                                    point_estimate = FALSE)       
head(transmod$hazard(c(1, 2, 3)))
head(transmod$cumhazard(c(1, 2, 3)))
transmod$sim_stateprobs(t = c(0, 5, 10))[t == 5]
# }

Run the code above in your browser using DataLab