msdes

Introduction

This shows how to run the MS discrete event simulation model in its simplest case. Refer to articles for explanation of the internal workings.

Main options

Load the required packages

library(msdes)
library(magrittr)
library(WARDEN)
library(flexsurv)
#> Loading required package: survival
library(VGAM)
#> Loading required package: stats4
#> Loading required package: splines
#> 
#> Attaching package: 'VGAM'
#> The following objects are masked from 'package:flexsurv':
#> 
#>     AICc, dgompertz, pgompertz, qgompertz, rgompertz
library(MASS)
library(utils)
library(hesim)
library(purrr)
#> 
#> Attaching package: 'purrr'
#> The following object is masked from 'package:magrittr':
#> 
#>     set_names
library(rlang)
#> 
#> Attaching package: 'rlang'
#> The following objects are masked from 'package:purrr':
#> 
#>     flatten, flatten_chr, flatten_dbl, flatten_int, flatten_lgl,
#>     flatten_raw, invoke, splice
#> The following object is masked from 'package:magrittr':
#> 
#>     set_names
library(progressr)
library(data.table)
#> 
#> Attaching package: 'data.table'
#> The following object is masked from 'package:rlang':
#> 
#>     :=
#> The following object is masked from 'package:purrr':
#> 
#>     transpose
#> The following object is masked from 'package:base':
#> 
#>     %notin%
library(BCEA)
#> Registered S3 method overwritten by 'BCEA':
#>   method     from
#>   plot.evppi voi
#> The BCEA version loaded is: 2.4.83 (stable version)
#> A development version is available at https://giabaio.r-universe.dev/BCEA
#> 
#> Attaching package: 'BCEA'
#> The following object is masked from 'package:graphics':
#> 
#>     contour
library(voi)
#> 
#> Attaching package: 'voi'
#> The following object is masked from 'package:BCEA':
#> 
#>     evppi

model setup

Data is loaded with the function [rrmsdessetup()] below, all the data is self contained within this function. The user has the option to change a few of the inputs.

rrmsdessetup(  # change model settings or assumptions used in scenario analyses
  drc= 0.035, #3.5% discount rate for costs
  drq= 0.035, #3.5% discount rate for qalys
  time_horizon = 70, # number of years model is running for starting at intial age
  p_eid=0.6, # proportion of patients on external interval dosing
  jcvtest_cost= 0 #assumed free due to home service, test cost could be £247 privately but not offered in the NHS
  )

Run Model

Model is run with the function [rrmsdesmodel()] below. The user has the specify the number of patients and number of inputs.

rrmsdesmodel(n_patients=10,n_samples=10)
#> Analysis number: 1
#> Simulation number: 1
#> Time to run simulation 1: 1.17s
#> Simulation number: 2
#> Time to run simulation 2: 1.18s
#> Simulation number: 3
#> Time to run simulation 3: 1.08s
#> Simulation number: 4
#> Time to run simulation 4: 1.1s
#> Simulation number: 5
#> Time to run simulation 5: 1.16s
#> Simulation number: 6
#> Time to run simulation 6: 1.32s
#> Simulation number: 7
#> Time to run simulation 7: 1.09s
#> Simulation number: 8
#> Time to run simulation 8: 1.03s
#> Simulation number: 9
#> Time to run simulation 9: 1.09s
#> Simulation number: 10
#> Time to run simulation 10: 1.2s
#> Time to run analysis 1: 11.43s
#> Total time to run: 11.43s
#> Simulation finalized;

Plot Results

# Summarise the results

dim_results <- c(n_samples, n_treatments, n_patients)
trt_idx <- setNames(seq_along(v_treatment_names), v_treatment_names)
total_costs_ipd <- total_qalys_ipd <-  array(
  NA_real_,
  dim = dim_results,
  dimnames = list(NULL, v_treatment_names, NULL)
)

for (i_sample in seq_len(n_samples)) {
  
  df <- results[[1]][[i_sample]]$merged_df
  
  # Keep only final ("death") rows
  df <- df[df$evtname == "death", ]
  
  idx <- cbind(
    i_sample,
    trt_idx[df$arm],
    df$pat_id
  )
  
  total_costs_ipd[idx]         <- df$total_costs
  total_qalys_ipd[idx]         <- df$total_qalys
}


options(scipen = 999)
total_costs <- apply(total_costs_ipd, c(1, 2), mean)
total_qalys <- apply(total_qalys_ipd, c(1, 2), mean)


