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.7303831 0.18679555 0.07260427 0.010217072 0 0.6025887 0.3872602
#> 2: 0.8823737 0.08149364 0.03167520 0.004457421 0 0.8266206 0.1689507
#> 3: 0.7129687 0.20776387 0.06806632 0.011201099 0 0.6137990 0.3760511
#> 4: 0.8859624 0.08254467 0.02704278 0.004450201 0 0.8465622 0.1494053
#> 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.010151107 0 0 0.7420537 0.2579463 0 0 0 1
#> 2: 0.004428642 0 0 0.8874653 0.1125347 0 0 0 1
#> 3: 0.010149909 0 0 0.7463815 0.2536185 0 0 0 1
#> 4: 0.004032563 0 0 0.8992373 0.1007627 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: 1463.6975 1262.136 15708.566
#> 2: 1463.6975 1262.136 15708.566
#> 3: 293.2644 4551.563 7743.327
#> 4: 293.2644 4551.563 7743.327
#>
#>
#> $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)