This document demonstrates running the screening, diagnosis and treatment decision tree model.

First, we need to attach the packages we’ll need. treeSimR is written by us too so this will need to be installed from GitHub.

library(treeSimR)
library(LTBIscreeningproject)
library(dplyr)
library(data.tree)
library(purrr)

Load in data

data("intervention_constants", package = "LTBIscreeningproject")
data("cost_effectivness_params", package = "LTBIscreeningproject")
data("scenario_parameters", package = "LTBIscreeningproject")
load("model_input_cohort.RData")

Intervention specific individual-level data

According to the parameter values we specified in interv we first need to prepare the cohort data set to only include those individuals we’re interested in analysing.

Only use a single year cohort

cohort <- dplyr::filter(IMPUTED_sample,
                        issdt_year == interv$year_cohort)

EWNI stay long enough to be screened

cohort <- dplyr::filter(cohort,
                        date_exit_uk1_issdt.years >= interv$min_screen_length_of_stay)

Only keep those inidiviuals that are screened before some other event

if (interv$screen_with_delay) {
  cohort <- dplyr::filter(cohort,
                          screen == 1)
}

Do we include student in the screening programme?

if (interv$no_students) {
  cohort <- dplyr::filter(cohort,
                          visatype2 != "Students")}

Include individuals from ‘higher’ incidence countries only

cohort <- dplyr::filter(cohort,
                        who_prev_cat_Pareek2011 %in% interv$incidence_grps_screen)

Count numbers of TB cases

n.exit_tb <-
  cohort %>%
  dplyr::filter(exituk_tb) %>%
  dplyr::count()

n.uk_tb <-
  cohort %>%
  dplyr::filter(uk_tb) %>%
  dplyr::count()


num_all_tb_cost <-
  if (interv$ENDPOINT_cost == "exit uk") {
    n.uk_tb
  } else if (interv$ENDPOINT_cost == "death") {
    n.uk_tb + n.exit_tb}

num_all_tb_QALY <-
  if (interv$ENDPOINT_QALY == "exit uk") {
    n.uk_tb
  } else if (interv$ENDPOINT_QALY == "death") {
    n.uk_tb + n.exit_tb}
saveRDS(cohort, file = "cohort.Rds")

Prepare decision tree

Load input files. We have defined the decision tree using YAML syntax. We have a separate trees for cost and health. They have the same structure and probabilities but different values on the branches. We also create our own class.

osNode.cost.fileName <- system.file("data", "LTBI_dtree-cost-symptoms.yaml",
                                    package = "LTBIscreeningproject")

osNode.health.fileName <- system.file("data", "LTBI_dtree-QALYloss-symptoms.yaml",
                                      package = "LTBIscreeningproject")

costeff.cost <- treeSimR::costeffectiveness_tree(yaml_tree = osNode.cost.fileName)
osNode.cost <- costeff.cost$osNode

