This is a helper package for the AD616 course in Enterprise Risk Analytics at BU. The primary purpose of this package is to allow you to build decision trees and do sensitivity analysis and stochastic optimization on the decision trees. It also helps you visualize the Trees and the Expected Values, calculate PayOffs and Utilities with built-in functions.
You can install the package using the devtools
package in R.
devtools::install_github("WXCode/AD616")
and then load the package with the library
command
library (AD616)
The package allows you to build a decision Tree with the following options - Root Node - The Root node is by default a decision node. - Decision Nodes - Decision nodes are typically represented by rectangles and have an yes or no branch - Chance Nodes - Chance nodes represent probabilistic outcomes and always have a cost associated with performing the experiment - Terminal Nodes - Terminal Nodes are outcomes which will have payoffs associated with them
Use new
method to create and initialize the new tree
new_tree <- Tree$new('newTree')
To add a chance node, use the tree that was created and define the parent node where the Chance node needs to connect to. A chance is an experiment and there is always a cost attached to it.
new_tree$addChance(name='chance_1',parent='new_tree',route='Yes',cost=20)
To add a terminal node, use the tree that was created and define the parent node where the terminal node needs to connect to. A terminal is an experiment and there is always a payoff attached to it. If the parent node is a chance event then add the probability from the chance event that leads to the terminal node
new_tree$addTerminal(name='term_1',parent='chance_1',prob,payoff)
To calculate the EMV of the decision Tree, invoke update_payoff() function from the root node.
new_tree$update_payoff()
This will automatically traverse through the decision tree and calculate the EMV
The optimal decision path can be accessed at
new_tree$DecisionPath
To calculate the Utility of the decision analysis, invoke update_utility from the root node.
new_tree$update_utility()
We make use of the data.tree
package heavily in creating the graphical models. We also use stats package and R6 package.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.