Random number generation expressions are used to
randomly sample model parameters from suitable distributions for probabilistic
sensitivity analysis. These functions are typically used when evaluating
an object of class model_def
defined using define_model()
.
define_rng(expr, n = 1, ...) eval_rng(x, params = NULL, check = FALSE)
expr  An expression used to randomly draw variates for each parameter of
interest in the model. Braces should be used so that the result
of the last expression within the braces is evaluated. The expression must
return a list where each element is either a 

n  Number of samples of the parameters to draw. 
...  Additional arguments to pass to the environment used to evaluate

x  An object of class 
params  A list containing the values of parameters for random number
generation. Each element of the list should either be a 
check  Whether to check the returned output so that (i) it returns a list
and (ii) each element has the correct length or number of rows. Default is 
define_rng()
returns an object of class rng_def
,
which is a list containing the unevaluated random number generation
expressions passed to expr
, n
, and any additional arguments passed to
...
. eval_rng()
evaluates the rng_def
object and should return a list.
hesim
contains a number of random number generation functions
that return parameter samples in convenient formats
and do not require the number of samples, n
, as arguments
(see rng_distributions). The random number generation expressions
are evaluated using eval_rng()
and used within expr
in define_rng()
. If multivariate object is returned by eval_rng()
,
then the rows are random samples and columns are
distinct parameters (e.g., costs for each health state, elements of a
transition probability matrix).
params < list( alpha = matrix(c(75, 25, 33, 67), byrow = TRUE, ncol = 2), inptcost_mean = c(A = 900, B = 1500, C = 2000), outptcost_mean = matrix(c(300, 600, 800, 400, 700, 700), ncol = 3, byrow = TRUE) ) rng_def < define_rng({ aecost_mean < c(500, 800, 1000) # Local object not # not returned by eval_rng() list( # Sampled values of parameters returned by eval_rng() p = dirichlet_rng(alpha), # Default column names inptcost = gamma_rng(mean = inptcost_mean, # Column names based on sd = inptcost_mean), # named vector outptcost = outptcost_mean, # No column names because # outptcost_mean has none. aecost = gamma_rng(mean = aecost_mean, # Explicit naming of columns sd = aecost_mean, names = aecost_colnames) ) }, n = 2, aecost_colnames = c("A", "B", "C")) # Add aecost_colnames to environment eval_rng(x = rng_def, params)#> $p #> s1_s1 s1_s2 s2_s1 s2_s2 #> 1: 0.7641322 0.2358678 0.3216384 0.6783616 #> 2: 0.7717676 0.2282324 0.3332963 0.6667037 #> #> $inptcost #> A B C #> 1: 233.0313 2524.334 1931.8009 #> 2: 1374.0879 2499.035 134.1758 #> #> $outptcost #> [,1] [,2] [,3] #> [1,] 300 600 800 #> [2,] 400 700 700 #> #> $aecost #> A B C #> 1: 883.7757 2086.364 855.9896 #> 2: 623.5611 1062.843 1898.9403 #>