costeff.health <- treeSimR::costeffectiveness_tree(yaml_tree = osNode.health.fileName)
osNode.health <- costeff.health$osNode
#> Warning in treeSimR::costeffectiveness_tree(yaml_tree = "LTBI_dtree-cost-symptoms.yaml"): Check type of attributes. Should they be numeric rather than character?
#> $osNode
#>                                                  levelName distn    max    min       p  scale shape     type
#> 1   LTBI screening cost                                     unif   0.00   0.00 1.00000     NA    NA  logical
#> 2    ¦--(0,50]                                              unif   0.00   0.00 0.00000                chance
#> 3    ¦   ¦--LTBI                                            unif   0.00   0.00 0.03000                chance
#> 4    ¦   ¦   ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 5    ¦   ¦   °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 6    ¦   ¦       ¦--1-Sensitivity                           unif   0.00   0.00 0.16000              terminal
#> 7    ¦   ¦       °--Sensitivity                             unif   0.00   0.00 0.84000                chance
#> 8    ¦   ¦           ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 9    ¦   ¦           °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 10   ¦   ¦               ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 11   ¦   ¦               ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 12   ¦   ¦               ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 13   ¦   ¦               ¦   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 14   ¦   ¦               ¦   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 15   ¦   ¦               ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 16   ¦   ¦               ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 17   ¦   ¦               ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 18   ¦   ¦               ¦       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 19   ¦   ¦               ¦       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 20   ¦   ¦               ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 21   ¦   ¦               °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 22   ¦   ¦                   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 23   ¦   ¦                   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 24   ¦   ¦                   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 25   ¦   ¦                   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 26   ¦   ¦                   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 27   ¦   ¦                   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 28   ¦   ¦                       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 29   ¦   ¦                       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 30   ¦   ¦                       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 31   ¦   ¦                       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 32   ¦   °--non-LTBI                                        unif   0.00   0.00 0.97000                chance
#> 33   ¦       ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 34   ¦       °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 35   ¦           ¦--Specificity                             unif   0.00   0.00 0.99000              terminal
#> 36   ¦           °--1-Specificity                           unif   0.00   0.00 0.01000                chance
#> 37   ¦               ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 38   ¦               °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 39   ¦                   ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 40   ¦                   ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 41   ¦                   ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 42   ¦                   ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 43   ¦                   ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 44   ¦                   ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 45   ¦                   ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 46   ¦                   °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 47   ¦                       ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 48   ¦                       ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 49   ¦                       ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 50   ¦                       °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 51   ¦                           ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 52   ¦                           °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 53   ¦--(50,150]                                            unif   0.00   0.00 0.04000                chance
#> 54   ¦   ¦--LTBI                                            unif   0.00   0.00 0.03000                chance
#> 55   ¦   ¦   ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 56   ¦   ¦   °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 57   ¦   ¦       ¦--1-Sensitivity                           unif   0.00   0.00 0.16000              terminal
#> 58   ¦   ¦       °--Sensitivity                             unif   0.00   0.00 0.84000                chance
#> 59   ¦   ¦           ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 60   ¦   ¦           °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 61   ¦   ¦               ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 62   ¦   ¦               ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 63   ¦   ¦               ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 64   ¦   ¦               ¦   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 65   ¦   ¦               ¦   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 66   ¦   ¦               ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 67   ¦   ¦               ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 68   ¦   ¦               ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 69   ¦   ¦               ¦       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 70   ¦   ¦               ¦       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 71   ¦   ¦               ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 72   ¦   ¦               °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 73   ¦   ¦                   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 74   ¦   ¦                   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 75   ¦   ¦                   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 76   ¦   ¦                   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 77   ¦   ¦                   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 78   ¦   ¦                   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 79   ¦   ¦                       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 80   ¦   ¦                       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 81   ¦   ¦                       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 82   ¦   ¦                       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 83   ¦   °--non-LTBI                                        unif   0.00   0.00 0.97000                chance
#> 84   ¦       ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 85   ¦       °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 86   ¦           ¦--Specificity                             unif   0.00   0.00 0.99000              terminal
#> 87   ¦           °--1-Specificity                           unif   0.00   0.00 0.01000                chance
#> 88   ¦               ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 89   ¦               °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 90   ¦                   ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 91   ¦                   ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 92   ¦                   ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 93   ¦                   ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 94   ¦                   ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 95   ¦                   ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 96   ¦                   ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 97   ¦                   °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 98   ¦                       ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 99   ¦                       ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 100  ¦                       ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 101  ¦                       °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 102  ¦                           ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 103  ¦                           °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 104  ¦--(150,250]                                           unif   0.00   0.00 0.16000                chance
#> 105  ¦   ¦--LTBI                                            unif   0.00   0.00 0.03000                chance
#> 106  ¦   ¦   ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 107  ¦   ¦   °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 108  ¦   ¦       ¦--1-Sensitivity                           unif   0.00   0.00 0.16000              terminal
#> 109  ¦   ¦       °--Sensitivity                             unif   0.00   0.00 0.84000                chance
#> 110  ¦   ¦           ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 111  ¦   ¦           °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 112  ¦   ¦               ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 113  ¦   ¦               ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 114  ¦   ¦               ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 115  ¦   ¦               ¦   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 116  ¦   ¦               ¦   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 117  ¦   ¦               ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 118  ¦   ¦               ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 119  ¦   ¦               ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 120  ¦   ¦               ¦       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 121  ¦   ¦               ¦       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 122  ¦   ¦               ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 123  ¦   ¦               °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 124  ¦   ¦                   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 125  ¦   ¦                   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 126  ¦   ¦                   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 127  ¦   ¦                   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 128  ¦   ¦                   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 129  ¦   ¦                   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 130  ¦   ¦                       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 131  ¦   ¦                       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 132  ¦   ¦                       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 133  ¦   ¦                       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 134  ¦   °--non-LTBI                                        unif   0.00   0.00 0.97000                chance
#> 135  ¦       ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 136  ¦       °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 137  ¦           ¦--Specificity                             unif   0.00   0.00 0.99000              terminal
#> 138  ¦           °--1-Specificity                           unif   0.00   0.00 0.01000                chance
#> 139  ¦               ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 140  ¦               °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 141  ¦                   ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 142  ¦                   ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 143  ¦                   ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 144  ¦                   ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 145  ¦                   ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 146  ¦                   ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 147  ¦                   ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 148  ¦                   °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 149  ¦                       ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 150  ¦                       ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 151  ¦                       ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 152  ¦                       °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 153  ¦                           ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 154  ¦                           °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 155  ¦--(250,350]                                           unif   0.00   0.00 0.60000                chance
#> 156  ¦   ¦--LTBI                                            unif   0.00   0.00 0.03000                chance
#> 157  ¦   ¦   ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 158  ¦   ¦   °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 159  ¦   ¦       ¦--1-Sensitivity                           unif   0.00   0.00 0.16000              terminal
#> 160  ¦   ¦       °--Sensitivity                             unif   0.00   0.00 0.84000                chance
#> 161  ¦   ¦           ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 162  ¦   ¦           °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 163  ¦   ¦               ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 164  ¦   ¦               ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 165  ¦   ¦               ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 166  ¦   ¦               ¦   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 167  ¦   ¦               ¦   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 168  ¦   ¦               ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 169  ¦   ¦               ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 170  ¦   ¦               ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 171  ¦   ¦               ¦       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 172  ¦   ¦               ¦       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 173  ¦   ¦               ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 174  ¦   ¦               °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 175  ¦   ¦                   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 176  ¦   ¦                   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 177  ¦   ¦                   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 178  ¦   ¦                   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 179  ¦   ¦                   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 180  ¦   ¦                   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 181  ¦   ¦                       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 182  ¦   ¦                       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 183  ¦   ¦                       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 184  ¦   ¦                       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 185  ¦   °--non-LTBI                                        unif   0.00   0.00 0.97000                chance
#> 186  ¦       ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 187  ¦       °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 188  ¦           ¦--Specificity                             unif   0.00   0.00 0.99000              terminal
#> 189  ¦           °--1-Specificity                           unif   0.00   0.00 0.01000                chance
#> 190  ¦               ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 191  ¦               °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 192  ¦                   ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 193  ¦                   ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 194  ¦                   ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 195  ¦                   ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 196  ¦                   ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 197  ¦                   ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 198  ¦                   ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 199  ¦                   °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 200  ¦                       ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 201  ¦                       ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 202  ¦                       ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 203  ¦                       °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 204  ¦                           ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 205  ¦                           °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 206  °--(350,1e+05]                                         unif   0.00   0.00 0.20000                chance
#> 207      ¦--LTBI                                            unif   0.00   0.00 0.03000                chance
#> 208      ¦   ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 209      ¦   °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 210      ¦       ¦--1-Sensitivity                           unif   0.00   0.00 0.16000              terminal
#> 211      ¦       °--Sensitivity                             unif   0.00   0.00 0.84000                chance
#> 212      ¦           ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 213      ¦           °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 214      ¦               ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 215      ¦               ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 216      ¦               ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 217      ¦               ¦   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 218      ¦               ¦   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 219      ¦               ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 220      ¦               ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 221      ¦               ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 222      ¦               ¦       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 223      ¦               ¦       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 224      ¦               ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 225      ¦               °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 226      ¦                   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 227      ¦                   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 228      ¦                   ¦   ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 229      ¦                   ¦   ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 230      ¦                   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 231      ¦                   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 232      ¦                       ¦--Complete Treatment      unif 842.45 511.69 0.80000                chance
#> 233      ¦                       ¦   ¦--Effective           unif   0.00   0.00 0.90000              terminal
#> 234      ¦                       ¦   °--Not Effective       unif   0.00   0.00 0.10000              terminal
#> 235      ¦                       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 236      °--non-LTBI                                        unif   0.00   0.00 0.97000                chance
#> 237          ¦--Not Agree to Screen                         unif   0.00   0.00 0.40000              terminal
#> 238          °--Agree to Screen                             unif 106.00  50.00 0.60000                chance
#> 239              ¦--Specificity                             unif   0.00   0.00 0.99000              terminal
#> 240              °--1-Specificity                           unif   0.00   0.00 0.01000                chance
#> 241                  ¦--Not Start Treatment                 unif   0.00   0.00 0.30000              terminal
#> 242                  °--Start Treatment                     unif   0.00   0.00 0.70000                chance
#> 243                      ¦--Symptoms Hepatotoxicity        gamma     NA     NA 0.00245 87.889 6.679   chance
#> 244                      ¦   ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 245                      ¦   ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 246                      ¦   ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 247                      ¦   °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 248                      ¦       ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 249                      ¦       °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 250                      °--Not Symptoms Hepatotoxicity     unif   0.00   0.00 0.99755                chance
#> 251                          ¦--Symptoms Nausea            gamma     NA     NA 0.14300     13     5   chance
#> 252                          ¦   ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 253                          ¦   °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 254                          °--Not Symptoms Nausea         unif   0.00   0.00 0.85700                chance
#> 255                              ¦--Complete Treatment      unif 842.45 511.69 0.80000              terminal
#> 256                              °--Not Complete Treatment  unif 140.41  85.24 0.20000              terminal
#> 
#> $data
#> $data$data_prob
#> [1] NA
#> 
#> $data$data_val
#> [1] NA
#> 
#> 
#> attr(,"details")
#> [1] ""
#> attr(,"class")
#> [1] "costeffectiveness_object" "list"

