/
dtree.html
452 lines (385 loc) · 22.3 KB
/
dtree.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<title>Model > Decide > Decision analysis</title>
<script src="libs/jquery-1.11.3/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="libs/bootstrap-3.3.5/css/united.min.css" rel="stylesheet" />
<script src="libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style type="text/css">
/* padding for bootstrap navbar */
body {
padding-top: 50px;
padding-bottom: 40px;
}
/* offset scroll position for anchor links (for fixed navbar) */
.section h2 {
padding-top: 55px;
margin-top: -55px;
}
.section h3 {
padding-top: 55px;
margin-top: -55px;
}
/* don't use link color in navbar */
.dropdown-menu>li>a {
display: inline;
color: black;
padding-top: 0;
padding-bottom: 0;
}
.dropdown-menu .divider {
margin-top: 2px;
margin-bottom: 2px;
}
img {
max-width: 85% !important;
}
/*
img.center {
display: block;
margin: 0 auto;
}
*/
</style>
<link rel="stylesheet" href="libs/font-awesome-4.1.0/css/font-awesome.min.css"/>
<link rel="shortcut icon" type="image/png" href="/docs/images/radiant_red.png"/>
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet"
href="libs/highlight/textmate.css"
type="text/css" />
<script src="libs/highlight/highlight.js"></script>
<style type="text/css">
pre:not([class]) {
background-color: white;
}
</style>
<script type="text/javascript">
if (window.hljs && document.readyState && document.readyState === "complete") {
window.setTimeout(function() {
hljs.initHighlighting();
}, 0);
}
</script>
<style type="text/css">
h1 {
font-size: 34px;
}
h1.title {
font-size: 38px;
}
h2 {
font-size: 30px;
}
h3 {
font-size: 24px;
}
h4 {
font-size: 18px;
}
h5 {
font-size: 16px;
}
h6 {
font-size: 12px;
}
.table th:not([align]) {
text-align: left;
}
</style>
</head>
<body>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
.tabbed-pane {
padding-top: 12px;
}
button.code-folding-btn:focus {
outline: none;
}
</style>
<div class="container-fluid main-container">
<!-- tabsets -->
<script src="libs/navigation-1.0/tabsets.js"></script>
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
</script>
<!-- code folding -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://github.com/radiant-rstats/docs">Radiant</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/docs/index.html">Home</a></li>
<li><a href="/docs/news.html">News</a></li>
<li class="dropdown">
<a href="/docs/data/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Data<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="/docs/data/manage.html">Manage</a></li>
<li><a href="/docs/data/view.html">View</a></li>
<li><a href="/docs/data/visualize.html">Visualize</a></li>
<li><a href="/docs/data/pivotr.html">Pivot</a></li>
<li><a href="/docs/data/explore.html">Explore</a></li>
<li><a href="/docs/data/transform.html">Transform</a></li>
<li><a href="/docs/data/combine.html">Combine</a></li>
</ul>
</li>
<li class="dropdown">
<a href="/docs/design/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Design<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">DOE</li>
<li><a href="/docs/design/doe.html">Design of Experiments (DOE)</a></li>
<li class="divider"></li>
<li class="dropdown-header">Sample</li>
<li><a href="/docs/design/sampling.html">Sampling</a></li>
<li><a href="/docs/design/sample_size.html">Sample size (single)</a></li>
<li><a href="/docs/design/sample_size_comp.html">Sample size (compare)</a></li>
</ul>
</li>
<li class="dropdown">
<a href="/docs/basics/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Basics<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Probability</li>
<li><a href="/docs/basics/prob_calc.html">Probability calculator</a></li>
<li><a href="/docs/basics/clt.html">Central Limit Theorem</a></li>
<li class="divider"></li>
<li class="dropdown-header">Means</li>
<li><a href="/docs/basics/single_mean.html">Single mean</a></li>
<li><a href="/docs/basics/compare_means.html">Compare means</a></li>
<li class="divider"></li>
<li class="dropdown-header">Proportions</li>
<li><a href="/docs/basics/single_prop.html">Single proportion</a></li>
<li><a href="/docs/basics/compare_props.html">Compare proportions</a></li>
<li class="divider"></li>
<li class="dropdown-header">Tables</li>
<li><a href="/docs/basics/goodness.html">Goodness of fit</a></li>
<li><a href="/docs/basics/cross_tabs.html">Cross-tabs</a></li>
<li><a href="/docs/basics/correlation.html">Correlation</a></li>
</ul>
</li>
<li class="dropdown">
<a href="/docs/model/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Model<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Estimate</li>
<li><a href="/docs/model/regress.html">Linear regression (OLS)</a></li>
<li><a href="/docs/model/logistic.html">Logistic regression (GLM)</a></li>
<li><a href="/docs/model/ann.html">Neural Network (ANN)</a></li>
<li class="divider"></li>
<li class="dropdown-header">Evaluate</li>
<li><a href="/docs/model/evalreg.html">Evaluate regression</a></li>
<li><a href="/docs/model/evalbin.html">Evaluate classification</a></li>
<li class="divider"></li>
<li class="dropdown-header">Decide</li>
<li><a href="/docs/model/dtree.html">Decision analysis</a></li>
<li><a href="/docs/model/simulater.html">Simulate</a></li>
</ul>
</li>
<li class="dropdown">
<a href="/docs/multivariate/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Multivariate<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">Maps</li>
<li><a href="/docs/multivariate/mds.html">(Dis)similarity</a></li>
<li><a href="/docs/multivariate/pmap.html">Attributes</a></li>
<li class="divider"></li>
<li class="dropdown-header">Factor</li>
<li><a href="/docs/multivariate/pre_factor.html">Pre-factor</a></li>
<li><a href="/docs/multivariate/full_factor.html">Factor</a></li>
<li class="divider"></li>
<li class="dropdown-header">Cluster</li>
<li><a href="/docs/multivariate/hier_clus.html">Hierarchical</a></li>
<li><a href="/docs/multivariate/kmeans_clus.html">K-means</a></li>
<li class="divider"></li>
<li class="dropdown-header">Conjoint</li>
<li><a href="/docs/multivariate/conjoint.html">Conjoint</a></li>
</ul>
</li>
<li class="dropdown">
<a href="/docs/R/" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">R<span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="/docs/data/report.html">Report</a></li>
<li><a href="/docs/data/code.html">Code</a></li>
<li><a href="/docs/programming.html">Programming</a></li>
<li><a href="/docs/resources.html">Resources</a></li>
</ul>
</li>
<li><a href="/docs/tutorials.html">Tutorials</a></li>
<li><a href="/docs/about.html">About</a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div class="fluid-row" id="header">
<h1 class="title toc-ignore">Model > Decide > Decision analysis</h1>
</div>
<hr />
<blockquote>
<p>Create and evaluate a decision tree for decision analysis</p>
</blockquote>
<p>To create and evaluate a decision tree first (1) enter the structure of the tree in the input editor or (2) load a tree structure from a file. When you first navigate to the <em>Model > Decision analysis</em> tab you will see an example tree structure. This structure is based on an <a href="https://github.com/gluc/useR15/blob/master/00_data/jennylind.yaml">example</a> by Christop Glur, the developer of the <a href="https://github.com/gluc/data.tree">data.tree</a> library.</p>
<p>To enter a new structure, start by providing a name for the tree and enter a label in the input box next to the <code>Calculate</code> button. In the example below the name for the decision tree is entered as follow: <code>name: Sign contract</code>. The next step is to indicate the <strong>type</strong> of the first <strong>node</strong>. Options are <code>type: decision</code> or <code>type: chance</code>. Note that we are skipping <code>variables</code> for now but will return to this section below.</p>
<p>In the provided example, the first node is a <strong>decision node</strong>. The decision maker has to decide to <code>Sign with Movie Company</code> or <code>Sign with TV Network</code>. The first option leads to a <strong>chance</strong> node with probabilities and payoffs. The second has a fixed payoff.</p>
<blockquote>
<p><strong>Note:</strong> Indentation is critically important when defining a tree structure. Use tabs to create branches as shown in the example. Names for branches <strong>must</strong> be followed by a <code>:</code> and information about the branch <strong>must</strong> be indented using the <code>tab</code> key.</p>
</blockquote>
<p>After providing the name for the decision <code>Sign with Movie Company</code>, the next line <strong>must</strong> be indented using the <code>tab</code> key. In the example, the next line starts the description of a chance node (<code>type: chance</code>). There are 3 possibilities in the example: (1) <code>Small Box Office</code>, (2) <code>Medium Box Office</code>, and (3) <code>Large Box Office</code>, each with a probability and a payoff. These are end-points for one branch of the tree and are often referred to as <code>terminal nodes</code> or <code>leaves</code>. All endpoints must have a <code>payoff</code> value.</p>
<blockquote>
<p><strong>Note:</strong> Probabilities for a chance node should sum to 1 and all probabilities must be smaller than 1.</p>
</blockquote>
<p>A decision can also be assigned a <code>cost</code>. For example, if we decide to sign with the movie studio we may incur a cost of $5,000 for legal support. Assume the contract with the TV network is simpler and does not reguire legal assistance. Note that using <code>costs</code> is optional. In the example we could also subtract $5,000 from each of the possible box-office payoffs.</p>
<p>If some values in the tree are relate or repeated it can be useful to use a <code>variables</code> section. Here you can assign labels to values and formulas. In the <code>Sign contract</code> example only one variable is created (i.e., <code>legal fees</code>). The <em>Sensitivity</em> tab requires that a variables section is included in the tree structure.</p>
<div id="rules-for-decision-tree-input" class="section level2">
<h2>Rules for decision tree input</h2>
<ol style="list-style-type: decimal">
<li>Always start with a tree name (e.g., <code>name: My tree</code>)</li>
<li>The second line should start a <code>variables</code> section or a node defintion (i.e., type: chance or type: decision)</li>
<li>All lines must have a <code>:</code>. For node names the <code>:</code> ends the line. For all other lines it assigns a value. Specically, it assigns a name (e.g., <code>name: My tree</code>), a node type (e.g., <code>type: decision</code>), a variable (e.g., <code>legal fees: 5000</code>), or a number (e.g., <code>payoff: 100</code>, <code>p: 0.1</code>, <code>cost: 10</code>)</li>
<li>A node type must be followed on the next line by a node name (e.g., <code>Cancel orders:</code>)</li>
<li>Use only letters and spaces in node names (i.e., no symbols)</li>
<li>The line after a node name must <strong>always</strong> be indented</li>
<li>End (or terminal or leave) nodes must have a payoff (e.g., <code>payoff: 100</code>)</li>
<li>If linked to a chance node, terminal nodes must have a probability (e.g, <code>p: 0.4</code>) and a payoff</li>
</ol>
<p>After specifying the tree structure in the editor, press the <code>Calculate</code> button to see the <code>Initial</code> and <code>Final</code> decision tree in text format on the right side of the screen (see screen shot below). The initial tree simply shows the tree structure that was specified, together with the node types, probabilities, costs, and payoffs. The final tree shows the optimal decision strategy determined by <code>folding-back</code> the tree. In this case, the optimal decision is to <code>Sign with Movie Company</code> because this decision has a higher <strong>Expected Monetary Value (EMV)</strong>.</p>
<p align="center">
<img src="figures_model/dtree_model.png">
</p>
<p>For a visual representation of the decision tree open the <em>Plot</em> tab. If you already clicked the <code>Calculate</code> button in the <em>Model</em> tab you will see a graph of the <code>Initial</code> decision tree (see screen shot below). Decision nodes are shown in green and chance nodes in orange. If the tree does not look as you intended/expected, return to the <em>Model</em> tab and edit the tree structure.</p>
<p align="center">
<img src="figures_model/dtree_plot_initial.png">
</p>
<p>The <code>Final</code> graph shows the optimal decision determined by <code>folding-back</code> the tree. The optimal decision is to <code>Sign with Movie Company</code> because this decision has a higher <strong>Expected Monetary Value</strong>. Note that the optimal decision at each decision node is shown by a thicker line connecting to the nodes.</p>
<p align="center">
<img src="figures_model/dtree_plot_final.png">
</p>
<p>The EMV for the <code>Sign with TV Network</code> is $900,000. The expected box office revenue following a decision to <code>Sign with Movie Company</code> is:</p>
<p><span class="math display">\[
0.3 \times 200,000 + 0.6 \times 1,000,000 + 0.1 \times 3000,000 - 5,000 = 955,000
\]</span></p>
<p>The EMV from signing with the movie company is however <span class="math inline">\(960,000 - 5,000 = 955,000\)</span>. Hover the cursor over the chance node shown on screen to see a <code>tooltip</code> that shows the calculation. To highlight that a <code>cost</code> was specified the chance node in the figure has a dashed outer line.</p>
<p>In the <code>Sign contract</code> example it is clear that <code>Sign with Movie Company</code> is the prefered option. However, suppose the legal fees associated with this option were $10,000, or $30,000, would we still choose the same option? This is where the <em>Sensitivity</em> tab is useful. Here we can evaluate how decisions (e.g., <code>Sign with Movie Company</code> and <code>Sign with TV Network</code>) would change if the legal fee changes. Enter 0 as the <code>Min</code> value, 80000 as the <code>Max value</code>, 10000 as the <code>Step</code> size, and then press the <i class="fa fa-plus"></i> icon. After pressing <code>Evaluate sensitivty</code> a graph will be shown that illustrates how payoffs for the decisions change. Notice that for legal fees higher than $60,000 <code>Sign with TV Network</code> produces the highest EMV.</p>
<p align="center">
<img src="figures_model/dtree_sensitivity.png">
</p>
</div>
<div id="buttons" class="section level2">
<h2>Buttons</h2>
<p>In the <em>Model</em> tab:</p>
<ul>
<li>To see this help file click the <i class="fa fa-question" ></i> icon</li>
<li>To generate a report about the decision tree in the <em>R > Report</em> tab click the <i class="fa fa-edit" ></i> icon</li>
<li>Choose to maximize (<code>Max</code>) or minimize (<code>Min</code>) payoffs. Note that payoffs can be negative</li>
<li>Click the <code>Calculate</code> button to generate or update results</li>
<li>Specify a name for your decision tree in the text input next to the <code>Calculate</code> button. Clicking on the <code>Calculate</code> button will store your settings. If multiple tree structures are available there will also be a dropdown where you can select which structure to use and a <code>Remove</code> button to delete tree structures</li>
<li>To save the tree structure entered into the editor window to disk press the <code>Save input</code> button</li>
<li>To save the text representation of the initial and final tree to a file click the <code>Save output</code> button</li>
<li>To load a tree structure from a file in <code>yaml</code> format click the <code>Choose File</code> button</li>
</ul>
<p>In the <em>Plot</em> tab:</p>
<ul>
<li>To see this help file click the <i class="fa fa-question" ></i> icon</li>
<li>To generate a report about the decision tree in the <em>R > Report</em> tab click the <i class="fa fa-edit" ></i> icon</li>
<li>Show either the <code>Initial</code> or <code>Final</code> decision tree</li>
<li>Click the <code>Calculate</code> button to generate or update results</li>
<li>Enter the number of decimal places to show in the plot (default is 2 for payoffs and 4 for probabilities)</li>
<li>Provide a symbol to use for the payoffs (e.g., $ or RMB)</li>
<li>Click the download icon in the top right of your browser to <em>print</em> either the initial or final plot to a pdf-file</li>
</ul>
<p>In the <em>Sensitivity</em> tab:</p>
<ul>
<li>To see this help file click the <i class="fa fa-question" ></i> icon</li>
<li>To generate a report about the decision tree in the <em>R > Report</em> tab click the <i class="fa fa-edit" ></i> icon</li>
<li>Select <code>Decisions to evaluate</code></li>
<li>Select variables in <code>Sensitivity to changes in</code>. These variables must be defined in the decision tree structure in the <em>Model</em> tab</li>
<li>Enter the minimum, maximum, and step size for the selected variable and press the <i class="fa fa-plus"></i> icon</li>
<li>Press <code>Evaluate sensitity</code> to generate results and the plot</li>
<li>Click the download icon in the top right of your browser to <em>print</em> either the initial or final plot to a pdf-file</li>
</ul>
</div>
<div id="the-decision-tree-editor" class="section level2">
<h2>The decision tree editor</h2>
<p>Useful keyboard short-cuts:</p>
<ul>
<li>Comment current or selected line(s) (Win: Ctrl-/ Mac: Cmd-/)</li>
<li>Fold all lines (Win: Alt-0 Mac: Alt-Cmd-0)</li>
<li>Unfold all lines (Win: Shift-Alt-0 Mac: Shift-Alt-Cmd-0)</li>
<li>Search (Win: Ctrl-f, Mac: Cmd-f)</li>
<li>Search & Replace (Win: Ctrl-f-f, Mac: Cmd-f-f)</li>
<li>Undo edit (Win: Ctrl-z, Mac: Cmd-z)</li>
<li>Redo edit (Win: Shift-Ctrl-z, Mac: Shift-Cmd-z)</li>
</ul>
<p>You can also (un)fold lines using the small triangles next to the line numbers.</p>
<p>For additional shortcuts see:</p>
<p><a href="https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts" target="_blank">https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts</a></p>
</div>
© Vincent Nijs (2016) <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank"><img alt="Creative Commons License" style="border-width:0" src="/docs/images/80x15.png" /></a>
<!-- some extra javascript for older browsers -->
<script type="text/javascript" src="libs/polyfill.js"></script>
<!-- mathjax -->
<!-- <script type='text/javascript' src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script> -->
<script>
// manage active state of menu based on current page
$(document).ready(function () {
// active menu
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
$('a[href="' + href + '"]').parent().addClass('active');
// manage active menu header
if (href.startsWith('authoring_'))
$('a[href="' + 'authoring' + '"]').parent().addClass('active');
else if (href.endsWith('_format.html'))
$('a[href="' + 'formats' + '"]').parent().addClass('active');
else if (href.startsWith('developer_'))
$('a[href="' + 'developer' + '"]').parent().addClass('active');
});
// Google analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-61296577-1', 'auto');
ga('send', 'pageview');
</script>
</div>
<script>
// add bootstrap table styles to pandoc tables
$(document).ready(function () {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>