#drop natalizumab-biosimilar-SC and cladrebiene
total_costs <- total_costs[,-c(4,5)]
total_qalys <- total_qalys[,-c(4,5)]

results_table <- summarise_ce_results(wtp1 = 25000, wtp2 = 35000,
                                      total_qalys = total_qalys, 
                                      total_costs = total_costs,
                                      reference = "Natalizumab-IV")

knitr::kable(results_table) 
Total costs (95% CrI) Total QALYs (95% CrI) Net benefit at £25000/QALY (95% CrI) Net benefit at £35000/QALY (95% CrI) Incremental costs (95% CrI) Incremental QALYs (95% CrI) INB at £25000/QALY (95% CrI) INB at £35000/QALY (95% CrI) CEAC at £25000/QALY (95% CrI) CEAC at £35000/QALY (95% CrI)
Natalizumab-IV 351,399.68 (306,827.55, 405,862.05) 9.51 (7.80, 11.33) -113,768.00 (-173,670.18, -26,828.18) -18,715.32 (-92,592.52, 85,171.57) 0.00 (0.00, 0.00) 0.00 (0.00, 0.00) 0.00 (0.00, 0.00) 0.00 (0.00, 0.00) 0.2 0.3
Natalizumab-SC 306,412.98 (254,131.81, 348,378.56) 8.77 (6.40, 10.77) -87,261.91 (-129,557.13, -15,975.56) 398.52 (-57,018.60, 88,452.29) -44,986.70 (-118,034.30, 22,809.01) -0.74 (-3.14, 1.56) 26,506.09 (-19,287.27, 64,663.09) 19,113.84 (-49,375.47, 74,064.20) 0.3 0.2
Natalizumab biosimilar-IV 335,011.50 (299,648.30, 365,786.83) 9.35 (5.16, 13.00) -101,173.34 (-203,107.35, -24,389.34) -7,638.07 (-151,479.96, 103,860.79) -16,388.19 (-63,466.11, 29,855.87) -0.15 (-3.37, 3.63) 12,594.66 (-37,638.82, 84,936.77) 11,077.25 (-68,161.84, 121,274.41) 0.2 0.2
Ublituximab 357,782.91 (319,753.92, 381,738.14) 9.50 (6.37, 12.83) -120,319.16 (-199,729.74, -56,992.14) -25,333.66 (-136,015.91, 68,440.99) 6,383.23 (-40,728.60, 56,449.48) -0.0067 (-2.99, 3.24) -6,551.16 (-77,080.69, 94,856.41) -6,618.33 (-104,272.29, 125,113.88) 0.3 0.3
Ofatumumab 375,890.37 (333,598.35, 424,320.89) 8.86 (7.20, 10.26) -154,417.90 (-231,569.09, -81,039.75) -65,828.91 (-156,837.43, 20,539.24) 24,490.68 (-37,477.92, 64,783.41) -0.65 (-1.87, 0.46) -40,649.90 (-87,697.91, 21,753.34) -47,113.59 (-104,598.97, 16,552.28) 0 0
Ocrelizumab 400,430.86 (341,075.02, 443,772.97) 9.42 (6.77, 12.86) -164,968.91 (-219,207.98, -101,810.91) -70,784.13 (-146,874.61, 21,613.23) 49,031.18 (-3,525.41, 109,018.13) -0.087 (-1.78, 3.15) -51,200.91 (-116,307.52, 9,261.65) -52,068.81 (-123,115.35, 39,026.85) 0 0
#write.csv(results_table, paste0(c("results/results warden determenistic", n_samples, "x", n_patients, ".csv"), collapse = " "))

#plot results
v_results_treatment_names<- v_treatment_names[-c(4,5)]

# Create a BCEA object
des_bcea <- bcea(eff = total_qalys,
                 cost = total_costs,
                 ref = 1,
                 interventions = v_results_treatment_names)
ceplane.plot(des_bcea, wtp = 35000,
             graph = "ggplot2")


#plot a CEAC
des_multi_ce <- multi.ce(des_bcea)
ceac.plot(des_multi_ce, graph = "ggplot2",
          line = list(color = c("darkorange", "palegreen3", "blue", "grey",
                                "cyan3", "black"),
                      size=2 ),
          #ylim=c(0, 0.5),
          pos = c(1, 1)
)