Create look-up tables using the cohort data to give proportion in each incidence in country of origin and the probability of LTBI for each of these.

who_levels <- c("(0,50]", "(50,150]", "(150,250]", "(250,350]", "(350,1e+05]")

p_incid_grp <- miscUtilities::prop_table(cohort$who_prev_cat_Pareek2011)

pLatentTB.who <- data.frame(who_prev_cat_Pareek2011 = names(p_incid_grp),
                            LTBI = c(0.03, 0.13, 0.2, 0.3, 0.3))

Then insert these probabilities in to the decision tree

for (i in seq_along(who_levels)) {
  
  osNode.cost$Set(p = p_incid_grp[i],
                  filterFun = function(x) x$name == who_levels[i])
  
  osNode.health$Set(p = p_incid_grp[i],
                    filterFun = function(x) x$name == who_levels[i])
}

for (i in who_levels) {
  
  pLTBI <- subset(pLatentTB.who,
                  who_prev_cat_Pareek2011 == i,
                  select = LTBI)
  
  osNode.cost$Set(p = pLTBI,
                  filterFun = function(x) x$pathString == miscUtilities::pastef("LTBI screening cost", i, "LTBI"))
  osNode.health$Set(p = pLTBI,
                    filterFun = function(x) x$pathString == miscUtilities::pastef("LTBI screening QALY loss", i, "LTBI"))
  
  osNode.cost$Set(p = 1 - pLTBI,
                  filterFun = function(x) x$pathString == miscUtilities::pastef("LTBI screening cost", i, "non-LTBI"))
  osNode.health$Set(p = 1 - pLTBI,
                    filterFun = function(x) x$pathString == miscUtilities::pastef("LTBI screening QALY loss", i, "non-LTBI"))
}

