Skip to content

Commit 49c620c

Browse files
committed
add README.R for high level script
1 parent 1daaaa9 commit 49c620c

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

README.R

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
## ----set-options, echo=FALSE, cache=FALSE--------------------------------
2+
options(width = 1000)
3+
4+
## ----eval=FALSE----------------------------------------------------------
5+
## library(devtools)
6+
## install_github("n8thangreen/treeSimR")
7+
8+
## ----eval=FALSE----------------------------------------------------------
9+
## library("treeSimR")
10+
11+
## ----load packages, echo=FALSE, warning=FALSE----------------------------
12+
library(yaml)
13+
library(data.tree)
14+
devtools::load_all(".")
15+
16+
17+
## ------------------------------------------------------------------------
18+
# osList <- yaml.load(yaml)
19+
osList <- yaml.load_file("raw data/LTBI_dtree-cost-distns.yaml")
20+
osNode <- as.Node(osList)
21+
osNode
22+
23+
## ------------------------------------------------------------------------
24+
osNode <- treeSimR::costeffectiveness_tree(yaml_tree = "raw data/LTBI_dtree-cost-distns.yaml")
25+
print(osNode, "type", "p", "distn", "mean", "sd")
26+
27+
## ----eval=FALSE----------------------------------------------------------
28+
## library(listviewer)
29+
## l <- ToListSimple(osNode)
30+
## jsonedit(l)
31+
32+
## ------------------------------------------------------------------------
33+
rpayoff <- osNode$Get(sampleNode)
34+
osNode$Set(payoff = rpayoff)
35+
print(osNode, "type", "p", "distn", "mean", "sd", "payoff")
36+
37+
## ------------------------------------------------------------------------
38+
osNode$Do(payoff, traversal = "post-order", filterFun = isNotLeaf)
39+
40+
print(osNode, "type", "p", "distn", "mean", "sd", "payoff")
41+
42+
## ------------------------------------------------------------------------
43+
osNode <- calc_expectedValues(osNode)
44+
print(osNode, "type", "p", "distn", "mean", "sd", "payoff")
45+
46+
## ------------------------------------------------------------------------
47+
MonteCarlo_expectedValues(osNode, n=100)
48+
49+
## ------------------------------------------------------------------------
50+
path_probs <- calc_pathway_probs(osNode)
51+
osNode$Set(path_probs = path_probs)
52+
53+
terminal_states <- data.frame(pathname = osNode$Get('pathString', filterFun = isLeaf),
54+
path_probs = osNode$Get('path_probs', filterFun = isLeaf))
55+
terminal_states
56+
57+
## ------------------------------------------------------------------------
58+
startstate_prob <- matrix(NA, nrow = 3, ncol = 2,
59+
dimnames = list(c("<40k","40-150k",">150k"), c("LTBI","nonLTBI")))
60+
61+
startstate.LTBI <- grepl("/Complete Treatment", x = terminal_states$pathname) | grepl("non-LTBI", x = terminal_states$pathname)
62+
63+
startstate_prob["<40k","nonLTBI"] <- sum(terminal_states$path_probs[grepl("under 40k cob incidence", x = terminal_states$pathname) &
64+
startstate.LTBI])
65+
66+
startstate_prob["<40k","LTBI"] <- sum(terminal_states$path_probs[grepl("under 40k cob incidence", x = terminal_states$pathname) &
67+
!startstate.LTBI])
68+
69+
startstate_prob["40-150k","nonLTBI"] <- sum(terminal_states$path_probs[grepl("40-150k cob incidence", x = terminal_states$pathname) &
70+
startstate.LTBI])
71+
72+
startstate_prob["40-150k","LTBI"] <- sum(terminal_states$path_probs[grepl("40-150k cob incidence", x = terminal_states$pathname) &
73+
!startstate.LTBI])
74+
75+
startstate_prob[">150k","nonLTBI"] <- sum(terminal_states$path_probs[grepl("over 150k cob incidence", x = terminal_states$pathname) &
76+
startstate.LTBI])
77+
78+
startstate_prob[">150k","LTBI"] <- sum(terminal_states$path_probs[grepl("over 150k cob incidence", x = terminal_states$pathname) &
79+
!startstate.LTBI])
80+
81+
knitr::kable(startstate_prob/sum(startstate_prob))
82+
83+
## ------------------------------------------------------------------------
84+
osNode <- calc_riskprofile(osNode)
85+
print(osNode, "type", "path_prob", "path_payoff")
86+
87+
## ------------------------------------------------------------------------
88+
plot(data.frame(osNode$Get('path_payoff', filterFun = isLeaf),
89+
osNode$Get('path_prob', filterFun = isLeaf)), type="h",
90+
xlab="payoff", ylab="probability")
91+
92+
## ----eval=FALSE----------------------------------------------------------
93+
## ##TODO##
94+
## osNode$Do(decision, filterFun = function(x) x$type == 'decision')
95+
## osNode$Get('decision')[1]
96+
97+
## ----eval=FALSE----------------------------------------------------------
98+
## ##TODO##
99+
## ## probabilty of successfully & correctly treating LTBI
100+
## dummy <- rep(0, osNode$totalCount)
101+
## dummy[12] <- 1
102+
## osNode$Set(payoff = dummy)
103+
## print(osNode, "type", "p", "distn", "mean", "sd", "payoff")
104+
## osNode$Do(payoff, traversal = "post-order", filterFun = isNotLeaf)
105+
## print(osNode, "type", "p", "distn", "mean", "sd", "payoff")
106+
## osNode$Get('payoff')[1]
107+

0 commit comments

Comments
 (0)