Author
Affiliation

Vagish Hemmige

Albert Einstein College of Medicine

The code in this script reruns the decision tree under four alternative sets of assumptions and saves the annotated trees shown on the scenario analyses results page. Each scenario changes one or more parameters and leaves every other parameter at its base-case value.

RcodeSource code

The full R script is available at:

The code sections below are imported directly from that script when this page is rendered.

This R script file is itself reliant on the following helper files:

Each section calls create_tree_diagram_QC() with the changed parameters, then exports the tree to SVG, adds the incremental cost, QALYs and net monetary benefit with add_svg_annotation(), and saves the result to figures/.

Scenario 1: transplants almost never cancelled after a positive screen

p_cancelled = 0.01. Saved as figures/alternative_tree_1_annotated.svg.

Click to show/hide R Code
#Run the base case tree diagram, where organ wastage is nearly eliminated
alternative_tree_1<-create_tree_diagram_QC(p_cancelled = 0.01)

#Convert the tree diagram to svg, then XML, then add the annotation and save
export_svg(alternative_tree_1$plot)%>%
  read_xml()%>%
  add_svg_annotation(
  c("Screening vs no screening:",
    glue("• ΔC = {scales::number(alternative_tree_1$cost_difference, accuracy = 0.01)}"),
    glue("• ΔQ = {formatC(alternative_tree_1$qaly_difference, format = 'f', digits = 4)}"),
    glue("• NMB = {scales::number(alternative_tree_1$nmb, accuracy = 0.01)}")
    )
  )%>%
  write_xml("figures/alternative_tree_1_annotated.svg")

Scenario 2: almost no cancellations and near-universal prophylaxis

p_cancelled = 0.01 and p_prophrate = 0.99. Saved as figures/alternative_tree_2_annotated.svg.

Click to show/hide R Code
#Run the base case tree diagram, where organ wastage is nearly eliminated and near-universal prophylaxis is achieved
alternative_tree_2<-create_tree_diagram_QC(p_cancelled = 0.01,
                                           p_prophrate = 0.99)

#Convert the tree diagram to svg, then XML, then add the annotation and save
export_svg(alternative_tree_2$plot)%>%
  read_xml()%>%
  add_svg_annotation(
    c("Screening vs no screening:",
      glue("• ΔC = {scales::number(alternative_tree_2$cost_difference, accuracy = 0.01)}"),
      glue("• ΔQ = {formatC(alternative_tree_2$qaly_difference, format = 'f', digits = 4)}"),
      glue("• NMB = {scales::number(alternative_tree_2$nmb, accuracy = 0.01)}")
    )
  )%>%
  write_xml("figures/alternative_tree_2_annotated.svg")

Scenario 3: much higher cost of cryptococcal disease

cost_disease = 3,000,000. Saved as figures/alternative_tree_3_annotated.svg.

Click to show/hide R Code
#Run the base case tree diagram, where cost of cryptococcus is $3 million
alternative_tree_3<-create_tree_diagram_QC(cost_disease = 3000000)

#Convert the tree diagram to svg, then XML, then add the annotation and save
export_svg(alternative_tree_3$plot)%>%
  read_xml()%>%
  add_svg_annotation(
    c("Screening vs no screening:",
      glue("• ΔC = {scales::number(alternative_tree_3$cost_difference, accuracy = 0.01)}"),
      glue("• ΔQ = {formatC(alternative_tree_3$qaly_difference, format = 'f', digits = 4)}"),
      glue("• NMB = {scales::number(alternative_tree_3$nmb, accuracy = 0.01)}")
    )
  )%>%
  write_xml("figures/alternative_tree_3_annotated.svg")

Scenario 4: all three changes combined

p_cancelled = 0.01, p_prophrate = 0.99 and cost_disease = 3,000,000. Saved as figures/alternative_tree_4_annotated.svg.

Click to show/hide R Code
#Assume both very high costs of disease as well as near-perfect implementation
alternative_tree_4<-create_tree_diagram_QC(p_cancelled = 0.01,
                                           p_prophrate = 0.99,
                                           cost_disease = 3000000)

#Convert the tree diagram to svg, then XML, then add the annotation and save
export_svg(alternative_tree_4$plot)%>%
  read_xml()%>%
  add_svg_annotation(
    c("Screening vs no screening:",
      glue("• ΔC = {scales::number(alternative_tree_4$cost_difference, accuracy = 0.01)}"),
      glue("• ΔQ = {formatC(alternative_tree_4$qaly_difference, format = 'f', digits = 4)}"),
      glue("• NMB = {scales::number(alternative_tree_4$nmb, accuracy = 0.01)}")
    )
  )%>%
  write_xml("figures/alternative_tree_4_annotated.svg")

#Save the scenario results for the website
scenario_results<-tibble(
  scenario = 1:4,
  description = c(
    "p_cancelled = 0.01",
    "p_cancelled = 0.01, p_prophrate = 0.99",
    "cost_disease = 3000000",
    "p_cancelled = 0.01, p_prophrate = 0.99, cost_disease = 3000000"
  ),
  tree = list(alternative_tree_1, alternative_tree_2, alternative_tree_3, alternative_tree_4)
)%>%
  mutate(
    cost_difference = map_dbl(tree, "cost_difference"),
    qaly_difference = map_dbl(tree, "qaly_difference"),
    nmb = map_dbl(tree, "nmb")
  )%>%
  select(-tree)
write_csv(scenario_results, "output/scenario_results.csv")