Decision tree output

Now we can run the decision tree model using the scenario parameter values, active TB cases, and cost and health decision tree objects.

A single scenario:

decision_tree_cluster(parameters = scenario_parameters[[1]],
                      N.mc = interv$N.mc,
                      n.uk_tb = 10, #as.numeric(n.uk_tb),
                      n.exit_tb = 10, #as.numeric(n.exit_tb),
                      cost_dectree = "osNode_cost_2009.Rds",
                      health_dectree = "osNode_health_2009.Rds")
#> $mc_cost
#>  [1] 37.27940 36.37491 37.06578 36.67532 36.26612 36.40452 36.22418 36.55427 36.97845 37.68561
#> 
#> $mc_health
#>  [1] 4.806743e-06 5.340375e-06 5.137309e-06 5.309466e-06 4.995974e-06 4.651200e-06 5.618218e-06 5.200578e-06 5.229864e-06 4.938510e-06
#> 
#> $n_tb_screen_all
#>    sim       status  n
#> 1    1 disease-free  4
#> 2    1           tb 16
#> 3    2 disease-free  2
#> 4    2           tb 18
#> 5    3 disease-free  4
#> 6    3           tb 16
#> 7    4 disease-free  1
#> 8    4           tb 19
#> 9    5 disease-free  5
#> 10   5           tb 15
#> 11   6 disease-free  5
#> 12   6           tb 15
#> 13   7 disease-free  5
#> 14   7           tb 15
#> 15   8 disease-free  4
#> 16   8           tb 16
#> 17   9 disease-free  3
#> 18   9           tb 17
#> 19  10 disease-free  2
#> 20  10           tb 18
#> 
#> $n_tb_screen_uk
#>    sim       status  n
#> 1    1 disease-free  1
#> 2    1           tb  9
#> 3    2 disease-free  4
#> 4    2           tb  6
#> 5    3 disease-free  2
#> 6    3           tb  8
#> 7    4 disease-free  0
#> 8    4           tb 10
#> 9    5 disease-free  0
#> 10   5           tb 10
#> 11   6 disease-free  1
#> 12   6           tb  9
#> 13   7 disease-free  1
#> 14   7           tb  9
#> 15   8 disease-free  0
#> 16   8           tb 10
#> 17   9 disease-free  4
#> 18   9           tb  6
#> 19  10 disease-free  0
#> 20  10           tb 10
#> 
#> $p_LTBI_to_effectiveTx
#> (350,1e+05] 
#>    0.108864 
#> 
#> $subset_pop
#>    LTBI_pre tests  positive    startTx completeTx      cured LTBI_post
#> 1 0.2868171   0.6 0.1488349 0.08930096 0.05358058 0.03122406 0.2555931
#> 
#> $call
#> decision_tree_cluster(parameters = scenario_parameters[[1]], 
#>     N.mc = interv$N.mc, n.uk_tb = 10, n.exit_tb = 10, cost_dectree = "osNode_cost_2009.Rds", 
#>     health_dectree = "osNode_health_2009.Rds")
#> 
#> $N.mc
#> [1] 10

