Learn R Programming

hesim (version 0.2.0)

IndivCtstm: Individual-level continuous time state transition model

Description

Simulate outcomes from an individual-level continuous time state transition model (CTSTM). The class supports "clock-reset" (i.e., semi-Markov), "clock-forward" (i.e., Markov), and mixtures of clock-reset and clock-forward models as described in IndivCtstmTrans.

Usage

IndivCtstm

Arguments

Format

R6Class object.

Fields

trans_model

Model for health state transitions. Must be an object of class IndivCtstmTrans.

utility_model

The model used to predict utility by health state. Must be an object of class StateVals.

cost_models

The models used to predict costs by health state. Must be a list of objects of class StateVals, where each element of the list represents a different cost category.

disprog_

A data.table simulated using sim_disease containing the following columns:

sample

A random sample from the PSA.

strategy_id

The treatment strategy ID.

patient_id

The patient ID.

from

The health state ID transitioned from.

to

The health state ID transitioned to.

final

An indicator equal to 1 if a patient is in their final health state during the simulation and 0 otherwise.

time_start

The time at the start of the interval.

time_stop

The time at the end of the interval.

stateprobs_

A data.table of health state probabilities as a function of time simulated using sim_stateprobs. See the description of the output of sim_stateprobs in IndivCtstmTrans.

qalys_

A data.table of quality-adjusted life-years (QALYs) simulated using sim_qalys. Columns are:

sample

A random sample from the probabilistic sensitivity analysis (PSA).

strategy_id

The treatment strategy ID.

patient_id

A patient ID.

dr

The discount rate.

qalys

Simulated QALYs.

lys

Simulated life-years.

Note that the lys column is only computed if lys = TRUE.

costs_

A data.table of costs by category simulated using sim_costs. Columns are:

sample

A random sample from the PSA.

strategy_id

The treatment strategy ID.

patient_id

A patient ID.

dr

The discount rate.

category

The cost category.

costs

Simulated costs.

Methods

new(trans_model = NULL, utility_model = NULL, cost_models = NULL)

Constructor for the class.

sim_disease(max_t = 100, max_age = 100, progress = NULL)

Simulate disease progression.

  • max_t: A scalar or vector denoting the number of time periods to simulate the model. If a vector, must be equal to the number of simulated patients.

  • max_age: A scalar or vector denoting the maximum age to simulate each patient until. If a vector, must be equal to the number of simulated patients.

  • progress: An 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 instance of self with simulated output stored in disprog_.

sim_stateprobs(t)

Simulate the probability of being in each health state as a function of time using the simulation output stored in disprog_.

  • t: A numeric vector of times.

Returns an instance of self with simulated output stored in stateprobs_.

sim_qalys(dr = .03, type = c("predict", "random"), by_patient = FALSE, lys = TRUE)

Compute simulated (mean discounted) QALYs using the simulation output stored in disprog_ by random sample from the PSA, treatment strategy, health state, and (optionally) patient.

  • dr: Discount rate to apply to QALYs. May be a vector in which case QALYs are calculated for each element in dr.

  • type: predict for mean values or random for random samples as in $sim() in StateVals.

  • by_patient: If TRUE, QALYs are computed at the patient level. If FALSE, QALYs are averaged across patients by health state.

  • lys: If TRUE, then life-years are computed in addition to QALYs.

Returns an instance of self with simulated output stored in qalys_.

sim_costs(dr = .03, type = c("predict", "random"), by_patient = FALSE, max_t = Inf)

Compute simulated (mean discounted) costs using the simulation output stored in disprog_ by random sample from the PSA, treatment strategy, health state, and (optionally) patient.

  • dr: Discount rate to apply to costs. May be a vector in which case costs are calculated for each element in dr.

  • type: predict for mean values or random for random samples as in $sim() in StateVals.

  • by_patient: If TRUE, costs are computed at the patient level. If FALSE, costs are averaged across patients by health state.

  • max_t: Maximum time duration to compute costs once a patient has entered a (new) health state. By default, equal to Inf, so that costs are computed over the entire duration that a patient is in a given health state. If time varies by each cost category, then time can also be passed as a numeric vector of length equal to the number of cost categories (e.g., c(1, 2, Inf, 3) for a model with 4 cost categories).

Returns an instance of self with simulated output stored in costs_.

,

summarize()

Summarize costs and QALYs so that cost-effectiveness analysis can be performed. See summarize_ce.

See Also

create_IndivCtstmTrans, IndivCtstmTrans

Examples

Run this code
# NOT RUN {
library("flexsurv")

# Treatment strategies, target population, and model structure
strategies <- data.frame(strategy_id = c(1, 2))
patients <- data.frame(patient_id = seq(1, 3),
                          age = c(45, 50, 60),
                          female = c(0, 0, 1))
states <- data.frame(state_id = c(1, 2))
hesim_dat <- hesim_data(strategies = strategies,
                        patients = patients,
                        states = states)

# Parameter estimation
## Multi-state model
tmat <- rbind(c(NA, 1, 2),
              c(3, NA, 4),
              c(NA, NA, NA))
fits <- vector(length = max(tmat, na.rm = TRUE), mode = "list")
surv_dat <- data.frame(ctstm3_exdata$transitions)
for (i in 1:length(fits)){
  fits[[i]] <- flexsurvreg(Surv(years, status) ~ factor(strategy_id), 
                           data = surv_dat,
                           subset = (trans == i),
                           dist = "weibull")
}
fits <- flexsurvreg_list(fits)

## Utility
utility_tbl <- stateval_tbl(data.frame(state_id = states$state_id,
                                       mean = ctstm3_exdata$utility$mean,
                                       se = ctstm3_exdata$utility$se),
                            dist = "beta",
                            hesim_data = hesim_dat)
## Costs
drugcost_tbl <- stateval_tbl(data.frame(strategy_id = strategies$strategy_id,
                                       est = ctstm3_exdata$costs$drugs$costs),
                            dist = "fixed",
                            hesim_data = hesim_dat) 
medcost_tbl <- stateval_tbl(data.frame(state_id = states$state_id,
                                       mean = ctstm3_exdata$costs$medical$mean,
                                       se = ctstm3_exdata$costs$medical$se),
                            dist = "gamma",
                            hesim_data = hesim_dat)  

# Economic model
n_samples = 2

## Construct model
### Transitions 
transmod_data <- expand(hesim_dat)
transmod <- create_IndivCtstmTrans(fits, input_data = transmod_data, 
                                   trans_mat = tmat,
                                   n = n_samples)
                        
### Utility 
utilitymod <- create_StateVals(utility_tbl, n = n_samples)

### Costs
drugcostmod <- create_StateVals(drugcost_tbl, n = n_samples)
medcostmod <- create_StateVals(medcost_tbl, n = n_samples)
costmods <- list(drugs = drugcostmod,
                 medical = medcostmod)
                 
### Combine
ictstm <- IndivCtstm$new(trans_model = transmod,
                         utility_model = utilitymod,
                         cost_models = costmods)


## Simulate outcomes
head(ictstm$sim_disease()$disprog_)
head(ictstm$sim_stateprobs(t = c(0, 5, 10))$stateprobs_[t == 5])
ictstm$sim_qalys(dr = .03)
ictstm$sim_costs(dr = .03)
head(ictstm$summarize())
# }

Run the code above in your browser using DataLab