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)
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).
A rng_def object used to randomly draw samples of the parameters from suitable probability distributions.
Either (i) a list containing the values of parameters for random
number generation or (ii) parameter samples that have already been randomly
generated using eval_rng()
. In case (ii), rng_def
should be NULL
.
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.
An object of class model_def
created with define_model()
.
An object of class expanded_hesim_data expanded by patients and treatment strategies.
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.
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:
Input data: Objects of class expanded_hesim_data consisting of the treatment strategies and patient population.
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.
# 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)
# Model parameters
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
)
)
})
# Simulation
## Define the economic model
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
#> <int> <int> <num> <num> <num>
#> 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
#> <num> <num> <num> <num> <num> <num> <num>
#> 1: 0.7410758 0.18486974 0.06071355 0.013340912 0 0.5900978 0.4003033
#> 2: 0.8841936 0.08268479 0.02715473 0.005966853 0 0.8166672 0.1790396
#> 3: 0.7451720 0.18357772 0.06243799 0.008812269 0 0.5809175 0.4102444
#> 4: 0.8607228 0.10033510 0.03412572 0.004816379 0 0.7709489 0.2242206
#> s2_s4 s3_s1 s3_s2 s3_s3 s3_s4 s4_s1 s4_s2 s4_s3 s4_s4
#> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1: 0.009598896 0 0 0.7511341 0.2488659 0 0 0 1
#> 2: 0.004293200 0 0 0.8886923 0.1113077 0 0 0 1
#> 3: 0.008838098 0 0 0.7429604 0.2570396 0 0 0 1
#> 4: 0.004830496 0 0 0.8595140 0.1404860 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
#> <num> <num> <num>
#> 1: 96.51387 14843.617 15404.23
#> 2: 96.51387 14843.617 15404.23
#> 3: 2373.02664 1090.711 13432.20
#> 4: 2373.02664 1090.711 13432.20
#>
#>
#> $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)