Multiple scenarios:

lapply(scenario_parameters[1:3],
       decision_tree_cluster,
       N.mc = 1,
       n.uk_tb = 10, #as.numeric(n.uk_tb),
       n.exit_tb = 10, #as.numeric(n.exit_tb),
       cost_dectree = "osNode_cost_2009.Rds",
       health_dectree = "osNode_health_2009.Rds")
#> $`1`
#> $`1`$mc_cost
#> [1] 36.51917
#> 
#> $`1`$mc_health
#> [1] 5.271375e-06
#> 
#> $`1`$n_tb_screen_all
#>   sim       status  n
#> 1   1 disease-free  2
#> 2   1           tb 18
#> 
#> $`1`$n_tb_screen_uk
#>   sim       status n
#> 1   1 disease-free 1
#> 2   1           tb 9
#> 
#> $`1`$p_LTBI_to_effectiveTx
#> (350,1e+05] 
#>    0.108864 
#> 
#> $`1`$subset_pop
#>    LTBI_pre tests  positive    startTx completeTx      cured LTBI_post
#> 1 0.2868171   0.6 0.1488349 0.08930096 0.05358058 0.03122406 0.2555931
#> 
#> $`1`$call
#> FUN(parameters = X[[i]], N.mc = 1, n.uk_tb = 10, n.exit_tb = 10, 
#>     cost_dectree = "osNode_cost_2009.Rds", health_dectree = "osNode_health_2009.Rds")
#> 
#> $`1`$N.mc
#> [1] 1
#> 
#> 
#> $`2`
#> $`2`$mc_cost
#> [1] 44.03829
#> 
#> $`2`$mc_health
#> [1] 7.074663e-06
#> 
#> $`2`$n_tb_screen_all
#>   sim       status  n
#> 1   1 disease-free  3
#> 2   1           tb 17
#> 
#> $`2`$n_tb_screen_uk
#>   sim       status n
#> 1   1 disease-free 2
#> 2   1           tb 8
#> 
#> $`2`$p_LTBI_to_effectiveTx
#> (350,1e+05] 
#>    0.145152 
#> 
#> $`2`$subset_pop
#>    LTBI_pre tests  positive   startTx completeTx      cured LTBI_post
#> 1 0.2868171   0.6 0.1488349 0.1190679 0.07144077 0.04163208 0.2451851
#> 
#> $`2`$call
#> FUN(parameters = X[[i]], N.mc = 1, n.uk_tb = 10, n.exit_tb = 10, 
#>     cost_dectree = "osNode_cost_2009.Rds", health_dectree = "osNode_health_2009.Rds")
#> 
#> $`2`$N.mc
#> [1] 1
#> 
#> 
#> $`3`
#> $`3`$mc_cost
#> [1] 52.58395
#> 
#> $`3`$mc_health
#> [1] 9.690061e-06
#> 
#> $`3`$n_tb_screen_all
#>   sim       status  n
#> 1   1 disease-free  6
#> 2   1           tb 14
#> 
#> $`3`$n_tb_screen_uk
#>   sim       status n
#> 1   1 disease-free 1
#> 2   1           tb 9
#> 
#> $`3`$p_LTBI_to_effectiveTx
#> (350,1e+05] 
#>     0.18144 
#> 
#> $`3`$subset_pop
#>    LTBI_pre tests  positive   startTx completeTx     cured LTBI_post
#> 1 0.2868171   0.6 0.1488349 0.1488349 0.08930096 0.0520401  0.234777
#> 
#> $`3`$call
#> FUN(parameters = X[[i]], N.mc = 1, n.uk_tb = 10, n.exit_tb = 10, 
#>     cost_dectree = "osNode_cost_2009.Rds", health_dectree = "osNode_health_2009.Rds")
#> 
#> $`3`$N.mc
#> [1] 1