knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
PSA is a core part of any cost-effectiveness analysis [@Briggs2012]. Here we will carry this out for a simple decision tree. This involves repeatedly sampling from a distribution for each branch probability and cost and calculating the total expected value for each set of realisations.
library(CEdecisiontree, quietly = TRUE) library(assertthat, quietly = TRUE) library(tibble, quietly = TRUE) library(tidyverse, quietly = TRUE) library(purrr, quietly = TRUE)
We first define the decision tree. The difference to previous trees is that we now use the list-column feature to define distributions rather than point values.
tree_dat <- list(child = list("1" = c(2, 3), "2" = NULL, "3" = NULL), dat = tibble( node = 1:3, prob = list( NA_real_, list(distn = "unif", params = c(min = 0, max = 1)), list(distn = "unif", params = c(min = 0, max = 1))), vals = list( 0L, list(distn = "unif", params = c(min = 0, max = 1)), list(distn = "unif", params = c(min = 0, max = 1))))) tree_dat
We can now loop over this tree and generate samples of values for the given distributions.
We use the sample_distributions()
function to do this.
This is all wrapped up in the convenience function create_psa_inputs
.
library(purrr) tree_dat_sa <- create_psa_inputs(tree_dat, n = 1000)
This results in a list of trees.
head(tree_dat_sa, 2)
Now it is straightforward to map over each of these trees to obtain the total expected values
res <- map_dbl(tree_dat_sa, dectree_expected_values) head(res) hist(res, breaks = 20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.