An R6 class for a variable in a health economic model.
Andrew Sims andrew.sims@newcastle.ac.uk
new()Create an object of type ModVar.
ModVar$new(description, units, D = NULL, k = as.integer(1))descriptionA character string description of the variable and its role in the model. This description will be used in a tabulation of the variables linked to a model.
unitsA character string description of the units, e.g.
"GBP", "per year".
DThe distribution representing the uncertainty in the variable.
Should inherit from class Distribution, or NULL if none is
defined.
kThe index of the dimension of the multivariate distribution that applies to this model variable.
A ModVar is associated with an uncertainty distribution
(a "has-a" relationship in object-oriented terminology). There can be a
1-1 mapping of ModVars to Distributions, or several
model variables can be linked to the same distribution in a
many-1 mapping, e.g. when each transition probability from a Markov state
is represented as a ModVar and each can be linked to the k
dimensions of a common multivariate Dirichlet distribution.
A new ModVar object.
is_expression()Is this ModVar an expression?
ModVar$is_expression()TRUE if it inherits from ExprModVar, FALSE
otherwise.
is_probabilistic()Is the model variable probabilistic?
ModVar$is_probabilistic()Tests whether the model variable is probabilistic, i.e. a random variable that follows a distribution, or an expression involving random variables, some of which follow distributions.
TRUE if probabilistic
description()Accessor function for the description.
ModVar$description()Description of model variable as character string.
Description of units as character string.
distribution()Name and parameters of the uncertainty distribution.
ModVar$distribution()If \(K > 1\) the dimension of the distribution associated
with this model variable is appended, e.g. Dir(2,3)[1]
means that the model variable is associated with the first dimension
of a 2D Dirichlet distribution with alpha parameters 2 and 3.
Distribution name as character string.
Mean value as a numeric value.
By default returns NA, which will be the case for
most ModVar variables, because arbitrary distributions are
not guaranteed to be unimodal.
Mode as a numeric value.
SD()Standard deviation of the model variable.
ModVar$SD()Standard deviation as a numeric value
probsNumeric vector of probabilities, each in range [0,1].
Vector of numeric values of the same length as probs.
r()Draw a random sample from the model variable.
ModVar$r()The same random sample will be returned until set is
called to force a resample.
A sample drawn at random.
set()Sets the value of the ModVar.
ModVar$set(what = "random", val = NULL)whatUntil set is called again, subsequent calls to
get will return a value determined by the what parameter
as follows:
"random"a random sample is drawn from the uncertainty distribution;
"expected"the mean of the uncertainty distribution;
"q2.5"the lower 95% confidence limit of the uncertainty distribution, i.e. the 2.5th percentile;
"q50"the median of the uncertainty distribution;
"q97.5"the upper 95% confidence limit of the uncertainty distribution, i.e. the 97.5th percentile;
"current"leaves the what parameter of method
set unchanged, i.e. the call to set has no effect on the
subsequent values returned by get. It is provided as an option to
help use cases in which the what parameter is a variable;
"value"sets the value explicitly to be equal to parameter
val. This is not recommended for normal usage because it allows
the model variable to be set to an implausible value, based on its
defined uncertainty. An example of where this may be needed is in
threshold finding.
valA numeric value, only used with what="value",
ignored otherwise.
Updated ModVar.
Returns the value defined by the most recent call
to set().
Value determined by last set().
clone()The objects of this class are cloneable with this method.
ModVar$clone(deep = FALSE)deepWhether to make a deep clone.
Base class for a variable used in a health economic model. The base class wraps a numerical value which is used in calculations. It provides a framework for creating classes of model variables whose uncertainties are described by statistical distributions parametrized with hyperparameters.