| Title: | Decision Analytic Modelling in Health Economics |
|---|---|
| Description: | Classes and functions for modelling health care interventions using decision trees and semi-Markov models. Mechanisms are provided for associating an uncertainty distribution with each source variable and for ensuring transparency of the mathematical relationships between variables. The package terminology follows Briggs "Decision Modelling for Health Economic Evaluation" (2006, ISBN:978-0-19-852662-9). |
| Authors: | Andrew Sims [aut, cre] (ORCID: <https://orcid.org/0000-0002-9553-7278>), Kim Keltie [aut] (ORCID: <https://orcid.org/0000-0001-5108-6279>), Paola Cognigni [aut] (ORCID: <https://orcid.org/0000-0001-5418-3103>) |
| Maintainer: | Andrew Sims <[email protected]> |
| License: | GPL-3 |
| Version: | 1.3.0.9001 |
| Built: | 2026-05-28 06:12:12 UTC |
| Source: | https://github.com/ajsims1704/rdecision |
R6 class representing an action (choice) edge.
A specialism of class Arrow which is used in a decision tree
to represent an edge whose source node is a DecisionNode.
Action$new()Create an object of type Action. Optionally, a cost
and a benefit may be associated with traversing the edge. A pay-off
(benefit minus cost) is sometimes used in edges of decision trees; the
parametrization used here is more general.
Action$new(source_node, target_node, label, cost = 0, benefit = 0)
source_nodeDecision node from which the arrow leaves.
target_nodeNode to which the arrow points.
labelCharacter string containing the arrow label. This must be defined for an action because the label is used in tabulation of strategies. It is recommended to choose labels that are brief and not punctuated with spaces, dots or underscores.
costCost associated with traversal of this edge (numeric or
ModVar), not NA.
benefitBenefit associated with traversal of the edge, (numeric or
ModVar), not NA.
A new Action object.
Action$grob()Creates a grid::grob for an action edge.
Action$grob(xs, ys, xt, yt, fs = 0.2)
xsx coordinate of source of edge, grid::unit object.
ysy coordinate of source of edge, grid::unit object.
xtx coordinate of target of edge, grid::unit object.
yty coordinate of target of edge, grid::unit object.
fsFraction of the edge which slopes.
A grid::grob containing the symbol and label.
Action$modvars()Find all the model variables of type ModVar that have
been specified as values associated with this Action. Includes
operands of these ModVars, if they are expressions.
Action$modvars()
A list of ModVars.
Action$p()Return the current value of the edge probability, i.e., the conditional probability of traversing the edge.
Action$p()
Numeric value equal to 1.
Action$set_cost()Set the cost associated with the action edge.
Action$set_cost(c = 0)
cCost associated with traversing the action edge. Of type numeric
or ModVar, not NA.
Updated Action object.
Action$cost()Return the cost associated with traversing the edge.
Action$cost()
Cost.
Action$set_benefit()Set the benefit associated with the action edge.
Action$set_benefit(b = 0)
bBenefit associated with traversing the action edge. Of type
numeric or ModVar.
Updated Action object.
Action$benefit()Return the benefit associated with traversing the edge.
Action$benefit()
Benefit.
Action$clone()The objects of this class are cloneable with this method.
Action$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing an arborescence (a rooted directed tree).
Class to encapsulate a directed rooted tree specialization of a
digraph. An arborescence is a directed tree with exactly one root and
unique directed paths from the root. Inherits from class Digraph.
Graph -> Digraph -> Arborescence
Graph$degree()Graph$edge_along()Graph$edge_at()Graph$edge_index()Graph$edge_label()Graph$edges()Graph$graph_adjacency_matrix()Graph$has_edge()Graph$has_vertex()Graph$is_simple()Graph$neighbours()Graph$order()Graph$size()Graph$vertex_along()Graph$vertex_at()Graph$vertex_index()Graph$vertex_label()Graph$vertexes()Digraph$arrow_source()Digraph$arrow_target()Digraph$as_DOT()Digraph$as_gml()Digraph$digraph_adjacency_matrix()Digraph$digraph_incidence_matrix()Digraph$direct_predecessors()Digraph$direct_successors()Digraph$is_acyclic()Digraph$is_arborescence()Digraph$is_connected()Digraph$is_polytree()Digraph$is_tree()Digraph$is_weakly_connected()Digraph$paths()Digraph$topological_sort()Digraph$walk()Arborescence$new()Create a new Arborescence object from sets of nodes
and edges.
Arborescence$new(V, A)
VA list of Nodes.
AA list of Arrows.
An Arborescence object.
Arborescence$parent()Find the parent of a Node.
Arborescence$parent(v)
vIndex node, or a list of index Nodes.
A list of Nodes of the same length as v, if v is a list, or a scalar Node if v is a single node. NA if v (or an element of v) is the root node.
Arborescence$is_parent()Test whether the given node(s) is (are) parent(s).
Arborescence$is_parent(v)
vNode to test, or a list of Nodes.
In an arborescence, is_parent() and is_leaf() are
mutually exclusive.
A logical vector of the same length as v, if v is a list, or a logical scalar if v is a single node.
Arborescence$is_leaf()Test whether the given node is a leaf.
Arborescence$is_leaf(v)
vNode to test, or a list of Nodes.
In an arborescence, is_parent() and is_leaf() are
mutually exclusive.
A logical vector of the same length as v, if v is a list, or a logical scalar is v is a single node.
Arborescence$root()Find the root vertex of the arborescence.
Arborescence$root()
The root vertex.
Arborescence$is_root()Is the specified node the root?
Arborescence$is_root(v)
vVertex to test, or list of vertexes
A logical vector if v is a list, or a logical scalar if v is a single node.
Arborescence$siblings()Find the siblings of a vertex in the arborescence.
Arborescence$siblings(v)
vVertex to test (only accepts a scalar Node).
A (possibly empty) list of siblings.
Arborescence$root_to_leaf_paths()Find all directed paths from the root of the tree to the leaves.
Arborescence$root_to_leaf_paths()
A list of ordered node lists.
Arborescence$postree()Implements function POSITIONTREE (Walker, 1989) to
determine the coordinates for each node in an arborescence.
Arborescence$postree( SiblingSeparation = 4, SubtreeSeparation = 4, LevelSeparation = 1, RootOrientation = "SOUTH", MaxDepth = Inf )
SiblingSeparationDistance in arbitrary units for the distance between siblings.
SubtreeSeparationDistance in arbitrary units for the distance between neighbouring subtrees.
LevelSeparationDistance in arbitrary units for the separation between adjacent levels.
RootOrientationMust be one of "NORTH", "SOUTH", "EAST", "WEST". Defined as per Walker (1989), but noting that Walker assumed that y increased down the page. Thus the meaning of NORTH and SOUTH are opposite to his, with the default (SOUTH) having the child nodes at positive y value and root at zero, as per his example (figure 12).
MaxDepthThe maximum depth (number of levels) to be drawn; if the tree exceeds this, an error will be raised.
In the rdecision implementation, the
sibling order is taken to be the lexicographic order of the node
labels, if they are unique among siblings, or the node indexes otherwise.
A data frame with one row per node and three columns (n, x
and y) where n gives the node index given by the
Graph::vertex_index() function.
Arborescence$clone()The objects of this class are cloneable with this method.
Arborescence$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
Walker, John Q II. A A node-positioning algorithm for general trees. University of North Carolina Technical Report TR 89-034, 1989.
An R6 class representing an directed edge in a digraph.
An arrow is the formal term for an edge between pairs of nodes in a
directed graph. Inherits from class Edge.
Edge -> Arrow
Arrow$new()Create an object of type Arrow.
Arrow$new(source_node, target_node, label = "")
source_nodeNode from which the arrow leaves.
target_nodeNode to which the arrow points.
labelCharacter string containing the arrow label.
A new Arrow object.
Arrow$source()Access source node.
Arrow$source()
Node from which the arrow leads.
Arrow$target()Access target node.
Arrow$target()
Node to which the arrow points.
Arrow$clone()The objects of this class are cloneable with this method.
Arrow$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing a Beta distribution with parameters.
A Beta distribution with hyperparameters for shape (alpha
and beta). Inherits from class Distribution.
Distribution -> BetaDistribution
BetaDistribution$new()Create an object of class BetaDistribution.
BetaDistribution$new(alpha, beta)
alphaparameter of the Beta distribution.
betaparameter of the Beta distribution.
An object of class BetaDistribution.
BetaDistribution$distribution()Accessor function for the name of the uncertainty distribution.
BetaDistribution$distribution()
Distribution name as character string.
BetaDistribution$mean()The expected value of the distribution.
BetaDistribution$mean()
Expected value as a numeric value.
BetaDistribution$mode()The mode of the distribution (if
alpha, beta > 1)
BetaDistribution$mode()
mode as a numeric value.
BetaDistribution$SD()The standard deviation of the distribution.
BetaDistribution$SD()
Standard deviation as a numeric value
BetaDistribution$sample()Draw and hold a random sample from the model variable.
BetaDistribution$sample(expected = FALSE)
expectedIf TRUE, sets the next value retrieved by a call to
r() to be the mean of the distribution.
Updated distribution.
BetaDistribution$quantile()The quantiles of the Beta distribution.
BetaDistribution$quantile(probs)
probsVector of probabilities, in range [0,1].
Vector of quantiles.
BetaDistribution$clone()The objects of this class are cloneable with this method.
BetaDistribution$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing a model variable whose uncertainty is described by a Beta distribution.
A model variable for which the uncertainty in the point estimate can
be modelled with a Beta distribution. The hyperparameters of the
distribution are the shape parameters (alpha and beta) of
the uncertainty distribution. Inherits from class ModVar.
ModVar -> BetaModVar
BetaModVar$new()Create an object of class BetaModVar.
BetaModVar$new(description, units, alpha, beta)
descriptionA character string describing the variable.
unitsUnits of the variable, as character string.
alphaparameter of the Beta distribution.
betaparameter of the Beta distribution.
An object of class BetaModVar.
BetaModVar$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.
BetaModVar$is_probabilistic()
TRUE if probabilistic
BetaModVar$clone()The objects of this class are cloneable with this method.
BetaModVar$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
A dataset containing PSA results of Briggs example 2.5.
data(BriggsEx47)data(BriggsEx47)
A data frame with 1000 rows and 7 columns:
Life years gained with monotherapy
Incremental cost with monotherapy, in GBP
Life years gained with combination therapy
Incremental cost with combination therapy, in GBP
Difference in life years gained
Difference in incremental cost, GBP
Incremental cost effectiveness ratio, GBP/QALY
A dataset containing the results of probabilistic sensitivity analysis of Briggs (2006) example 2.5 (HIV model), provided as Example 4.7 in the book. These data were generated from the solution spreadsheet provided as a companion to the book (Exercise 4.7 solution) via an Excel macro written to record 1000 runs of the model.
https://www.herc.ox.ac.uk/downloads/decision-modelling-for-health-economic-evaluation/
Briggs A, Claxton K, Sculpher M. Decision modelling for health economic evaluation. Oxford, UK: Oxford University Press; 2006.
An R6 class representing a chance node in a decision tree.
A chance node is associated with at least two branches to other
nodes, each of which has a conditional probability (the probability of
following that branch given that the node has been reached). Inherits from
class Node.
Node -> ChanceNode
ChanceNode$new()Create a new ChanceNode object
ChanceNode$new(label = "")
labelAn optional label for the chance node.
A new ChanceNode object
ChanceNode$grob()Creates a grid::grob for a chance node.
ChanceNode$grob(x, y, bb = FALSE)
xx coordinate of the node, grid::unit object.
yy coordinate of the node, grid::unit object.
bbLogical. If TRUE, function returns the bounding box.
A grob containing the symbol and label, or a bounding box as a grid::unit vector with elements: left, right, bottom, top.
ChanceNode$clone()The objects of this class are cloneable with this method.
ChanceNode$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
An R6 class representing a constant in a model.
A ModVar with no uncertainty in its value. Its distribution
is treated as a Dirac delta function where is the
hyperparameter (value of the constant). The benefit over
using a regular numeric variable in a model is that it will appear in
tabulations of the model variables associated with a model and therefore be
explicitly documented as a model input. Inherits from class ModVar.
ModVar -> ConstModVar
ConstModVar$new()Create a new constant model variable.
ConstModVar$new(description, units, const)
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".
constThe constant numerical value of the object.
A new ConstModVar object.
ConstModVar$is_probabilistic()Tests whether the model variable is probabilistic.
ConstModVar$is_probabilistic()
Does the random variable follow a distribution, or is it an expression involving' random variables, some of which follow distributions?
TRUE if probabilistic
ConstModVar$clone()The objects of this class are cloneable with this method.
ConstModVar$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
An R6 class representing a decision node in a decision tree.
A class to represent a decision node in a decision tree. The node
is associated with one or more branches to child nodes. Inherits from class
Node.
Node -> DecisionNode
DecisionNode$new()Create a new decision node.
DecisionNode$new(label)
labelA label for the node. Must be defined because the label is used in tabulation of strategies. The label is automatically converted to a syntactically valid (in R) name to ensure it can be used as a column name in a data frame.
A new DecisionNode object.
DecisionNode$grob()Creates a grid::grob for drawing a decision node.
DecisionNode$grob(x, y, bb = FALSE)
xx coordinate of the node, unit object.
yy coordinate of the node, unit object.
bbLogical. If TRUE, function returns the bounding box.
A grob containing the symbol and label, or a bounding box as a grid::unit vector with 4 values: left, right, bottom, top.
DecisionNode$clone()The objects of this class are cloneable with this method.
DecisionNode$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class to represent a decision tree model.
A DecisionTree object contains decision nodes, chance nodes and leaf
nodes, connected by edges (either actions or reactions). It inherits from
class Arborescence and satisfies the following conditions:
Nodes and edges must form a tree with a single root and there must be a unique path from the root to each node. In graph theory terminology, the directed graph formed by the nodes and edges must be an arborescence.
Each node must inherit from one of DecisionNode,
ChanceNode or LeafNode. Formally the set of vertices
must be a disjoint union of sets of decision nodes, chance nodes
and leaf nodes.
All and only leaf nodes must have no children.
Each edge must inherit from either Action or
Reaction.
All and only edges that have source endpoints joined to
decision nodes must inherit from Action.
All and only edges that have source endpoints joined to
chance nodes must inherit from Reaction.
The sum of probabilities of each set of reaction edges with a common source endpoint must be 1.
Each DecisionNode must have a label, and the labels of all
DecisionNodes must be unique within the model.
Each Action must have a label, and the labels of
Actions that share a common source endpoint must be unique.
The timing of events is not explicitly modelled in decision trees
(O'Mahony, 2015). rdecision makes the assumption that all costs are
incurred at time and that QALYs are gained during the
time intervals defined for each leaf node. Discounting of future costs to
present values is therefore not applicable. Future utilities may be
discounted to present values by setting a discount rate for
each leaf node (in usual circumstances the interval and discount rate should
be the same for each leaf node). The QALYs gained are calculated by
integrating the continuously discounted utility over the interval for each
leaf node.
Graph -> Digraph -> Arborescence -> DecisionTree
Graph$degree()Graph$edge_along()Graph$edge_at()Graph$edge_index()Graph$edge_label()Graph$edges()Graph$graph_adjacency_matrix()Graph$has_edge()Graph$has_vertex()Graph$is_simple()Graph$neighbours()Graph$order()Graph$size()Graph$vertex_along()Graph$vertex_at()Graph$vertex_index()Graph$vertex_label()Graph$vertexes()Digraph$arrow_source()Digraph$arrow_target()Digraph$as_DOT()Digraph$as_gml()Digraph$digraph_adjacency_matrix()Digraph$digraph_incidence_matrix()Digraph$direct_predecessors()Digraph$direct_successors()Digraph$is_acyclic()Digraph$is_arborescence()Digraph$is_connected()Digraph$is_polytree()Digraph$is_tree()Digraph$is_weakly_connected()Digraph$paths()Digraph$topological_sort()Digraph$walk()Arborescence$is_leaf()Arborescence$is_parent()Arborescence$is_root()Arborescence$parent()Arborescence$postree()Arborescence$root()Arborescence$root_to_leaf_paths()Arborescence$siblings()DecisionTree$new()Create a new decision tree.
DecisionTree$new(V, E)
VA list of nodes.
EA list of edges.
The tree must consist of a set of nodes and a set of edges
which satisfy the conditions given in the details section of this class.
In addition, the decision nodes must not be labelled with any of the
words used as the column headings listed in evaluate.
A DecisionTree object
DecisionTree$decision_nodes()Find the decision nodes in the tree.
DecisionTree$decision_nodes(what = "node")
whatA character string defining what to return. Must be one of "node", "label" or "index".
A list of DecisionNode objects (for what = "node"); a list
of character strings (for what = "label"), or an integer vector with
indexes of the decision nodes (for what = "index").
DecisionTree$chance_nodes()Find the chance nodes in the tree.
DecisionTree$chance_nodes(what = "node")
whatA character string defining what to return. Must be one of "node", "label" or "index".
A list of ChanceNode objects (for what = "node"); a list
of character strings (for what = "label"), or an integer vector with
indexes of the decision nodes (for what = "index").
DecisionTree$leaf_nodes()Find the leaf nodes in the tree.
DecisionTree$leaf_nodes(what = "node")
whatOne of "node" (returns Node objects), "label" (returns the leaf node labels) or "index" (returns the vertex indexes of the leaf nodes).
A list of LeafNode objects (for what = "node"); a list
of character strings (for what = "label"); or an integer vector of
leaf node indexes (for what = "index").
DecisionTree$actions()Find the edges that have the specified decision node as their source.
DecisionTree$actions(d)
dA decision node.
A list of Action edges.
DecisionTree$modvars()Find all the model variables of type ModVar.
DecisionTree$modvars()
Find ModVars that have been specified as values
associated with the nodes and edges of the tree.
A list of ModVars.
DecisionTree$modvar_table()Tabulate the model variables.
DecisionTree$modvar_table()
Data frame with one row per model variable, as follows:
DescriptionAs given at initialization.
UnitsUnits of the variable.
DistributionEither the uncertainty distribution, if
it is a regular model variable, or the expression used to create it,
if it is an ExprModVar.
MeanMean; calculated from means of operands if an expression.
EExpectation; estimated from random sample if expression, mean otherwise.
SDStandard deviation; estimated from random sample if expression, exact value otherwise.
Q2.5p=0.025 quantile; estimated from random sample if expression, exact value otherwise.
Q97.5p=0.975 quantile; estimated from random sample if expression, exact value otherwise.
EstTRUE if the quantiles and SD have been estimated by random sampling.
DecisionTree$draw()Draw the decision tree to the current graphics output.
DecisionTree$draw(border = FALSE, fontsize = 8)
borderIf TRUE draw a light grey border around the plot area.
fontsizeFont size for labels in point. Symbols for nodes scale with font size.
Uses the algorithm of Walker (1989) to distribute the nodes compactly (see the Arborescence class help for details).
No return value.
DecisionTree$is_strategy()Tests whether an object is a valid strategy.
DecisionTree$is_strategy(strategy)
strategyA list of Action edges, or a single Action edge for decision trees with one decision node.
A strategy is a unanimous prescription of an action taken at each decision node, coded as a list of action edges. This checks whether the strategy is valid for this decision tree.
TRUE if the strategy is valid for this tree. Returns FALSE if the list of Action edges are not a valid strategy.
DecisionTree$strategy_table()Find all potential strategies for the decision tree.
DecisionTree$strategy_table(what = "index", select = NULL)
whatA character string defining what to return. Must be one of "label" or "index".
selectA single strategy, given as a list of action edges, with one action edge per decision node, or as a single action edge if there is one decision node in the tree. If provided, only that strategy is selected from the returned table. Intended for tabulating a single strategy into a readable form.
A strategy is a unanimous prescription of the actions at each decision node. If there are decision nodes that are descendants of other nodes in the tree, the strategies returned will not necessarily be unique.
A data frame where each row is a potential strategy and each column is a decision node, ordered lexicographically. Values are either the index of each action edge, or their label. The row names are the edge labels of each strategy, concatenated with underscores.
DecisionTree$strategy_paths()Find all paths walked in each possible strategy.
DecisionTree$strategy_paths()
A strategy is a unanimous prescription of an action in each decision node. Some paths can be walked in more than one strategy, if there exist paths that do not pass a decision node.
A data frame, where each row is a path walked in a strategy. The
structure is similar to that returned by strategy_table but
includes an extra column, Leaf which gives the leaf node index of
each path, and there is one row for each path in each strategy.
DecisionTree$edge_properties()Properties of all actions and reactions as a matrix.
DecisionTree$edge_properties()
Gets the properties (probability, cost, benefit) of each action and reaction in the decision tree in matrix form. If there are reactions from chance nodes whose conditional probability of traversal set to NA, the missing values are replaced by one minus the sum of the conditional probabilities of the other reaction edges from that node (provided there is no more than one with NA). If the method is called at evaluation, the replacement of NAs happens after sampling from model variables.
A numeric matrix with one row per edge, and with four columns:
the index of the edge, the conditional probability of traversing the
edge, the cost of traversing the edge and the benefit associated with
traversing the edge. The column names are index,
probability, cost, benefit and the row names are
the labels of the edges.
DecisionTree$evaluate_walks()Evaluate the components of pay-off associated with a set of walks in the decision tree.
DecisionTree$evaluate_walks(W = NULL, Wi = NULL)
WA list of root-to-leaf walks. A walk is a sequence of edges (actions and reactions), stored as a list. Each walk must start with an edge whose source is the root node and end with an edge whose target is a leaf node. The list of walks is normally the walks associated with all the root to leaf paths in a tree.
WiAs W but with edge indices instead of Edge objects. One of W and Wi must be NULL. It is more efficient to provide Wi during PSA, where the paths do not change between cycles, to avoid repeated conversion of edges to indices.
For each walk, probability, cost, benefit and utility are calculated. There is minimal checking of the argument because this function is intended to be called repeatedly during tree evaluation, including PSA. Discounts are applied to calculate the present value of future costs and health effects.
A pay-off table, represented as a matrix of numeric values with response columns as follows:
ProbabilityThe probability of traversing the pathway.
Path.CostThe cost of traversing the pathway.
Path.BenefitThe benefit derived from traversing the pathway.
Path.UtilityThe utility associated with the outcome (leaf node).
Path.QALYThe QALYs associated with the outcome (leaf node).
CostPath.Cost probability of traversing the
pathway.
BenefitPath.Benefit probability of
traversing the pathway.
UtilityPath.Utility probability of
traversing the pathway.
QALYPath.QALY probability of traversing the
pathway.
The matrix has one row per path, with the row label equal to the character representation of the index of the leaf node at the end of the path.
DecisionTree$evaluate()Evaluate each strategy.
DecisionTree$evaluate(setvars = "expected", N = 1L, by = "strategy")
setvarsOne of "expected" (evaluate with each model variable at its mean value), "random" (sample each variable from its uncertainty distribution and evaluate the model), "q2.5", "q50", "q97.5" (set each model variable to its 2.5%, 50% or 97.5% quantile, respectively, and evaluate the model) or "current" (leave each model variable at its current value prior to calling the function and evaluate the model).
NNumber of replicates. Intended for use with PSA
(modvars = "random"); use with modvars = "expected"
will be repetitive and uninformative.
byOne of {"path", "strategy", "run"}. If "path", the table has one row per path walked per strategy, per run, and includes the label of the terminating leaf node to identify each path. If "strategy" (the default), the table is aggregated by strategy, i.e., there is one row per strategy per run. If "run", the table has one row per run and uses concatenated strategy names (as above) and one (cost, benefit, utility, QALY) as row names.
Starting with the root, the function works though all possible paths to leaf nodes and computes the probability, cost, benefit and utility of each, optionally aggregated by strategy or run. The columns of the returned data frame are:
by = "path"RunRun number
<label of first decision node>label of action leaving the node
<label of second decision node (etc.)>label of action leaving the node
LeafThe label of terminating leaf node
ProbabilityProbability of traversing the path
CostCost of traversing the path x probability
BenefitBenefit of traversing the path x probability
UtilityUtility of traversing the path x probability
QALYQALYs gained by those traversing the path
by = "strategy"RunRun number
<label of first decision node>label of action leaving the node
<label of second decision node (etc)label of action
Probability for the run (1)
CostAggregate cost of the strategy
BenefitAggregate benefit of the strategy
UtilityAggregate utility of the strategy
QALYAggregate QALY of the strategy
by = "run"RunRun number
Probability.<S>Probability for strategy S
Cost.<S>Cost for strategy S
Benefit.<S>Benefit for strategy S
Utility.<S>Benefit for strategy S
QALY.<S>QALY for strategy S
where <S> is a label associated with strategy S. Each strategy
label is
a list of the labels of the action edges that are traversed in the
strategy, concatenated with underscores. The ordering of each label
part follows the lexicographical order of the decision node labels
concatenated with underscores. For example, if there are three
decision nodes labelled d1, d2 and d3, each strategy label will be of
the form a1i_a2i_a3i where a1i is the label of one action edge
emanating from decision node d1, etc. There will be one probability,
cost, benefit, utility and QALY column for each strategy.
A data frame whose columns depend on by; see "Details".
DecisionTree$tornado()Create a "tornado" diagram.
DecisionTree$tornado( index, ref, outcome = "saving", exclude = NULL, draw = TRUE )
indexThe index strategy (option) to be evaluated.
refThe reference strategy (option) with which the index strategy will be compared.
outcomeOne of "saving" or "ICER". For
"saving" (e.g. in cost consequence analysis), the x axis is cost
saved (cost of reference minus
cost of index), on the presumption that the new technology will be cost
saving at the point estimate. For "ICER" the x axis is
and is expected to be positive at the point
estimate (i.e. in the NE or SW quadrants of the cost-effectiveness
plane), where is cost of index minus cost of reference,
and is utility of index minus utility of reference.
excludeA list of descriptions of model variables to be excluded from the tornado.
drawTRUE if the graph is to be drawn; otherwise return the data frame silently.
Used to compare two strategies for traversing the decision tree. A strategy is a unanimous prescription of the actions at each decision node. The extreme values of each input variable are the upper and lower 95% confidence limits of the uncertainty distributions of each variable. This ensures that the range of each input is defensible (Briggs 2012).
A data frame with one row per input model variable and columns
for: minimum value of the variable, maximum value of the variable,
minimum value of the outcome and maximum value of the outcome. NULL
if there are no ModVars.
DecisionTree$threshold()Find the threshold value of a model variable at which the cost difference is zero or the ICER is equal to a threshold, for an index strategy compared with a reference strategy.
DecisionTree$threshold( index, ref, outcome, mvd, a, b, tol, lambda = NULL, nmax = 1000L )
indexThe index strategy (option) to be evaluated.
refThe reference strategy (option) with which the index strategy will be compared.
outcomeOne of "saving" or "ICER". For
"saving" (e.g., in cost consequence analysis), the value of
mvd
is found at which cost saved is zero (cost saved is cost of reference
minus cost of index, on the presumption that the new technology will be
cost saving at the point estimate). For "ICER" the value of
mvd
is found for which the incremental cost effectiveness ratio (ICER) is
equal to the threshold lambda. ICER is calculated as
, which will normally be positive
at the point estimate (i.e. in the NE or SW quadrants of the
cost-effectiveness plane), where is cost of index minus
cost of reference and is utility of index minus utility
of reference.
mvdThe description of the model variable for which the threshold is to be found.
aThe lower bound of the range of values of mvd to search
for the root (numeric).
bThe upper bound of the range of values of mvd to search
for the root (numeric).
tolThe tolerance to which the threshold should be calculated (numeric).
lambdaThe ICER threshold (threshold ratio) for outcome="ICER".
nmaxMaximum number if iterations allowed to reach convergence.
Uses a rudimentary bisection method method to find the root. In PSA terms, the algorithm finds the value of the specified model variable for which 50% of runs are cost saving (or above the ICER threshold) and 50% are cost incurring (below the ICER threshold).
Value of the model variable of interest at the threshold.
DecisionTree$clone()The objects of this class are cloneable with this method.
DecisionTree$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
Briggs A, Claxton K, Sculpher M. Decision modelling for health economic evaluation. Oxford, UK: Oxford University Press; 2006.
Briggs AH, Weinstein MC, Fenwick EAL, Karnon J, Sculpher MJ, Paltiel AD. Model Parameter Estimation and Uncertainty: A Report of the ISPOR-SMDM Modeling Good Research Practices Task Force-6. Value in Health 2012;15:835–42, doi:10.1016/j.jval.2012.04.014.
Kaminski B, Jakubczyk M, Szufel P. A framework for sensitivity analysis of decision trees. Central European Journal of Operational Research 2018;26:135–59, doi:10.1007/s10100-017-0479-6.
O'Mahony JF, Newall AT, van Rosmalen J. Dealing with time in health economic evaluation: methodological issues and recommendations for practice. PharmacoEconomics 2015;33:1255-1268, doi:10.1007/s40273-015-0309-4.
An R6 class representing a digraph (a directed graph).
Encapsulates and provides methods for computation and checking of
directed graphs (digraphs). Inherits from class Graph.
Graph -> Digraph
Graph$degree()Graph$edge_along()Graph$edge_at()Graph$edge_index()Graph$edge_label()Graph$edges()Graph$graph_adjacency_matrix()Graph$has_edge()Graph$has_vertex()Graph$is_simple()Graph$neighbours()Graph$order()Graph$size()Graph$vertex_along()Graph$vertex_at()Graph$vertex_index()Graph$vertex_label()Graph$vertexes()Digraph$new()Create a new Digraph object from sets of nodes and
edges.
Digraph$new(V, A)
VA list of Nodes.
AA list of Arrows.
A Digraph object.
Digraph$digraph_adjacency_matrix()Compute the adjacency matrix for the digraph.
Digraph$digraph_adjacency_matrix(boolean = FALSE)
booleanIf TRUE, the adjacency matrix is logical, each
cell is {FALSE,TRUE}.
Each cell contains the number of edges from the row vertex to
the column vertex, with the convention of self loops being counted once,
unless boolean is TRUE when cells are either FALSE
(not adjacent) or TRUE (adjacent).
A square integer matrix with the number of rows and columns
equal to the order of the graph. The rows and columns are in the
same order as V. If the nodes have defined and unique labels the
dimnames of the matrix are the labels of the nodes.
Digraph$digraph_incidence_matrix()Compute the incidence matrix for the digraph.
Digraph$digraph_incidence_matrix()
Each row is a vertex and each column is an edge. Edges leaving a vertex have value -1 and edges entering have value +1. By convention self loops have value 0 (1-1). If all vertexes have defined and unique labels and all edges have defined and unique labels, the dimnames of the matrix are the labels of the vertexes and edges.
The incidence matrix of integers.
Digraph$topological_sort()Topologically sort the vertexes in the digraph.
Digraph$topological_sort()
Uses Kahn's algorithm (Kahn, 1962).
A list of vertexes, topologically sorted. If the digraph has cycles, the returned ordered list will not contain all the vertexes in the graph, but no error will be raised.
Digraph$is_connected()Test whether the graph is connected.
Digraph$is_connected()
For digraphs this will always return FALSE because
connected is not defined. Function weakly_connected
calculates whether the underlying graph is connected.
TRUE if connected, FALSE if not.
Digraph$is_weakly_connected()Test whether the digraph is weakly connected, i.e. if the underlying graph is connected.
Digraph$is_weakly_connected()
TRUE if connected, FALSE if not.
Digraph$is_acyclic()Checks for the presence of a cycle in the graph.
Digraph$is_acyclic()
Attempts to do a topological sort. If the sort does not contain
all vertexes, the digraph contains at least one cycle. This method
overrides is_acyclic in Graph.
TRUE if no cycles detected.
Digraph$is_tree()Is the digraph's underlying graph a tree?
Digraph$is_tree()
It is a tree if it is connected and acyclic.
TRUE if the underlying graph is a tree; FALSE
if not.
Digraph$is_polytree()Is the digraph's underlying graph a polytree?
Digraph$is_polytree()
It is a polytree if it is directed, connected and acyclic.
Because the object is a digraph (directed), this is synonymous with
tree.
TRUE if the underlying graph is a tree; FALSE
if not.
Digraph$is_arborescence()Is the digraph an arborescence?
Digraph$is_arborescence()
An arborescence is a tree with a single root and unique paths from the root.
TRUE if the digraph is an arborescence; FALSE
if not.
Digraph$direct_successors()Find the direct successors of a node.
Digraph$direct_successors(v)
vThe index vertex (a scalar; does not accept a vector of nodes).
A list of Nodes or an empty list if the specified node has no successors.
Digraph$direct_predecessors()Find the direct predecessors of a node.
Digraph$direct_predecessors(v)
vThe index vertex (a scalar; does not accept an index of nodes).
A list of Nodes or an empty list if the specified node has no predecessors.
Digraph$arrow_source()Find the node that is the source of the given arrow.
Digraph$arrow_source(a)
aAn arrow (directed edge), which must be in the digraph.
The source node is a property of the arrow, not the digraph of
which it is part, hence the canonical method for establishing the source
node of an arrow is via method $source of an Arrow object.
This function is provided for convenience when iterating the arrows of a
digraph. It raises an error if the arrow is not in the graph. It
returns the index of the source node, which is a property of the graph;
the node object itself may be retrieved using the $vertex_at
method of the graph.
Index of the source node of the specified edge.
Digraph$arrow_target()Find the node that is the target of the given arrow.
Digraph$arrow_target(a)
aAn arrow (directed edge), which must be in the digraph.
The target node is a property of the arrow, not the digraph of
which it is part, hence the canonical method for establishing the target
node of an arrow is via method $target of an $Arrow object.
This function is provided for convenience when iterating the arrows of a
digraph. It raises an error if the arrow is not in the graph. It
returns the index of the target node, which is a property of the graph;
the node itself may be retrieved using the $vertex_at method
of the graph.
Index of the target node of the specified edge.
Digraph$paths()Find all directed simple paths from source to target.
Digraph$paths(s, t)
sSource node.
tTarget node.
In simple paths all vertexes are unique. Uses a recursive depth-first search algorithm.
A list of ordered node lists.
Digraph$walk()Sequence of edges which join the specified path.
Digraph$walk(P, what = "edge")
PA list of Nodes
whatOne of "edge" or "index".
A list of Edges for what = "edge" or a list of Edge
indices for what = "index".
Digraph$as_DOT()Exports the digraph in DOT notation.
Digraph$as_DOT(rankdir = "LR", width = 7, height = 7)
rankdirOne of "LR" (default), "TB", "RL" or "BT".
widthof the drawing, in inches
heightof the drawing, in inches
Writes a representation of the digraph in the
graphviz DOT language
(https://graphviz.org/doc/info/lang.html) for drawing with one
of the graphviz tools, including dot (Gansner, 1993).
This option is recommended if it is desired to rapidly plot a graph;
however it gives limited control over details of the appearance. In
addition, the appearance may vary between calls if the node order changes
(specifically, if there is no Hamiltonian path). For greater control over
the appearance of a graph, use the as_gml function and manipulate
the graph using igraph or DiagrammeR; please refer to the vignettes for
examples.
A character vector. Intended for passing to writeLines
for saving as a text file.
Digraph$as_gml()Exports the digraph as a Graph Modelling Language (GML) stream.
Digraph$as_gml()
Intended to work with the igraph or DiagrammeR packages, which are able to import GML files.
A GML stream as a character vector.
Digraph$clone()The objects of this class are cloneable with this method.
Digraph$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
Gansner ER, Koutsofios E, North SC, Vo K-P. A technique for drawing directed graphs. IEEE Transactions on Software Engineering, 1993;19:214–30, doi:10.1109/32.221135.
Gross JL, Yellen J, Zhang P. Handbook of Graph Theory. Second edition, Chapman and Hall/CRC.; 2013, doi:10.1201/b16132.
Kahn AB, Topological Sorting of Large Networks, Communications of the ACM, 1962;5:558-562, doi:10.1145/368996.369025.
An R6 class representing a Dirac Delta function.
A distribution modelled by a Dirac delta function
where is the hyperparameter (value of the constant). It has
probability 1 that the value will be equal to and zero otherwise.
The mode, mean, quantiles and random samples are all equal to . It is
acknowledged that there is debate over whether Dirac delta functions are
true distributions, but the assumption makes little practical difference in
this case. Inherits from class Distribution.
Distribution -> DiracDistribution
DiracDistribution$new()Create a new Dirac Delta function distribution.
DiracDistribution$new(const)
constThe value at which the distribution is centred.
A new DiracDistribution object.
DiracDistribution$distribution()Accessor function for the name of the distribution.
DiracDistribution$distribution()
Distribution name as character string.
DiracDistribution$mode()Return the mode of the distribution.
DiracDistribution$mode()
Numeric Value where the distribution is centered.
DiracDistribution$mean()Return the expected value of the distribution.
DiracDistribution$mean()
Expected value as a numeric value.
DiracDistribution$SD()Return the standard deviation of the distribution.
DiracDistribution$SD()
Standard deviation as a numeric value
DiracDistribution$quantile()Quantiles of the distribution.
DiracDistribution$quantile(probs)
probsNumeric vector of probabilities, each in range [0,1].
For a Dirac Delta Function all quantiles are returned as the value at which the distribution is centred.
Vector of numeric values of the same length as probs.
DiracDistribution$sample()Draw and hold a random sample from the model variable.
DiracDistribution$sample(expected = FALSE)
expectedIf TRUE, sets the next value retrieved by a call to
r() to be the mean of the distribution.
Updated distribution.
DiracDistribution$clone()The objects of this class are cloneable with this method.
DiracDistribution$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
An R6 class representing a multivariate Dirichlet distribution.
A multivariate Dirichlet distribution. See
https://en.wikipedia.org/wiki/Dirichlet_distribution for details.
Inherits from class Distribution.
Distribution -> DirichletDistribution
DirichletDistribution$new()Create an object of class DirichletDistribution.
DirichletDistribution$new(alpha)
alphaParameters of the distribution; a vector of K numeric
values each > 0, with .
An object of class DirichletDistribution.
DirichletDistribution$distribution()Accessor function for the name of the distribution.
DirichletDistribution$distribution()
Distribution name as character string.
DirichletDistribution$mean()Mean value of each dimension of the distribution.
DirichletDistribution$mean()
A numerical vector of length K.
DirichletDistribution$mode()Return the mode of the distribution.
DirichletDistribution$mode()
Undefined if any alpha is .
Mode as a vector of length K.
DirichletDistribution$quantile()Quantiles of the univariate marginal distributions.
DirichletDistribution$quantile(probs)
probsNumeric vector of probabilities, each in range [0,1].
The univariate marginal distributions of a Dirichlet distribution are Beta distributions. This function returns the quantiles of each marginal. Note that these are not the true quantiles of the multivariate Dirichlet.
A matrix of numeric values with the number of rows equal to the
length of probs, the number of columns equal to the order; rows
are labelled with quantiles and columns with the dimension (1, 2, etc).
DirichletDistribution$varcov()Variance-covariance matrix.
DirichletDistribution$varcov()
A positive definite symmetric matrix of size K by
K.
DirichletDistribution$sample()Draw and hold a random sample from the distribution.
DirichletDistribution$sample(expected = FALSE)
expectedIf TRUE, sets the next value retrieved by a call to
r() to be the mean of the distribution.
Void; sample is retrieved with call to r().
DirichletDistribution$clone()The objects of this class are cloneable with this method.
DirichletDistribution$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing a (possibly multivariate) distribution.
The base class for particular univariate or multivariate distributions.
Distribution$new()Create an object of class Distribution.
Distribution$new(name, K = 1L)
nameName of the distribution ("Beta" etc.)
KOrder of the distribution (1 = univariate, 2 = bivariate etc.). Must be an integer; use 1L, 3L etc. to avoid an error.
An object of class Distribution.
Distribution$order()Order of the distribution
Distribution$order()
Order (K).
Distribution$distribution()Description of the uncertainty distribution.
Distribution$distribution()
Includes the distribution name and its parameters.
Distribution name and parameters as character string.
Distribution$mean()Mean value of the distribution.
Distribution$mean()
Mean value as a numeric scalar (K = 1L) or vector of
length K.
Distribution$mode()Return the mode of the distribution.
Distribution$mode()
By default returns NA, which will be the case for most
because an arbitrary distribution is not guaranteed to be unimodal.
Mode as a numeric scalar (K = 1L) or vector of
length K.
Distribution$SD()Return the standard deviation of a univariate distribution.
Distribution$SD()
Only defined for univariate (K = 1L) distributions; for
multivariate distributions, function varcov returns the
variance-covariance matrix.
Standard deviation as a numeric value.
Distribution$varcov()Variance-covariance matrix.
Distribution$varcov()
A positive definite symmetric matrix of size K by
K, or a scalar for K = 1L, equal to the variance.
Distribution$quantile()Marginal quantiles of the distribution.
Distribution$quantile(probs)
probsNumeric vector of probabilities, each in range [0,1].
If they are defined, this function returns the marginal
quantiles of the multivariate distribution; i.e. the quantiles of each
univariate marginal distribution of the multivariate distribution. For
example, the univariate marginal distributions of a multivariate
normal are univariate normals, and the univariate marginal distributions
of a Dirichlet distribution are Beta distributions. Note that these are
not the true quantiles of a multivariate distribution, which are contours
for K = 2L, surfaces for K = 3L, etc. For example, the
2.5% and 97.5% marginal quantiles of a bivariate normal distribution
define a rectangle in space that will include more than
95% of the distribution, whereas the contour containing 95% of the
distribution is an ellipse.
For K = 1L a numeric vector of length equal to the length
of probs, with each entry labelled with the quantile. For
K > 1L a matrix of numeric values with the number of rows equal
to the length of probs, the number of columns equal to the order;
rows are labelled with probabilities and columns with the dimension
(1, 2, etc).
Distribution$sample()Draw and hold a random sample from the distribution.
Distribution$sample(expected = FALSE)
expectedIf TRUE, sets the next value retrieved by a call to
r() to be the mean of the distribution.
Void
Distribution$r()Return a random sample drawn from the distribution.
Distribution$r()
Returns the sample generated at the last call to sample.
A vector of length K representing one sample.
Distribution$clone()The objects of this class are cloneable with this method.
Distribution$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing an edge in a graph.
Edges are the formal term for links between pairs of nodes in a graph. A base class.
Edge$new()Create an object of type Edge.
Edge$new(v1, v2, label = "")
v1Node at one endpoint of the edge.
v2Node at the other endpoint of the edge.
labelCharacter string containing the edge label.
A new Edge object.
Edge$is_same_edge()Is this edge the same as the argument?
Edge$is_same_edge(e)
eedge to compare with this one
TRUE if e is also this one.
Edge$endpoints()Retrieve the endpoints of the edge.
Edge$endpoints()
List of two nodes to which the edge is connected.
Edge$label()Access label.
Edge$label()
Label of the edge; character string.
Edge$modvars()Find all the model variables of type ModVar that have
been specified as values associated with this Edge.
Edge$modvars()
An empty list for the base class.
Edge$clone()The objects of this class are cloneable with this method.
Edge$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing an empirical (1D) distribution.
An object representing an empirical distribution. It inherits
from class Distribution.
Distribution -> EmpiricalDistribution
EmpiricalDistribution$new()Create an object of class EmpiricalDistribution.
EmpiricalDistribution$new(x, interpolate.sample = TRUE)
xa sample of at least 1 numerical value from the population of interest.
interpolate.sampleLogical; if true, each call to sample()
make a random draw from to find a value, then
finds that quantile of the sample, using the quantile function
in R, via interpolation from the eCDF. If false, the sample()
function makes a random draw from x.
Empirical distributions based on very small sample sizes are supported, but not recommended.
An object of class EmpiricalDistribution.
EmpiricalDistribution$distribution()Accessor function for the name of the distribution.
EmpiricalDistribution$distribution()
Distribution name as character string.
EmpiricalDistribution$mean()Return the expected value of the distribution.
EmpiricalDistribution$mean()
Expected value as a numeric value.
EmpiricalDistribution$mode()Return the mode of the distribution,
EmpiricalDistribution$mode()
NA because an empirical distribution is not guaranteed to be unimodal.
EmpiricalDistribution$SD()Return the standard deviation of the distribution.
EmpiricalDistribution$SD()
Standard deviation as a numeric value
EmpiricalDistribution$sample()Draw and hold a random sample from the distribution.
EmpiricalDistribution$sample(expected = FALSE)
expectedIf TRUE, sets the next value retrieved by a call to
r() to be the mean of the distribution.
Samples with interpolation or by random draw from the
supplied distribution (see parameter interpolate.sample in
new()).
Updated distribution.
EmpiricalDistribution$quantile()Return the quantiles of the empirical uncertainty distribution.
EmpiricalDistribution$quantile(probs)
probsVector of probabilities, in range [0,1].
Vector of quantiles.
EmpiricalDistribution$clone()The objects of this class are cloneable with this method.
EmpiricalDistribution$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing a model variable constructed from an expression involving other variables.
A class to support expressions involving objects of base class
ModVar, which itself behaves like a model variable. For example, if
A and B are variables with base class ModVar and
c is a variable of type numeric, then it is not possible to
write, for example, x <- 42*A/B + c, because R cannot manipulate class
variables using the same operators as regular variables. But such forms of
expression may be desirable in constructing a model and this class provides
a mechanism for doing so. Inherits from class ModVar.
ModVar -> ExprModVar
ExprModVar$new()Create a ModVar formed from an expression involving
other model variables.
ExprModVar$new(description, units, quo, nemp = 1000L)
descriptionName for the model variable expression. In a complex model it may help to tabulate how model variables are combined into costs, probabilities and rates.
unitsUnits in which the variable is expressed.
quoA quosure (see package rlang), which contains an
expression and its environment. The usage is quo(x+y) or
rlang::quo(x+y).
nempsample size of the empirical distribution which will be
associated with the expression, and used to estimate values for
mu_hat, sigma_hat and q_hat.
An object of type ExprModVar
ExprModVar$add_method()Create a new quosure from that supplied in
new() but with each ModVar
operand appended with $x where x is the argument to this
function.
ExprModVar$add_method(method = "mean()")
methodA character string with the method, e.g. "mean()".
This method is mostly intended for internal use within the
class and will not generally be needed for normal use of
ExprModVar objects. The returned expression is not
syntactically checked or evaluated before it is returned.
A quosure whose expression is each ModVar v
in the
expression replaced with v$method and the same environment as
specified in the quosure supplied in new().
ExprModVar$is_probabilistic()Tests whether the model variable is probabilistic, i.e. a random variable that follows a distribution, or an expression involving random variables, at least one of which follows a distribution.
ExprModVar$is_probabilistic()
TRUE if probabilistic
ExprModVar$operands()Return a list of operands.
ExprModVar$operands(recursive = TRUE)
recursiveWhether to include nested variables in the list.
Finds operands that are themselves ModVars in the
expression. if recursive=TRUE, the list includes all
ModVars that are operands of expression operands, recursively.
A list of model variables.
ExprModVar$distribution()Accessor function for the name of the expression model variable.
ExprModVar$distribution()
Expression as a character string with all control characters having been removed.
ExprModVar$mean()Return the value of the expression when its operands take
their mean value (i.e. value returned by call to mean or their
value, if numeric). See notes on this class for further explanation.
ExprModVar$mean()
Mean value as a numeric value.
ExprModVar$mode()Return the mode of the variable. By default returns
NA, which will be the case for most ExprModVar variables,
because an arbitrary expression is not guaranteed to be unimodal.
ExprModVar$mode()
Mode as a numeric value.
ExprModVar$SD()Return the standard deviation of the distribution as
NA because the variance is not available as a closed form for
all functions of distributions.
ExprModVar$SD()
Standard deviation as a numeric value
ExprModVar$quantile()Find quantiles of the uncertainty distribution. Not
available as a closed form, and returned as NA.
ExprModVar$quantile(probs)
probsNumeric vector of probabilities, each in range [0,1].
Vector of numeric values of the same length as probs.
ExprModVar$mu_hat()Return the estimated expected value of the variable.
ExprModVar$mu_hat()
This is computed by numerical simulation because there is, in general, no closed form expressions for the mean of a function of distributions. It is derived from the empirical distribution associated with the object.
Expected value as a numeric value.
ExprModVar$sigma_hat()Return the estimated standard deviation of the distribution.
ExprModVar$sigma_hat()
This is computed by numerical simulation because there is, in general, no closed form expressions for the SD of a function of distributions. It is derived from the empirical distribution associated with the object.
Standard deviation as a numeric value.
ExprModVar$q_hat()Return the estimated quantiles by sampling the variable.
ExprModVar$q_hat(probs)
probsVector of probabilities, in range [0,1].
This is computed by numerical simulation because there is, in general, no closed form expressions for the quantiles of a function of distributions. The quantiles are derived from the empirical distribution associated with the object.
Vector of quantiles.
ExprModVar$set()Sets the value of the ExprModVar.
ExprModVar$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 derived by taking a random
sample from each of the operands and evaluating the expression. It
does not draw from the empirical distribution because of the possibility
of nested autocorrelation. For example, if , where is a
model variable and is an expression which involves , then
and are correlated and will produce a different
distribution for than if and were independent.
However, if was sampled from the empirical distribution of
and the uncertainty distribution of independently, the
effect of correlation would be lost;
"expected"the value of the expression when each of its
operands takes its expected value. This will not - in general - be the
mean of the uncertainty distribution for the expression which can be
estimated by calling mu_hat;
"q2.5"the value of the expression when each of its
operands is equal to the 2.5th centile of their own uncertainty
distribution. In general, this will be a more extreme value than the
2.5th centile of the uncertainty distribution of the expression, which
can be found by using q_hat(p=0.025);
"q50"as per "q2.5" but for the 50th
centile (median);
"q97.5"as per "q2.5" but for the 97.5th
centile;
"current"leaves the what parameter of method
set unchanged for each operand and causes the expression
to be re-evaluated at subsequent calls to get. Thus, after calling
set(what="current") for the expression, subsequent calls to
get for the expression may not return the same value, if method
set has been called for one or more operands in the meantime;
"value"sets the value of the expression 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.
The available options for parameter what are identical to
those available for the set method of ModVar. However,
because an ExprModVar represents the left hand side of an
expression involving operands, the effect of some options is different
from its effect on a non-expression ModVar.
Updated ExprModVar.
ExprModVar$get()Gets the value of the ExprModVar that was set by the
most recent call to set().
ExprModVar$get()
Value determined by last set().
ExprModVar$clone()The objects of this class are cloneable with this method.
ExprModVar$clone(deep = FALSE)
deepWhether to make a deep clone.
For many expressions involving model variables there will
be no closed form expressions for the mean, standard deviation and
the quantiles. When an ExprModVar is created, an empirical
distribution is generated by repeatedly drawing a random sample from each
operand and evaluating the expression. The empirical distribution, which
becomes associated with the object, is used to provide estimates of the
mean, standard deviation and the quantiles via functions mu_hat,
sigma_hat and q_hat.
For consistency with ModVars which are not expressions, the
function mean returns the value of the expression when all
its operands take their mean values. This will, in general, not
be the mean of the expression distribution (which can be obtained
via mu_hat), but is the value normally used in the base
case of a model as the point estimate. As Briggs et al note
(section 4.1.1) "in all but the most non-linear models, the
difference between the expectation over the output of a
probabilistic model and that model evaluated at the mean values
of the input parameters, is likely to be modest."
Functions SD, mode and quantile return NA
because they do not necessarily have a closed form. The standard
deviation can be estimated by calling sigma_hat and the
quantiles by q_hat. Because a unimodal distribution is not
guaranteed, there is no estimator provided for the mode.
Method distribution returns the string representation
of the expression used to create the model variable.
Andrew J. Sims [email protected]
Briggs A, Claxton K, Sculpher M. Decision modelling for health economic evaluation. Oxford, UK: Oxford University Press; 2006.
An R6 class representing a Gamma distribution.
An object representing a Gamma distribution with hyperparameters
shape (k) and scale (theta). In econometrics this
parametrization is more common but in Bayesian statistics the shape
(alpha) and rate (beta) parametrization is more usual. Note,
however, that although Briggs et al (2006) use the shape, scale
formulation, they use alpha, beta as parameter names. Inherits
from class Distribution.
Distribution -> GammaDistribution
GammaDistribution$new()Create an object of class GammaDistribution.
GammaDistribution$new(shape, scale)
shapeshape parameter of the Gamma distribution.
scalescale parameter of the Gamma distribution.
An object of class GammaDistribution.
GammaDistribution$distribution()Accessor function for the name of the distribution.
GammaDistribution$distribution()
Distribution name as character string.
GammaDistribution$mean()Return the expected value of the distribution.
GammaDistribution$mean()
Expected value as a numeric value.
GammaDistribution$mode()Return the mode of the distribution (if shape >= 1)
GammaDistribution$mode()
mode as a numeric value.
GammaDistribution$SD()Return the standard deviation of the distribution.
GammaDistribution$SD()
Standard deviation as a numeric value
GammaDistribution$sample()Draw and hold a random sample from the distribution.
GammaDistribution$sample(expected = FALSE)
expectedIf TRUE, sets the next value retrieved by a call to
r() to be the mean of the distribution.
Updated distribution.
GammaDistribution$quantile()Return the quantiles of the Gamma uncertainty distribution.
GammaDistribution$quantile(probs)
probsVector of probabilities, in range [0,1].
Vector of quantiles.
GammaDistribution$clone()The objects of this class are cloneable with this method.
GammaDistribution$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
Briggs A, Claxton K, Sculpher M. Decision modelling for health economic evaluation. Oxford, UK: Oxford University Press; 2006.
An R6 class for a model variable with Gamma uncertainty.
A model variable for which the uncertainty in the point estimate can
be modelled with a Gamma distribution. The hyperparameters of the
distribution are the shape (k) and the scale (theta). Note
that although Briggs et al (2006) use the shape, scale formulation,
they use alpha, beta as parameter names. Inherits from
class ModVar.
ModVar -> GammaModVar
GammaModVar$new()Create an object of class GammaModVar.
GammaModVar$new(description, units, shape, scale)
descriptionA character string describing the variable.
unitsUnits of the variable, as character string.
shapeshape parameter of the Gamma distribution.
scalescale parameter of the Gamma distribution.
An object of class GammaModVar.
GammaModVar$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.
GammaModVar$is_probabilistic()
TRUE if probabilistic
GammaModVar$clone()The objects of this class are cloneable with this method.
GammaModVar$clone(deep = FALSE)
deepWhether to make a deep clone.
The Gamma model variable class can be used to model the uncertainty of
the mean of a count quantity which follows a Poisson distribution. The Gamma
distribution is the conjugate prior of a Poisson distribution, and the shape
and scale relate directly to the number of intervals from which the mean
count has been estimated. Specifically, the shape () is equal to the
total count of events in intervals, where is the
scale. For example, if 200 counts were observed in a sample of 100 intervals,
setting shape=200 and scale=1/100 gives a Gamma distribution
with a mean of 2 and a 95% confidence interval from 1.73 to 2.29.
Andrew J. Sims [email protected]
Briggs A, Claxton K, Sculpher M. Decision modelling for health economic evaluation. Oxford, UK: Oxford University Press; 2006.
Formats a number, or list of numbers, into currency.
gbp(x, p = FALSE, char = TRUE)gbp(x, p = FALSE, char = TRUE)
x |
Monetary value, or list of values |
p |
Logical; if TRUE show value to nearest penny, cent etc. If FALSE show it to the nearest pound, dollar, euro etc. |
char |
Logical; if TRUE format the currency values into a character vector, with pretty printing, including comma separators for thousands, otherwise convert to rounded numeric values. |
If x is defined using the c() operator and contains elements of different mode, it will coerce all elements to a common mode. It is safer to define x as a list because R does not do implicit coercion.
A character vector with pretty formatted currency values (if
char is TRUE), or a vector of rounded numeric values.
An R6 class to represent a graph (from discrete mathematics).
Encapsulates and provides methods for computation and checking of undirected graphs. Graphs are systems of vertices connected in pairs by edges. A base class.
Graph$new()Create a new Graph object from sets of nodes
and edges.
Graph$new(V, E)
VAn unordered set of Nodes, as a list.
EAn unordered set of Edges, as a list.
A Graph object.
Graph$order()Return the order of the graph (number of vertices).
Graph$order()
Order of the graph (integer).
Graph$size()Return the size of the graph (number of edges).
Graph$size()
Size of the graph (integer).
Graph$vertexes()A list of all the Node objects in the graph.
Graph$vertexes()
The list of Node objects is returned in the same order as their
indexes understood by vertex_index, vertex_at and
vertex_along, which is not necessarily the same order in which
they were supplied in the V argument to new.
Graph$vertex_along()Sequence of vertex indices.
Graph$vertex_along()
Similar to base::seq_along, this function provides
the indices of the vertices in the graph. It is intended for use by
graph algorithms which iterate vertices.
A numeric vector of indices from 1 to the order of the graph.
The vertex at index is not guaranteed to be the same vertex at
V[[i]] of the argument V to new (i.e., the order in
which the vertices are stored internally within the class may differ
from the order in which they were supplied).
Graph$vertex_index()Find the index of a vertex in the graph.
Graph$vertex_index(v)
vA vertex, or list of vertexes.
Index or indexes of v. The index of vertex v is the
one used internally to the class object, which is not necessarily the
same as the order of vertices in the V argument of new.
NA if v is not a vertex, or is a vertex that is not in the
graph.
Graph$vertex_at()Find the vertex at a given index.
Graph$vertex_at(index, as_list = FALSE)
indexIndex of vertex in the graph, as an integer, or vector of integers.
as_listBoolean. If TRUE the method returns list of Nodes,
even if the length of index is 1.
The inverse of function vertex_index. The function will
raise an abort signal if all the supplied indexes are not vertexes. The
function is vectorized, but for historical compatibility the return
object is a single Node if index is a scalar. The
return object can be guaranteed to be a list if as_list is set.
Node at index if index is a scalar, a list of Nodes
at the values of index if index is a vector, or an empty
list if index is an empty array.
Graph$has_vertex()Test whether a vertex is an element of the graph.
Graph$has_vertex(v)
vVertex, or list of vertices.
A logical scalar or logical vector the same length as v if v is a vector, with TRUE if v is an element of V(G).
Graph$vertex_label()Find label of vertexes at index i.
Graph$vertex_label(iv)
ivIndex of vertex, or vector of indexes.
Label(s) of vertex at index i
Graph$edges()A list of all the Edge objects in the graph.
Graph$edges()
The list of Edge objects is returned in the same order as their
indexes understood by edge_index, edge_at and
edge_along, which is not necessarily the same order in which they
were supplied in the E argument to new.
Graph$edge_along()Sequence of edge indices.
Graph$edge_along()
Similar to base::seq_along, this function provides
the indices of the edges in the graph. It is intended for use by
graph algorithms which iterate edges. It is equivalent to
seq_along(g$edges()), where g is a graph.
A numeric vector of indices from 1 to the size of the graph.
The edge at index is not guaranteed to be the same edge at
E[[i]] of the argument E to new (i.e., the order in
which the edges are stored internally within the class may differ
from the order in which they were supplied).
Graph$edge_index()Find the index of an edge in a graph.
Graph$edge_index(e)
eAn edge object, or list of edge objects.
The index of edge e is the one used internally to the
class object, which is not necessarily the same as the
order of edges in the E argument of new.
Index, or indexes, of e. NA if e is not an
edge, or is an edge that is not in the graph.
Graph$edge_at()Find the edge at a given index.
Graph$edge_at(index, as_list = FALSE)
indexIndex of edge in the graph, as an integer, vector of integers, or list of integers.
as_listBoolean. If TRUE the method returns list of Edges,
even if the length of index is 1.
The inverse of function edge_index. The function will
raise an abort signal if the supplied index is not an edge. The
function is vectorized, but for historical compatibility the return
object is a single Edge if index is a scalar. The
return object can be guaranteed to be a list if as_list is set.
The edge, or list of edges, with the specified index.
Graph$has_edge()Test whether an edge is an element of the graph.
Graph$has_edge(e)
eEdge or list of edges.
Logical vector with each element TRUE if the corresponding
element of e is an element of .
Graph$edge_label()Find label of edge at index i
Graph$edge_label(ie)
ieIndex of edge, or vector of indexes.
Label of edge at index i, or character vector with the labels at
indexes ie.
Graph$graph_adjacency_matrix()Compute the adjacency matrix for the graph.
Graph$graph_adjacency_matrix(boolean = FALSE)
booleanIf TRUE, the adjacency matrix is logical, each
cell is {FALSE, TRUE}.
Each cell contains the
number of edges joining the two vertexes, with the convention of
self loops being counted twice, unless binary is TRUE when
cells are either 0 (not adjacent) or 1 (adjacent).
A square integer matrix with the number of rows and columns equal to the order of the graph. The rows and columns are labelled with the node labels, if all the nodes in the graph have unique labels, or the node indices if not.
Graph$is_simple()Is this a simple graph?
Graph$is_simple()
A simple graph has no self loops or multi-edges.
TRUE if simple, FALSE if not.
Graph$is_connected()Test whether the graph is connected.
Graph$is_connected()
Graphs with no vertices are considered unconnected; graphs with 1 vertex are considered connected. Otherwise a graph is connected if all nodes can be reached from an arbitrary starting point. Uses a depth first search.
TRUE if connected, FALSE if not.
Graph$is_acyclic()Checks for the presence of a cycle in the graph.
Graph$is_acyclic()
Uses a depth-first search from each node to detect the presence of back edges. A back edge is an edge from the current node joining a previously detected (visited) node, that is not the parent node of the current one.
TRUE if no cycles detected.
Graph$is_tree()Compute whether the graph is connected and acyclic.
Graph$is_tree()
TRUE if the graph is a tree; FALSE if not.
Graph$degree()The degree of a vertex in the graph.
Graph$degree(v)
vThe subject node.
The number of incident edges.
Degree of the vertex, integer.
Graph$neighbours()Find the neighbours of a node.
Graph$neighbours(v)
vThe subject node (scalar, not a list).
A property of the graph, not the node. Does not include self, even in the case of a loop to self.
A list of nodes which are joined to the subject.
Graph$as_DOT()Export a representation of the graph in DOT format.
Graph$as_DOT(rankdir = "LR", width = 7, height = 7)
rankdirOne of "LR" (default), "TB", "RL" or "BT".
widthof the drawing, in inches
heightof the drawing, in inches
Writes the representation in the graphviz DOT language
(https://graphviz.org/doc/info/lang.html) for drawing with one
of the graphviz tools including dot (Gansner, 1993).
A character vector. Intended for passing to writeLines
for saving as a text file.
Graph$as_gml()Exports the digraph as a Graph Modelling Language (GML) stream.
Graph$as_gml()
Intended to work with the igraph or DiagrammeR packages, which are able to import GML files.
A GML stream as a character vector.
Graph$clone()The objects of this class are cloneable with this method.
Graph$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
Gansner ER, Koutsofios E, North SC, Vo K-P. A technique for drawing directed graphs. IEEE Transactions on Software Engineering, 1993;19:214–30, doi:10.1109/32.221135.
Gross JL, Yellen J, Zhang P. Handbook of Graph Theory. Second edition, Chapman and Hall/CRC.; 2013, doi:10.1201/b16132
An R6 class representing a leaf (terminal) node in a decision tree.
Represents a terminal state in a tree, and is associated with an
incremental utility. Inherits from class Node.
Node -> LeafNode
LeafNode$new()Create a new LeafNode object; synonymous with a
health state.
LeafNode$new( label, utility = 1, interval = as.difftime(365.25, units = "days"), ru = 0 )
labelCharacter string; a label for the state; must be defined because it is used in tabulations. The label is automatically converted to a syntactically valid (in R) name to ensure it can be used as a column name in a data frame.
utilityThe utility that a user associates with being in the
health state for the interval. Can be numeric or
a type of ModVar. If the type is numeric, the allowed
range is -Inf to 1; if it is of type ModVar, it is
unchecked.
intervalThe time horizon, or duration for which a user is
expected to occupy the health state and experience a health-related
quality of life of utility, expressed as an R difftime
object; default 1 year.
ruAnnual discount rate for future utility. Note this is a rate, not a probability (i.e., use 0.035 for 3.5%).
A new LeafNode object
LeafNode$grob()Creates a grid::grob for a leaf node.
LeafNode$grob(x, y, bb = FALSE)
xx coordinate of the node, grid::unit object.
yy coordinate of the node, grid::unit object.
bbLogical. If TRUE, function returns the bounding box.
A grid::grob containing the symbol and label, or a bounding box as a grid::unit vector with 4 elements: left, right, bottom, top.
LeafNode$modvars()Find all the model variables of type ModVar that have
been specified as values associated with this LeafNode. Includes
operands of these ModVars, if they are expressions.
LeafNode$modvars()
A list of ModVars.
LeafNode$set_utility()Set the utility associated with the node.
LeafNode$set_utility(utility)
utilityThe utility that a user associates with being in the
health state for the interval. Can be numeric or
a type of ModVar. If the type is numeric, the allowed
range is -Inf to 1, not NA; if it is of type ModVar, it is
unchecked.
Updated Leaf object.
LeafNode$set_interval()Set the time interval associated with the node.
LeafNode$set_interval(interval)
intervalThe time interval over which the utility
parameter applies, expressed as an R difftime object; default
1 year, not NA.
Updated Leaf object.
LeafNode$utility()Return the utility associated with being in the state for the interval.
LeafNode$utility()
Utility (numeric value).
LeafNode$interval()Return the interval associated with being in the state.
LeafNode$interval()
Interval (as a difftime).
LeafNode$QALY()Return the discounted quality adjusted life years associated with being in the state.
LeafNode$QALY()
The present value of utility at future time can be expressed as
, where is the utility at time
and is the discount rate for utility
(O'Mahony, 2015), under the assumption of continuous discount. The
quality adjusted life years (QALYs) gained by occupying the state for
time is
For , the QALY
gain is equal to
and for
, it is '. For example, at a discount rate of 3.5%,
the number of QALYs gained after occupying a state for 1 year with a
present value utility of 0.75 is 0.983 0.75
0.737 QALYs, and after 2 years the gain is 1.449 QALYs.
QALY.
LeafNode$clone()The objects of this class are cloneable with this method.
LeafNode$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
O'Mahony JF, Newall AT, van Rosmalen J. Dealing with time in health economic evaluation: methodological issues and recommendations for practice. PharmacoEconomics 2015;33:1255–1268.
An R6 class representing a log Normal distribution.
A parametrized Log Normal distribution inheriting from class
Distribution. Swat (2017) defined seven parametrizations of the log
normal distribution.
These are linked, allowing the parameters of any one to be derived from any
other. All 7 parametrizations require two parameters as follows:
, , where and
are the mean and standard deviation, both on the log scale.
, , where and are the
mean and variance, both on the log scale.
, , where is the median on the
natural scale and is the standard deviation on the log scale.
, , where is the median on the
natural scale and is the coefficient of variation on the natural
scale.
, , where is the mean on the
log scale and is the precision on the log scale.
, , where is the median on
the natural scale and is the geometric standard deviation on
the natural scale.
, , where is the mean
on the natural scale and is the standard deviation on the
natural scale.
Distribution -> LogNormDistribution
LogNormDistribution$new()Create a log normal distribution.
LogNormDistribution$new(p1, p2, parametrization = "LN1")
p1First hyperparameter, a measure of location. See Details.
p2Second hyperparameter, a measure of spread. See Details.
parametrizationA character string taking one of the values
"LN1" (default) through "LN7" (see Details).
A LogNormDistribution object.
LogNormDistribution$distribution()Accessor function for the name of the distribution.
LogNormDistribution$distribution()
Distribution name as character string ("LN1", "LN2"
etc.).
LogNormDistribution$sample()Draw a random sample from the model variable.
LogNormDistribution$sample(expected = FALSE)
expectedIf TRUE, sets the next value retrieved by a call to
r() to be the mean of the distribution.
Updated LogNormDistribution object.
LogNormDistribution$mean()Return the expected value of the distribution.
LogNormDistribution$mean()
Expected value as a numeric value.
LogNormDistribution$mode()Return the point estimate of the variable.
LogNormDistribution$mode()
Point estimate (mode) of the log normal distribution.
LogNormDistribution$SD()Return the standard deviation of the distribution.
LogNormDistribution$SD()
Standard deviation as a numeric value
LogNormDistribution$quantile()Return the quantiles of the log normal distribution.
LogNormDistribution$quantile(probs)
probsVector of probabilities, in range [0,1].
Vector of quantiles.
LogNormDistribution$clone()The objects of this class are cloneable with this method.
LogNormDistribution$clone(deep = FALSE)
deepWhether to make a deep clone.
The log normal distribution may be used to model the uncertainty in
an estimate of relative risk (Briggs 2006, p90). If a relative risk
estimate is available with a 95% confidence interval, the "LN7"
parametrization
allows the uncertainty distribution to be specified directly. For example,
if RR = 0.67 with 95% confidence interval 0.53 to 0.84 (Leaper, 2016), it
can be modelled with
LogNormModVar$new("rr", "RR", p1=0.67,
p2=(0.84-0.53)/(2*1.96)), "LN7").
Andrew J. Sims [email protected]
Briggs A, Claxton K and Sculpher M. Decision Modelling for Health Economic Evaluation. Oxford 2006, ISBN 978-0-19-852662-9.
Leaper DJ, Edmiston CE and Holy CE. Meta-analysis of the potential economic impact following introduction of absorbable antimicrobial sutures. British Journal of Surgery 2017;104:e134-e144.
Swat MJ, Grenon P and Wimalaratne S. Ontology and Knowledge Base of Probability Distributions. Bioinformatics 2016;32:2719-2721, doi:10.1093/bioinformatics/btw170.
An R6 class representing a model variable with log Normal uncertainty.
A model variable for which the uncertainty in the point estimate can
be modelled with a log Normal distribution. One of seven parametrizations
defined by Swat et al can be used. Inherits from ModVar.
ModVar -> LogNormModVar
LogNormModVar$new()Create a model variable with log normal uncertainty.
LogNormModVar$new(description, units, p1, p2, parametrization = "LN1")
descriptionA character string describing the variable.
unitsUnits of the quantity; character string.
p1First hyperparameter, a measure of location.
p2Second hyperparameter, a measure of spread.
parametrizationA character string taking one of the values
"LN1" (default) through "LN7" (see Details).
A LogNormModVar object.
LogNormModVar$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.
LogNormModVar$is_probabilistic()
TRUE if probabilistic
LogNormModVar$clone()The objects of this class are cloneable with this method.
LogNormModVar$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
Briggs A, Claxton K and Sculpher M. Decision Modelling for Health Economic Evaluation. Oxford 2006, ISBN 978-0-19-852662-9.
Leaper DJ, Edmiston CE and Holy CE. Meta-analysis of the potential economic impact following introduction of absorbable antimicrobial sutures. British Journal of Surgery 2017;104:e134-e144.
Swat MJ, Grenon P and Wimalaratne S. Ontology and Knowledge Base of Probability Distributions. Bioinformatics 2016;32:2719-2721, doi:10.1093/bioinformatics/btw170.
An R6 class representing a state in a Markov model.
Represents a single state in a Markov model. A Markov model is
a digraph in which states are nodes and transitions are arrows. Inherits
from class Node.
Node -> MarkovState
MarkovState$new()Create an object of type MarkovState.
MarkovState$new(name, cost = 0, utility = 1)
nameThe name of the state (character string).
costThe annual cost of state occupancy (numeric or
ModVar). Default 0.0.
utilityThe utility associated with being in the state (numeric
or ModVar).
Utility must be in the range [-Inf,1]. If it is of type
numeric, the range is checked on object creation.
An object of type MarkovState.
MarkovState$name()Accessor function to retrieve the state name.
MarkovState$name()
State name.
MarkovState$set_cost()Set the annual occupancy cost.
MarkovState$set_cost(cost)
costThe annual cost of state occupancy
Updated MarkovState object.
MarkovState$cost()Gets the annual cost of state occupancy.
MarkovState$cost()
Annual cost; numeric.
MarkovState$set_utility()Set the utility of the state.
MarkovState$set_utility(utility)
utilityThe utility associated with being in the state (numeric
or ModVar).
Updated MarkovState object.
MarkovState$utility()Gets the utility associated with the state.
MarkovState$utility()
Utility; numeric.
MarkovState$modvars()Find all the model variables.
MarkovState$modvars()
Find variables of type ModVar that have been
specified as values associated with this MarkovState.
Includes operands of these ModVars, if they are expressions.
A list of ModVars.
MarkovState$clone()The objects of this class are cloneable with this method.
MarkovState$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class for a variable in a health economic model.
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.
ModVar$new()Create an object of type ModVar.
ModVar$new(description, units, D = NULL, k = 1L)
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.
ModVar$is_expression()Is this ModVar an expression?
ModVar$is_expression()
TRUE if it inherits from ExprModVar, FALSE
otherwise.
ModVar$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
ModVar$description()Accessor function for the description.
ModVar$description()
Description of model variable as character string.
ModVar$units()Accessor function for units.
ModVar$units()
Description of units as character string.
ModVar$distribution()Name and parameters of the uncertainty distribution.
ModVar$distribution()
If 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.
ModVar$mean()Mean value of the model variable.
ModVar$mean()
Mean value as a numeric value.
ModVar$mode()The mode of the variable.
ModVar$mode()
May return NA, which will be the case for
most ModVar variables, because arbitrary distributions are
not guaranteed to be unimodal.
Mode as a numeric value.
ModVar$SD()Standard deviation of the model variable.
ModVar$SD()
Standard deviation as a numeric value
ModVar$quantile()Quantiles of the uncertainty distribution.
ModVar$quantile(probs)
probsNumeric vector of probabilities, each in range [0,1].
Vector of numeric values of the same length as probs.
ModVar$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.
ModVar$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.
ModVar$get()Get the value of the ModVar.
ModVar$get()
Returns the value defined by the most recent call
to set().
Value determined by last set().
ModVar$clone()The objects of this class are cloneable with this method.
ModVar$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
An R6 class representing a node in a graph.
A base class to represent a single node in a graph.
Node$new()Create new Node object.
Node$new(label = "")
labelAn optional label for the node.
A new Node object.
Node$label()Return the label of the node.
Node$label()
Label as a character string.
Node$modvars()Find all the model variables of type ModVar that have
been specified as values associated with this Node.
Node$modvars()
An empty list for the base class.
Node$type()node type
Node$type()
Node class, as character string.
Node$clone()The objects of this class are cloneable with this method.
Node$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
An R6 class representing a parametrized Normal distribution.
A Normal distribution with hyperparameters mean (mu) and
standard deviation (sd). Inherits from class Distribution.
Distribution -> NormalDistribution
NormalDistribution$new()Create a parametrized normal distribution.
NormalDistribution$new(mu, sigma)
muMean of the Normal distribution.
sigmaStandard deviation of the Normal distribution.
A NormalDistribution object.
NormalDistribution$distribution()Accessor function for the name of the distribution.
NormalDistribution$distribution()
Distribution name as character string.
NormalDistribution$sample()Draw a random sample from the model variable.
NormalDistribution$sample(expected = FALSE)
expectedIf TRUE, sets the next value retrieved by a call to
r() to be the mean of the distribution.
A sample drawn at random.
NormalDistribution$mean()Return the mean value of the distribution.
NormalDistribution$mean()
Expected value as a numeric value.
NormalDistribution$SD()Return the standard deviation of the distribution.
NormalDistribution$SD()
Standard deviation as a numeric value
NormalDistribution$quantile()Return the quantiles of the Normal uncertainty distribution.
NormalDistribution$quantile(probs)
probsVector of probabilities, in range [0,1].
Vector of quantiles.
NormalDistribution$clone()The objects of this class are cloneable with this method.
NormalDistribution$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing a model variable with Normal uncertainty.
A model variable for which the uncertainty in its point estimate can
be modelled with a Normal distribution. The hyperparameters of the
distribution are the mean (mu) and the standard deviation (sd)
of the uncertainty distribution. The value of mu is the expected value
of the variable. Inherits from class ModVar.
ModVar -> NormModVar
NormModVar$new()Create a model variable with normal uncertainty.
NormModVar$new(description, units, mu, sigma)
descriptionA character string describing the variable.
unitsUnits of the quantity; character string.
muHyperparameter with mean of the Normal distribution for the uncertainty of the variable.
sigmaHyperparameter equal to the standard deviation of the normal distribution for the uncertainty of the variable.
A NormModVar object.
NormModVar$is_probabilistic()Tests whether the model variable is probabilistic.
NormModVar$is_probabilistic()
TRUE if probabilistic.
NormModVar$clone()The objects of this class are cloneable with this method.
NormModVar$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing a reaction (chance) edge in a decision tree.
A specialism of class Arrow which is used in a decision tree
to represent edges whose source nodes are ChanceNodes.
Reaction$new()Create an object of type Reaction. A probability
must be assigned
to the edge. Optionally, a cost and a benefit may be associated
with traversing the edge. A pay-off (benefit-cost) is sometimes
used in edges of decision trees; the parametrization used here is more
general.
Reaction$new( source_node, target_node, p = 0, cost = 0, benefit = 0, label = "" )
source_nodeChance node from which the reaction leaves.
target_nodeNode which the reaction enters.
pConditional probability of traversing the reaction edge. At most one Reaction from each chance node may have this set to 'NA_real_', in which case it will be replaced by one minus the sum of conditional probabilities of the other reaction edges from the node.
costCost associated with traversal of this edge (numeric or
ModVar), not NA.
benefitBenefit associated with traversal of the edge (numeric or
ModVar), not NA.
labelCharacter string containing the reaction label.
A new Reaction object.
Reaction$grob()Creates a grid::grob for a reaction edge.
Reaction$grob(xs, ys, xt, yt, fs = 0.2)
xsx coordinate of source of edge, grid::unit object.
ysy coordinate of source of edge, grid::unit object.
xtx coordinate of target of edge, grid::unit object.
yty coordinate of target of edge, grid::unit object.
fsFraction of the edge which slopes.
A grid::grob containing the symbol and label.
Reaction$modvars()Find all the model variables of type ModVar that
have been specified as values associated with this Action. Includes
operands of these ModVars, if they are expressions.
Reaction$modvars()
A list of ModVars.
Reaction$set_probability()Set the probability associated with the reaction edge.
Reaction$set_probability(p)
pConditional probability of traversing the reaction edge. Of type
numeric or ModVar. If numeric, p must be in the range
[0,1], or NA_real_. Note that setting p = NA will cause
an error.
Updated Reaction object.
Reaction$p()Return the current value of the edge probability, i.e., the conditional probability of traversing the edge.
Reaction$p()
Numeric value in range [0,1].
Reaction$set_cost()Set the cost associated with the reaction edge.
Reaction$set_cost(c = 0)
cCost associated with traversing the reaction edge. Of type
numeric or ModVar.
Updated Reaction object.
Reaction$cost()Return the cost associated with traversing the edge.
Reaction$cost()
Cost.
Reaction$set_benefit()Set the benefit associated with the reaction edge.
Reaction$set_benefit(b = 0)
bBenefit associated with traversing the reaction edge. Of type
numeric or ModVar.
Updated Action object.
Reaction$benefit()Return the benefit associated with traversing the edge.
Reaction$benefit()
Benefit.
Reaction$clone()The objects of this class are cloneable with this method.
Reaction$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
An R6 class representing a semi-Markov model for cohort simulation.
A class to represent a continuous time semi-Markov chain, modelled using cohort simulation. As interpreted in rdecision, semi-Markov models may include temporary states and transitions are defined by per-cycle probabilities. Although used widely in health economic modelling, the differences between semi-Markov models and Markov processes introduce some caveats for modellers:
If there are temporary states, the result will depend on cycle length.
Transitions are specified by their conditional probability, which is a per-cycle probability of starting a cycle in one state and ending it in another; if the cycle length changes, the probabilities should change, too.
Probabilities and rates cannot be linked by the Kolmogorov forward equation, where the per-cycle probabilities are given by the matrix exponential of the transition rate matrix, because this equation does not apply if there are temporary states. In creating semi-Markov models, it is the modeller's task to estimate probabilities from published data on event rates.
The cycle time cannot be changed during the simulation.
A Markov model is a directed multidigraph permitting loops (a loop multidigraph), optionally labelled, or a quiver. It is a multidigraph because there are potentially two edges between each pair of nodes {A,B} representing the transition probabilities from A to B and vice versa. It is a directed graph because the transition probabilities refer to transitions in one direction. Each edge can be optionally labelled. It permits self-loops (edges whose source and target are the same node) to represent patients that remain in the same state between cycles.
Beck and Pauker (1983) and later Sonnenberg and Beck (1993) proposed the use of Markov processes to model the health economics of medical interventions. Further, they introduced the additional concept of temporary states, to which patients who transition remain for exactly one cycle. This breaks the principle that Markov processes are memoryless and thus the underlying mathematical formalism, first developed by Kolmogorov, is not applicable. For example, ensuring that all patients leave a temporary state requires its transition rate to be infinite. Hence, such models are usually labelled as semi-Markov processes.
Miller and Homan (1994) and Fleurence & Hollenbeak (2007) provide advice
on estimating probabilities from rates. Jones (2017) and Welton (2005)
describe methods for estimating probabilities in multi-state,
multi-transition models, although those methods may not apply to
semi-Markov models with temporary states. In particular, the
"simple" equation, (Briggs 2006) applies only in a
two-state, one transition model (O'Mahony 2015).
In semi-Markov models, the conditional probabilities of the transitions
from each state are usually modelled by a Dirichlet distribution. In
rdecision, create a Dirichlet distribution for each state and
optionally create model variables for each conditional probability
() linked to an applicable Dirichlet distribution.
Graph -> Digraph -> SemiMarkovModel
Graph$degree()Graph$edge_along()Graph$edge_at()Graph$edge_index()Graph$edge_label()Graph$edges()Graph$graph_adjacency_matrix()Graph$has_edge()Graph$has_vertex()Graph$is_simple()Graph$neighbours()Graph$order()Graph$size()Graph$vertex_along()Graph$vertex_at()Graph$vertex_index()Graph$vertex_label()Graph$vertexes()Digraph$arrow_source()Digraph$arrow_target()Digraph$as_DOT()Digraph$as_gml()Digraph$digraph_adjacency_matrix()Digraph$digraph_incidence_matrix()Digraph$direct_predecessors()Digraph$direct_successors()Digraph$is_acyclic()Digraph$is_arborescence()Digraph$is_connected()Digraph$is_polytree()Digraph$is_tree()Digraph$is_weakly_connected()Digraph$paths()Digraph$topological_sort()Digraph$walk()SemiMarkovModel$new()Creates a semi-Markov model for cohort simulation.
SemiMarkovModel$new( V, E, tcycle = as.difftime(365.25, units = "days"), discount.cost = 0, discount.utility = 0 )
VA list of nodes (MarkovStates).
EA list of edges (Transitions).
tcycleCycle length, expressed as an R difftime object.
discount.costAnnual discount rate for future costs. Note this is a rate, not a probability (i.e. use 0.035 for 3.5%).
discount.utilityAnnual discount rate for future utility. Note this is a rate, not a probability (i.e. use 0.035 for 3.5%).
A semi-Markov model must meet the following conditions:
It must have at least one node and at least one edge.
All nodes must be of class MarkovState;
All edges must be of class Transition;
The nodes and edges must form a digraph whose underlying graph is connected;
Each state must have at least one outgoing transition (for absorbing states this is a self-loop);
For each state the sum of outgoing conditional transition
probabilities must be one. For convenience, one outgoing transition
probability from each state may be set to NA when the
probabilities are defined. Typically, probabilities for self
loops would be set to NA. Transition probabilities in
associated with transitions that are not defined as edges in the
graph are zero. Probabilities can be changed between cycles.
No two edges may share the same source and target nodes (i.e. the digraph may not have multiple edges). This is to ensure that there are no more transitions than cells in the transition matrix.
The node labels must be unique to the graph.
A SemiMarkovModel object. The population of the first
state is set to 1000 and from each state there is an equal
conditional probability of each allowed transition.
SemiMarkovModel$set_probabilities()Sets transition probabilities.
SemiMarkovModel$set_probabilities(Pt)
PtPer-cycle transition probability matrix. The row and
column labels must be the state names and each row must sum to one.
Non-zero probabilities for undefined transitions are not allowed. At
most one NA may appear in each row. If an NA is present in a row,
it is replaced by 1 minus the sum of the defined probabilities.
Updated SemiMarkovModel object
SemiMarkovModel$transition_probabilities()Per-cycle transition probability matrix for the model.
SemiMarkovModel$transition_probabilities()
A square matrix of size equal to the number of states. If all states are labelled, the dimnames take the names of the states.
SemiMarkovModel$transition_cost()Return the per-cycle transition costs for the model.
SemiMarkovModel$transition_cost()
A square matrix of size equal to the number of states. If all states are labelled, the dimnames take the names of the states.
SemiMarkovModel$get_statenames()Returns a character list of state names.
SemiMarkovModel$get_statenames()
List of the names of each state.
SemiMarkovModel$reset()Resets the model counters.
SemiMarkovModel$reset( populations = NULL, icycle = 0L, elapsed = as.difftime(0, units = "days") )
populationsA named vector of populations for
the start of the state. The names should be the state names.
Due to the R implementation of matrix algebra, populations
must be a numeric type and is not restricted to being an integer. If
NULL, the population of all states is set to zero.
icycleCycle number at which to start/restart.
elapsedElapsed time since the index (reference) time used for
discounting as an R difftime object.
Resets the state populations, next cycle number and elapsed time
of the model. By default the model is returned to its ground state (zero
people in the all states; next cycle is labelled
zero; elapsed time (years) is zero). Any or all of these can be set via
this function. icycle is simply an integer counter label for each
cycle, elapsed sets the elapsed time in years from the index time
from which discounting is assumed to apply.
Updated SemiMarkovModel object.
SemiMarkovModel$get_populations()Gets the occupancy of each state.
SemiMarkovModel$get_populations()
A numeric vector of populations, named with state names.
SemiMarkovModel$get_cycle()Gets the current cycle number.
SemiMarkovModel$get_cycle()
Current cycle count, as an integer.
SemiMarkovModel$get_tcycle()Gets the cycle duration.
SemiMarkovModel$get_tcycle()
Current cycle duration, as a difftime object.
SemiMarkovModel$get_elapsed()Gets the current elapsed time.
SemiMarkovModel$get_elapsed()
The elapsed time is defined as the difference between the
current time in the model and an index time used as the reference
time for applying discounting. By default the elapsed time starts at
zero. It can be set directly by calling reset. It is incremented
after each call to cycle by the cycle duration to the time at the
end of the cycle (even if half cycle correction is used). Thus, via the
reset and cycle methods, the time of each cycle relative
to the discounting index and its duration can be controlled arbitrarily.
Elapsed time as an R difftime object.
SemiMarkovModel$tabulate_states()Tabulation of states
SemiMarkovModel$tabulate_states()
Creates a data frame summary of each state in the model.
A data frame with the following columns:
State name
Annual cost of occupying the state
Incremental utility associated with being in the state.
SemiMarkovModel$cycle()Applies one cycle of the model.
SemiMarkovModel$cycle(hcc.pop = TRUE, hcc.cost = TRUE, hcc.QALY = TRUE)
hcc.popDetermines the state populations returned by this
function. If FALSE, the end of cycle populations apply; if TRUE the
mid-cycle populations and time apply. The mid-cycle populations are
taken as the mean of the start and end populations and the discount
time as the mid-point. The value of this parameter does not affect the
state populations or elapsed time passed to the next cycle or available
via get_populations; those are always the end cycle values.
hcc.costDetermines the state occupancy costs returned by this
function and the time at which the cost discount is applied to the
occupancy costs and the entry costs. If FALSE, the end of cycle
populations and time apply; if TRUE the mid-cycle populations and time
apply, as per hcc.pop. The value of this parameter does not affect
the state populations or elapsed time passed to the next cycle or
available via get_populations; those are always the end cycle
values.
hcc.QALYDetermines the incremental quality adjusted life years
returned by this function and the time at which the utility discount is
applied. If FALSE, the end of cycle population and reference time are
applied to the utilities of each state; if TRUE the mid-cycle populations
and time are applied to the state utilities. The value of this parameter
does not affect the state populations or elapsed time passed to the next
cycle or available via get_populations; those are always the
end cycle values.
Calculated values, one row per state, as a data frame with the following columns:
StateName of the state.
CycleThe cycle number.
TimeClock time in years of the end of the cycle.
PopulationPopulations of the states; see hcc.pop.
OccCostCost of the population occupying the state for
the cycle. Discounting and half cycle correction is applied, if those
options are set. The costs are normalized by the model population. The
cycle costs are derived from the annual occupancy costs of the
MarkovStates.
EntryCostCost of the transitions into the state
during the cycle. Discounting is applied, if the option is set.
The result is normalized by the model population. The cycle costs
are derived from Transition costs.
CostTotal cost, normalized by model population.
QALYQuality adjusted life years gained by occupancy of the states during the cycle. Half cycle correction and discounting are applied, if these options are set. Normalized by the model population.
SemiMarkovModel$cycles()Applies multiple cycles of the model.
SemiMarkovModel$cycles( ncycles = 2L, hcc.pop = TRUE, hcc.cost = TRUE, hcc.QALY = TRUE )
ncyclesNumber of cycles to run; default is 2.
hcc.popDetermines the state populations returned by this
function. If FALSE, the end of cycle populations apply; if TRUE the
mid-cycle populations and time apply. The mid-cycle populations are
taken as the mean of the start and end populations and the discount
time as the mid-point. The value of this parameter does not affect the
state populations or elapsed time passed to the next cycle or available
via get_populations; those are always the end cycle values.
hcc.costDetermines the state occupancy costs returned by this
function and the time at which the cost discount is applied to the
occupancy costs and the entry costs. If FALSE, the end of cycle
populations and time apply; if TRUE the mid-cycle populations and time
apply, as per hcc.pop. The value of this parameter does not affect
the state populations or elapsed time passed to the next cycle or
available via get_populations; those are always the end cycle
values.
hcc.QALYDetermines the incremental quality adjusted life years
returned by this function and the time at which the utility discount is
applied. If FALSE, the end of cycle population and reference time are
applied to the utilities of each state; if TRUE the mid-cycle populations
and time are applied to the state utilities. The value of this parameter
does not affect the state populations or elapsed time passed to the next
cycle or available via get_populations; those are always the
end cycle values.
The starting populations are redistributed through the
transition probabilities and the state occupancy costs are
calculated, using function cycle. The end populations are
then fed back into the model for a further cycle and the
process is repeated. For each cycle, the state populations and
the aggregated occupancy costs are saved in one row of the
returned data frame, with the cycle number. If the cycle count
for the model is zero when called, the first cycle reported
will be cycle zero, i.e. the distribution of patients to starting
states.
Data frame with cycle results, with the following columns:
CycleThe cycle number.
YearsElapsed time at end of cycle, years.
CostCost associated with occupancy and transitions between states during the cycle.
QALYQuality adjusted life years associated with occupancy of the states in the cycle.
<name>Population of state <name> at the end of
the cycle.
SemiMarkovModel$modvars()Find all the model variables in the Markov model.
SemiMarkovModel$modvars()
Returns variables of type ModVar that have been
specified as values associated with transition rates and costs and
the state occupancy costs and utilities.
A list of ModVars.
SemiMarkovModel$modvar_table()Tabulate the model variables in the Markov model.
SemiMarkovModel$modvar_table()
Data frame with one row per model variable, as follows:
DescriptionAs given at initialization.
UnitsUnits of the variable.
DistributionEither the uncertainty distribution, if
it is a regular model variable, or the expression used to create it,
if it is an ExprModVar.
MeanMean; calculated from means of operands if an expression.
EExpectation; estimated from random sample if expression, mean otherwise.
SDStandard deviation; estimated from random sample if expression, exact value otherwise.
Q2.5p=0.025 quantile; estimated from random sample if expression, exact value otherwise.
Q97.5p=0.975 quantile; estimated from random sample if expression, exact value otherwise.
EstTRUE if the quantiles and SD have been estimated by random sampling.
SemiMarkovModel$clone()The objects of this class are cloneable with this method.
SemiMarkovModel$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]
Beck JR and Pauker SG. The Markov Process in Medical Prognosis. Med Decision Making, 1983;3:419–458.
Briggs A, Claxton K, Sculpher M. Decision modelling for health economic evaluation. Oxford, UK: Oxford University Press; 2006.
Fleurence RL and Hollenbeak CS. Rates and probabilities in economic modelling. PharmacoEconomics, 2007;25:3–6.
Jones E, Epstein D and García-Mochón L. A procedure for deriving formulas to convert transition rates to probabilities for multistate Markov models. Medical Decision Making 2017;37:779–789.
Miller DK and Homan SM. Determining transition probabilities: confusion and suggestions. Medical Decision Making 1994;14:52-58.
O'Mahony JF, Newall AT, van Rosmalen J. Dealing with time in health economic evaluation: methodological issues and recommendations for practice. PharmacoEconomics 2015;33:1255–1268.
Sonnenberg FA, Beck JR. Markov models in medical decision making: a practical guide. Medical Decision Making, 1993:13:322.
Welton NJ and Ades A. Estimation of Markov chain transition probabilities and rates from fully and partially observed data: uncertainty propagation, evidence synthesis, and model calibration. Medical Decision Making, 2005;25:633-645.
An R6 class representing a stack of objects of any type.
Conventional implementation of a stack. Used extensively in graph algorithms and offered as a separate class for ease of programming and to ensure that implementations of stacks are optimized. By intention, there is only minimal checking of method arguments. This is to maximize performance and because the class is mainly intended for use internally to rdecision.
Stack$new()Create a stack.
Stack$new()
A new Stack object.
Stack$push()Push an item onto the stack.
Stack$push(x)
xThe item to push onto the top of the stack. It should be of the same class as items previously pushed on to the stack. It is not checked.
An updated Stack object
Stack$pop()Pop an item from the stack. Stack underflow raises an error.
Stack$pop()
The item previously at the top of the stack.
Stack$size()Gets the number of items on the stack.
Stack$size()
Number of items.
Stack$as_list()Inspect items in the stack.
Stack$as_list()
A list of items.
Stack$clone()The objects of this class are cloneable with this method.
Stack$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew Sims [email protected]
A function to plot a tornado diagram, given a data frame of model variable names, their confidence limits and the values of the outcome variable for each. The outcome measure (x axis) is expected to be cost, ICER, net monetary benefit, etc., but can be any meaningful quantity.
tornado_plot(to, outcome_mean, xlab = "")tornado_plot(to, outcome_mean, xlab = "")
to |
A data frame with one row per horizontal bar of the tornado plot, with columns:
|
outcome_mean |
Mean (base case) outcome. |
xlab |
Label for x axis |
An R6 class representing a transition in a semi-Markov model.
A specialism of class Arrow which is used in a semi-Markov
model to represent a transition between two MarkovStates. The
transition is optionally associated with a cost. The transition probability
is associated with the model (SemiMarkovModel) rather than the
transition.
Transition$new()Create an object of type MarkovTransition.
Transition$new(source_state, target_state, cost = 0, label = "")
source_stateMarkovState from which the transition starts.
target_stateMarkovState to which the transition ends.
costCost associated with the transition.
labelCharacter string containing a label for the transition (the name of the event).
A new Transition object.
Transition$modvars()Find all the model variables.
Transition$modvars()
Find variables of type ModVar that have been
specified as values associated with this MarkovTransition.
Includes operands of these ModVars, if they are expressions.
A list of ModVars.
Transition$set_cost()Set the cost associated with the transition.
Transition$set_cost(c = 0)
cCost associated with the transition.
Updated Transition object.
Transition$cost()Return the cost associated with traversing the edge.
Transition$cost()
Cost.
Transition$clone()The objects of this class are cloneable with this method.
Transition$clone(deep = FALSE)
deepWhether to make a deep clone.
Andrew J. Sims [email protected]