#compare key events by treatment groups
modelresults_summarised <- summary_results_sim(results[[1]])
proportion_spms  <- modelresults_summarised["spms_flag",]
average_numberof_relapses <- modelresults_summarised["n_relapse",] 
average_numberof_edssincreases <- modelresults_summarised["n_edssinc_evts",] 
average_numberof_edssdecreases<- modelresults_summarised["n_edssdec_evts",] 
average_numberof_saes<- modelresults_summarised["n_sae_evts",] 
final_edss_value <- modelresults_summarised["edss_value",]
average_numberof_treatmentswitches <- modelresults_summarised["n_switch",] 
average_numberof_yearsontreatment <- modelresults_summarised["years_on_treatment",] 
average_numberof_yearson2ndline<- modelresults_summarised["t_2ndline",] 
average_numberof_yearson3rdline<- modelresults_summarised["t_3rdline",] 
average_numberof_yearson4thline<- modelresults_summarised["t_4thline",]

key_events_trt_grps <- as.data.frame(rbind(
  proportion_spms,   average_numberof_relapses, 
  average_numberof_edssincreases,   average_numberof_edssdecreases, 
  final_edss_value,   average_numberof_saes,
  average_numberof_treatmentswitches,  average_numberof_yearsontreatment,
  average_numberof_yearson2ndline,  average_numberof_yearson3rdline,
  average_numberof_yearson4thline),
  row.names=c("proportion with spms", "average no. of relapses", 
              "average no. of edss increases", "average no. of edss decreases", 
              "final edss value", "average no. of SAEs",
              "average no. of treatment switches", "average no. of years on treatment",
              "average no. of years on 2ndline", "average no. of years on 3rdline",
              "average no. of years on 4thline")
)
knitr::kable(key_events_trt_grps)
Natalizumab-IV Natalizumab-SC Natalizumab biosimilar-IV Natalizumab biosimilar-SC Cladribine Ublituximab Ofatumumab Ocrelizumab
proportion with spms 0.29 (0.1; 0.5) 0.32 (0.1; 0.6) 0.34 (0.1; 0.8) 0.25 (0; 0.6) 0.35 (0.2; 0.7) 0.34 (0.1; 0.5) 0.35 (0.2; 0.5) 0.27 (0; 0.5)
average no. of relapses 2.47 (1; 4.3) 2.11 (1.1; 3.7) 2.49 (0.8; 4.1) 2.22 (0.9; 3.2) 2.5 (1.3; 3.7) 2.23 (0.7; 3.3) 2.5 (1; 4.3) 2.57 (1.3; 5.1)
average no. of edss increases 2.65 (1.5; 4) 2.31 (1; 4.1) 2.25 (1.1; 3.7) 2.56 (1.2; 4.5) 2.99 (1.2; 6.3) 2.71 (1.1; 3.8) 2.37 (0.9; 4.1) 2.36 (1.4; 3.8)
average no. of edss decreases 1.72 (1.4; 2.2) 1.59 (1.2; 2) 1.5 (1; 1.9) 1.65 (1.4; 2) 1.63 (1; 2.8) 1.6 (1.1; 2.2) 1.55 (1; 2.2) 1.65 (1; 2.2)
final edss value 4.66 (3.1; 5.7) 4.61 (3.2; 6.2) 4.68 (3.7; 6.3) 4.68 (2.8; 5.9) 5.17 (4; 6.7) 4.77 (2.9; 5.9) 4.74 (3.9; 5.9) 4.62 (3.1; 6)
average no. of SAEs 4.07 (2.3; 7.1) 3.58 (2.8; 7) 4.62 (2.6; 6.6) 4.07 (3.2; 5.9) 4.08 (2.7; 6.6) 4.01 (2.5; 7.3) 7.41 (3.4; 20.8) 4.42 (2.4; 6.7)
average no. of treatment switches 1.11 (0.4; 1.9) 1.19 (0.6; 1.8) 1.11 (0.6; 1.9) 1.17 (0.6; 1.8) 1.14 (0.6; 1.7) 1.12 (0.4; 1.7) 1.25 (0.5; 2.2) 1.12 (0.6; 1.9)
average no. of years on treatment 20.62 (15; 30.4) 18.23 (8.6; 24) 20.82 (11.9; 35.6) 19.43 (12.3; 31.1) 14.97 (3.3; 23.7) 18.19 (9.9; 24.9) 19.2 (10.2; 23) 18.07 (11.2; 24.6)
average no. of years on 2ndline 19.39 (11.2; 32.3) 16.44 (10; 24.6) 17.63 (6.4; 32.8) 18.75 (13.1; 28.5) 14.55 (7.7; 19.6) 17.3 (7.5; 26.7) 15.56 (10.1; 21.2) 18.04 (9; 28)
average no. of years on 3rdline 6.94 (1.4; 12.2) 5.53 (2.2; 9.9) 5.84 (2; 14.4) 6.25 (0.6; 14.2) 5.35 (1.6; 13.9) 6.48 (2.8; 14.8) 6.14 (2.3; 15.8) 6.7 (2.9; 11.4)
average no. of years on 4thline 4.74 (0.9; 12.1) 5.24 (0; 15.7) 3.97 (0; 9.7) 4.79 (1.8; 8) 3.6 (0.1; 7.4) 4.24 (0; 6.9) 5.18 (0; 12.2) 4.33 (0.2; 7)


