Follow these steps to run the simulation of the Sick-Sicker Model in continuous time and/or reproduce the CEA results and generate the exhibits from the tutorial paper.
- Clone the repository
- Verify R version 3.5.0 or newer is installed in your machine
Run DES simulation, compute epidemiological and economic outcomes of the example of the tutorial.
- Verify that
dplyranddata.tableare installed. - Run either of the two sim_modules:
Lite_modules/DES_Sick_Sicker_progressive.R: runs the simulation following the progressive version fo the Sick Sicker modelLite_modules/DES_Sick_Sicker_recurrence.R: runs the simulation following the version fo the Sick Sicker model that includes recurrence to the Healthy state
- Compute the Epidemiological and/or Economic Outcomes based on the DES of the Sick Sicker model with recurrence to Healthy.
Lite_modules/Module_A_CEA.R: computes a cost-effectiveness analysis comparing the strategies described in the coded example of the tutorialLite_modules/Module_B_Epi_Outcomes.R: computes key epidemiological outcomes comparing the strategies described in the coded example of the tutorial
We strongly suggest to use parallel engines to compute the probabilistic analysis and to do the analysis of the appropriate simulation sample size.
- To run distributed runs of the DES you need to have installed the standard packages for parallelization:
doParalleldoMCparallelabindforeach
and a specialized package to sample from the multivariate log-normal distribution:
MethylCapSig
- Run distributed probabilistic analysis
Parallelized_Modules/Module_C_Probabilistic_Analysis.R: computes a probabilistic analysis including
- Incremental cost-effectiveness ratios (ICERs) with probabilistic output,
- Cost-effectiveness acceptability curves (CEACs) and frontier (CEAF),
- Expected Loss Curves (ELCs), and
- Expected value of perfect information (EVPI).
- Run analysis of the appropriate simulation sample size
Parallelized_Modules/Aux_Module_Convergence.R: computes bootstrap distribution of prevalence estimates at each state for varying simulation samples sizes and a fixed number of replications.
- If you are interested in reproducing the plots presented in the tutorial verify that you have installed additional packages:
ggplot2ggrepelviridispatchworkellipse
- To generate the plots shown in the Tutorial paper use the following scripts:
Plotting_Modules/Module_CEA_wPlots.RPlotting_Modules/Module_Epi_Outcomes_wPlots.RPlotting_Modules/Aux_Module_Cont_Time_Trace_wPlots.RPlotting_Modules/Module_Probabilistic_Analysis_wPlots.RPlotting_Modules/Aux_Module_Convergence_wPlots.R
DES_Tutorial_beta/
├── DES_Tutorial.Rproj
├── install_deps.R
├── renv/ (ignore)
├── renv.lock
├── .Rhistory
├── .Rprofile
├── README.R
├── Inputs/
└── all_cause_mortality.rda
└── LifeTable_USA_Mx_2015.csv
├── Lite_Modules/
└── DES_Sick_Sicker_progressive.R
└── DES_Sick_Sicker_recurrence.R
└── Module_A_CEA.R
└── Module_B_Epi_Outcomes.R
└── Aux_Module_Cont_Time_Trace.R
├── Parallelized_Modules/
└── Module_C_Probabilistic_Analysis.R
└── Aux_Module_Convergence.R
├── Plotting_Modules/
└── Module_CEA_wPlots.R
└── Module_Epi_Outcomes_wPlots.R
└── Module_Probabilistic_Analysis_wPlots.R
└── Aux_Module_Cont_Time_Trace_wPlots.R
└── Aux_Module_Convergence_wPlots.R
├── Manuscript/
└── manuscript.qmd (.docx; .pdf)
└── appendix.qmd (.docx; .pdf)
└── bibliography.bib
└── apa-single-spaced.csl
└── figures/
└── R/
└── DES_functions.R
└── Functions.R
If you wish to contribute to this repository please follow these instructions to guarantee that you are using the same version of packages used by the developer.
- Run in RStudio Terminal:
Rscript install_deps.R
This script will install the package renv, which restores the 'locked' versions of all dependencies used by the developer. To do so, renv will install any missing packages and re-install versions of packages to match the version used by the developer. The script returns a list of packages that were not successfully installed and will require individual troubleshooting.
If all goes well, your environment should now match exactly the environment of the developer.
If you run into incompatibilities or mysterious errors running install.deps.R, verify that R version 3.5.0 or newer is installed.
You can try to install required packages manually, run the below code on a script or from the R console:
# Install `renv`
if (!requireNamespace("renv", quietly = TRUE)) {
install.packages("renv")
}
# Required packages
required_pkgs <- c(
"data.table" , # to manipulate data
"dplyr" , # to manipulate data
"ggplot2" , # to visualize data
"ggrepel" , # to visualize data
"ellipse" , # to visualize data
"viridis" , # color-blind friendly pallettes
"patchwork" , # for combining ggplot2 figures
"doParallel" , # parallel processing
"doMC" , # parallel processing
"parallel" , # parallel processing
"foreach" , # parallel processing
"abind" , # manipulate multidimensional arrays
"MethylCapSig", # multivariate lognormal random variate generator
"matrixStats" # optimized functions operating on rows and columns of matrices (optional, but strongly encouraged for non-parametric sampling, see /DES_Functions.R)
)
installed_pkgs <- rownames(installed.packages())
to_install_pkgs <- setdiff(required_pkgs, installed_pkgs)
# Install missing packages
if (length(to_install_pkgs)) {
message("Installing extra packages: ", paste(to_install, collapse = ", "))
failed_pkgs <- character()
for (pkg in to_install_pkgs) {
message("→ Installing ", pkg, " …")
tryCatch(
install.packages(pkg, dependencies = TRUE),
error = function(e) {
warning(sprintf(" ✗ Failed to install '%s': %s", pkg, e$message))
failed_pkgs <<- c(failed_pkgs, pkg)
}
)
}
if (length(failed_pkgs)) {
warning(
"The following packages could not be installed:\n",
paste0(" - ", failed_pkgs, collapse = "\n")
)
}
}
# Restore the project library from renv.lock
message("Restoring project library via renv...")
renv::restore(prompt = T)
mlopezme@stanford.edu{.email} and mlopezme@gmail.com{.email}
