A model expression is defined by specifying random number generation functions for a probabilistic sensitivity analysis (PSA) and transformations of the sampled parameters as a function of input_data. The unevaluated expressions are evaluated with eval_model() and used to generate the model inputs needed to create an economic model.

define_model(tparams_def, rng_def, params = NULL, n_states = NULL)

eval_model(x, input_data)

Arguments

tparams_def

A tparams_def object or a list of tparams_def objects. A list might be considered if time intervals specified with the times argument in define_tparams() vary across parameters. Parameters for a transition probability matrix (tpmatrix), utilities (utility), and/or cost categories (costs) are returned as a named list (see define_tparams() for more details).

rng_def

A rng_def object used to randomly draw samples of the parameters from suitable probability distributions.

params

A list containing the values of parameters for random number generation.

n_states

The number of health states (inclusive of all health states including the the death state) in the model. If tpmatrix is an element returned by tparams_def, then it will be equal to the number of states in the transition probability matrix; otherwise it must be specified as an argument.

x

An object of class model_def created with define_model().

input_data

An object of class expanded_hesim_data expanded by patients and treatment strategies.

Value

define_model() returns an object of class model_def, which is a list containing the arguments to the function. eval_model() returns a list containing ID variables identifying parameter samples, treatment strategies, patient cohorts, and time intervals; the values of parameters of the transition probability matrix, utilities, and/or cost categories; the number of health states; and the number of random number generation samples for the PSA.

Details

eval_model() evaluates the expressions in an object of class model_def returned by define_model() and is, in turn, used within functions that instantiate economic models (e.g., create_CohortDtstm()). The direct output of eval_model() can also be useful for understanding and debugging model definitions, but it is not used directly for simulation.

Economic models are constructed as a function of input data and parameters:

  1. Input data: Objects of class expanded_hesim_data consisting of the treatment strategies and patient population.

  2. Parameters: The underlying parameter estimates from the literature are first stored in a list (params argument). Random number generation is then used to sample the parameters from suitable probability distributions for the PSA (rng_def argument). Finally, the sampled parameters are transformed as a function of the input data into values (e.g., elements of a transition probability matrix) used for the simulation (tparams_def argument). The params argument can be omitted if the underlying parameters values are defined inside a define_rng() block.

See also

Examples

# Data library("data.table") strategies <- data.table(strategy_id = 1:2, strategy_name = c("Monotherapy", "Combination therapy")) patients <- data.table(patient_id = 1) hesim_dat <- hesim_data(strategies = strategies, patients = patients) data <- expand(hesim_dat) # Define the model rng_def <- define_rng({ alpha <- matrix(c(1251, 350, 116, 17, 0, 731, 512, 15, 0, 0, 1312, 437, 0, 0, 0, 469), nrow = 4, byrow = TRUE) rownames(alpha) <- colnames(alpha) <- c("A", "B", "C", "D") lrr_mean <- log(.509) lrr_se <- (log(.710) - log(.365))/(2 * qnorm(.975)) list( p_mono = dirichlet_rng(alpha), rr_comb = lognormal_rng(lrr_mean, lrr_se), u = 1, c_zido = 2278, c_lam = 2086.50, c_med = gamma_rng(mean = c(A = 2756, B = 3052, C = 9007), sd = c(A = 2756, B = 3052, C = 9007)) ) }, n = 2) tparams_def <- define_tparams({ rr = ifelse(strategy_name == "Monotherapy", 1, rr_comb) list( tpmatrix = tpmatrix( C, p_mono$A_B * rr, p_mono$A_C * rr, p_mono$A_D * rr, 0, C, p_mono$B_C * rr, p_mono$B_D * rr, 0, 0, C, p_mono$C_D * rr, 0, 0, 0, 1), utility = u, costs = list( drug = ifelse(strategy_name == "Monotherapy", c_zido, c_zido + c_lam), medical = c_med ) ) }) model_def <- define_model( tparams_def = tparams_def, rng_def = rng_def) # Evaluate the model expression to generate model inputs # This can be useful for understanding the output of a model expression eval_model(model_def, data)
#> $id #> $id[[1]] #> sample strategy_id patient_id time time_start #> 1: 1 1 1 0 0 #> 2: 1 2 1 0 0 #> 3: 2 1 1 0 0 #> 4: 2 2 1 0 0 #> #> #> $tpmatrix #> s1_s1 s1_s2 s1_s3 s1_s4 s2_s1 s2_s2 s2_s3 #> 1: 0.7248738 0.20213870 0.06375945 0.009228045 0 0.5764863 0.4142595 #> 2: 0.8910632 0.08003726 0.02524570 0.003653865 0 0.8323088 0.1640269 #> 3: 0.7130353 0.20425966 0.07500436 0.007700719 0 0.5765460 0.4021009 #> 4: 0.8542749 0.10372617 0.03808835 0.003910542 0 0.7849636 0.2041929 #> s2_s4 s3_s1 s3_s2 s3_s3 s3_s4 s4_s1 s4_s2 s4_s3 s4_s4 #> 1: 0.009254252 0 0 0.7599022 0.24009785 0 0 0 1 #> 2: 0.003664242 0 0 0.9049327 0.09506727 0 0 0 1 #> 3: 0.021353143 0 0 0.7679710 0.23202901 0 0 0 1 #> 4: 0.010843451 0 0 0.8821721 0.11782787 0 0 0 1 #> #> $utility #> [1] 1 1 1 1 #> attr(,"id_index") #> [1] 1 #> #> $costs #> $costs$drug #> [1] 2278.0 4364.5 2278.0 4364.5 #> attr(,"id_index") #> [1] 1 #> #> $costs$medical #> A B C #> 1: 1190.217 314.6723 655.1127 #> 2: 1190.217 314.6723 655.1127 #> 3: 3703.264 540.9411 3509.7679 #> 4: 3703.264 540.9411 3509.7679 #> #> #> $n_states #> [1] 4 #> #> $n #> [1] 2 #> #> attr(,"class") #> [1] "eval_model"
# Create an economic model with a factory function econmod <- create_CohortDtstm(model_def, data)