DecisionTree | R Documentation |
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
Action
s 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 t = 0
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.
rdecision::Graph
-> rdecision::Digraph
-> rdecision::Arborescence
-> DecisionTree
rdecision::Graph$degree()
rdecision::Graph$edge_along()
rdecision::Graph$edge_at()
rdecision::Graph$edge_index()
rdecision::Graph$edge_label()
rdecision::Graph$edges()
rdecision::Graph$graph_adjacency_matrix()
rdecision::Graph$has_edge()
rdecision::Graph$has_vertex()
rdecision::Graph$is_simple()
rdecision::Graph$neighbours()
rdecision::Graph$order()
rdecision::Graph$size()
rdecision::Graph$vertex_along()
rdecision::Graph$vertex_at()
rdecision::Graph$vertex_index()
rdecision::Graph$vertex_label()
rdecision::Graph$vertexes()
rdecision::Digraph$arrow_source()
rdecision::Digraph$arrow_target()
rdecision::Digraph$as_DOT()
rdecision::Digraph$as_gml()
rdecision::Digraph$digraph_adjacency_matrix()
rdecision::Digraph$digraph_incidence_matrix()
rdecision::Digraph$direct_predecessors()
rdecision::Digraph$direct_successors()
rdecision::Digraph$is_acyclic()
rdecision::Digraph$is_arborescence()
rdecision::Digraph$is_connected()
rdecision::Digraph$is_polytree()
rdecision::Digraph$is_tree()
rdecision::Digraph$is_weakly_connected()
rdecision::Digraph$paths()
rdecision::Digraph$topological_sort()
rdecision::Digraph$walk()
rdecision::Arborescence$is_leaf()
rdecision::Arborescence$is_parent()
rdecision::Arborescence$is_root()
rdecision::Arborescence$parent()
rdecision::Arborescence$postree()
rdecision::Arborescence$root()
rdecision::Arborescence$root_to_leaf_paths()
rdecision::Arborescence$siblings()
new()
Create a new decision tree.
DecisionTree$new(V, E)
V
A list of nodes.
E
A 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
decision_nodes()
Find the decision nodes in the tree.
DecisionTree$decision_nodes(what = "node")
what
A 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").
chance_nodes()
Find the chance nodes in the tree.
DecisionTree$chance_nodes(what = "node")
what
A 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").
leaf_nodes()
Find the leaf nodes in the tree.
DecisionTree$leaf_nodes(what = "node")
what
One 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").
actions()
Find the edges that have the specified decision node as their source.
DecisionTree$actions(d)
d
A decision node.
A list of Action
edges.
modvars()
Find all the model variables of type ModVar
.
DecisionTree$modvars()
Find ModVar
s that have been specified as values
associated with the nodes and edges of the tree.
A list of ModVar
s.
modvar_table()
Tabulate the model variables.
DecisionTree$modvar_table()
Data frame with one row per model variable, as follows:
Description
As given at initialization.
Units
Units of the variable.
Distribution
Either the uncertainty distribution, if
it is a regular model variable, or the expression used to create it,
if it is an ExprModVar
.
Mean
Mean; calculated from means of operands if an expression.
E
Expectation; estimated from random sample if expression, mean otherwise.
SD
Standard deviation; estimated from random sample if expression, exact value otherwise.
Q2.5
p=0.025 quantile; estimated from random sample if expression, exact value otherwise.
Q97.5
p=0.975 quantile; estimated from random sample if expression, exact value otherwise.
Est
TRUE if the quantiles and SD have been estimated by random sampling.
draw()
Draw the decision tree to the current graphics output.
DecisionTree$draw(border = FALSE, fontsize = 8)
border
If TRUE draw a light grey border around the plot area.
fontsize
Font 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.
is_strategy()
Tests whether an object is a valid strategy.
DecisionTree$is_strategy(strategy)
strategy
A 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.
strategy_table()
Find all potential strategies for the decision tree.
DecisionTree$strategy_table(what = "index", select = NULL)
what
A character string defining what to return. Must be one of "label" or "index".
select
A 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.
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.
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.
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)
W
A 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.
Wi
As 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:
Probability
The probability of traversing the pathway.
Path.Cost
The cost of traversing the pathway.
Path.Benefit
The benefit derived from traversing the pathway.
Path.Utility
The utility associated with the outcome (leaf node).
Path.QALY
The QALYs associated with the outcome (leaf node).
Cost
Path.Cost
*
probability of traversing the
pathway.
Benefit
Path.Benefit
*
probability of
traversing the pathway.
Utility
Path.Utility
*
probability of
traversing the pathway.
QALY
Path.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.
evaluate()
Evaluate each strategy.
DecisionTree$evaluate(setvars = "expected", N = 1L, by = "strategy")
setvars
One 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).
N
Number of replicates. Intended for use with PSA
(modvars = "random"
); use with modvars
= "expected"
will be repetitive and uninformative.
by
One 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"
Run
Run number
<label of first decision node>
label of action leaving the node
<label of second decision node (etc.)>
label of action leaving the node
Leaf
The label of terminating leaf node
Probability
Probability of traversing the path
Cost
Cost of traversing the path x probability
Benefit
Benefit of traversing the path x probability
Utility
Utility of traversing the path x probability
QALY
QALYs gained by those traversing the path
by = "strategy"
Run
Run number
<label of first decision node>
label of action leaving the node
<label of second decision node (etc)
label of action
Probability
\Sigma p_i
for the run (1)
Cost
Aggregate cost of the strategy
Benefit
Aggregate benefit of the strategy
Utility
Aggregate utility of the strategy
QALY
Aggregate QALY of the strategy
by = "run"
Run
Run 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".
tornado()
Create a "tornado" diagram.
DecisionTree$tornado( index, ref, outcome = "saving", exclude = NULL, draw = TRUE )
index
The index strategy (option) to be evaluated.
ref
The reference strategy (option) with which the index strategy will be compared.
outcome
One 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
\Delta C/\Delta E
and is expected to be positive at the point
estimate (i.e. in the NE or SW quadrants of the cost-effectiveness
plane), where \Delta C
is cost of index minus cost of reference,
and \Delta E
is utility of index minus utility of reference.
exclude
A list of descriptions of model variables to be excluded from the tornado.
draw
TRUE 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 ModVar
s.
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 )
index
The index strategy (option) to be evaluated.
ref
The reference strategy (option) with which the index strategy will be compared.
outcome
One 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
\Delta C/\Delta E
, which will normally be positive
at the point estimate (i.e. in the NE or SW quadrants of the
cost-effectiveness plane), where \Delta C
is cost of index minus
cost of reference and \Delta E
is utility of index minus utility
of reference.
mvd
The description of the model variable for which the threshold is to be found.
a
The lower bound of the range of values of mvd
to search
for the root (numeric).
b
The upper bound of the range of values of mvd
to search
for the root (numeric).
tol
The tolerance to which the threshold should be calculated (numeric).
lambda
The ICER threshold (threshold ratio) for outcome="ICER".
nmax
Maximum 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.
clone()
The objects of this class are cloneable with this method.
DecisionTree$clone(deep = FALSE)
deep
Whether to make a deep clone.
Andrew J. Sims andrew.sims@newcastle.ac.uk
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, \Sexpr[results=rd]{tools:::Rd_expr_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, \Sexpr[results=rd]{tools:::Rd_expr_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, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s40273-015-0309-4")}.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.