#  VOI analysis
#total EVPI

total_evpi <- voi::evpi(outputs = list(c = total_costs,
                                       e = total_qalys,
                                       k = c(0, 25000, 50000, 75000, 100000)))

knitr::kable(total_evpi)
k evpi
0 6555.979
25000 16688.220
50000 74070.547
75000 118468.469
100000 162866.391
plot(x=total_evpi$k, y=total_evpi$evpi, type="l")


# Total EVPPI
# All  parameters excluding hazard ratios that are constant as it causes errors
# df_inputs <- as.data.frame(results[["input_matrix"]][,-c(73:76,81:84,89:92,79:101)])
# parameters <- as.list(colnames(df_inputs))
# 
# total_evppi <- voi::evppi(outputs = list(c = total_costs,
#                                          e = total_qalys,
#                                          k = c(25000, 35000)),
#                           inputs = df_inputs,
#                           pars = parameters,
#                           method = "bart", 
#                           verbose = TRUE)
# 
# knitr::kable(total_evppi)
# 
# #plot in base R split ober A and B panels as there are too many parameters to plot
# total_evppi_25k_a <- total_evppi$evppi[total_evppi$k ==25000 & total_evppi$evppi > mean(total_evppi$evppi)]
# names(total_evppi_25k_a) <- total_evppi$pars[total_evppi$k ==25000 & total_evppi$evppi > mean(total_evppi$evppi)]
# par(las=1, bg="white", mai=c(0.85, 4, 0.5, 0.5))
# barplot(
#   sort(total_evppi_25k_a, decreasing=FALSE), horiz = TRUE, cex.names=0.9, main="EVPPI WTP 25,000/QALY (A)", xlab= "£"
# )
# 
# total_evppi_25k_b <- total_evppi$evppi[total_evppi$k ==25000 & total_evppi$evppi < mean(total_evppi$evppi)]
# names(total_evppi_25k_b) <- total_evppi$pars[total_evppi$k ==25000 & total_evppi$evppi < mean(total_evppi$evppi)]
# barplot(
#   sort(total_evppi_25k_b, decreasing=FALSE), horiz = TRUE, cex.names=0.6, main="EVPPI WTP 25,000/QALY (B)", xlab= "£"
# )
# 
# total_evppi_35k_a <- total_evppi$evppi[total_evppi$k ==35000 & total_evppi$evppi > mean(total_evppi$evppi)]
# names(total_evppi_35k_a) <- total_evppi$pars[total_evppi$k ==35000 & total_evppi$evppi > mean(total_evppi$evppi)]
# par(las=1, bg="white", mai=c(0.85, 4, 1, 0.5))
# barplot(
#   sort(total_evppi_35k_a, decreasing=FALSE), horiz = TRUE, cex.names=0.5, main="EVPPI WTP 35,000/QALY (A)", xlab= "£"
# )
# 
# total_evppi_35k_b <- total_evppi$evppi[total_evppi$k ==35000 & total_evppi$evppi < mean(total_evppi$evppi)]
# names(total_evppi_35k_b) <- total_evppi$pars[total_evppi$k ==35000 & total_evppi$evppi < mean(total_evppi$evppi)]
# par(las=1, bg="white", mai=c(0.85, 4, 1, 0.5))
# barplot(
#   sort(total_evppi_35k_b, decreasing=FALSE), horiz = TRUE, cex.names=0.6, main="EVPPI WTP 35,000/QALY (B)",xlab= "£"
# )