# Clear environment
rm(list=ls())
# Start timer
<- Sys.time()
start.time
# Disable scientific notation
options(scipen=999)
# Get the model and helper functions (but hide loading warnings for each package)
suppressMessages(source("model.R"))
suppressMessages(source("helpers.R"))
# Import other required libraries (if not otherwise import in R scripts below)
library(ggpubr)
library(tidyr, include.only = c("pivot_wider"))
Reproduce supplementary figure
This is run in a separate script from the other figures due to issues with RStudio crashing when all scenarios were run from a single script.
If run
is TRUE, it will run scenarios with double and triple the number of ECR patients.
To create the figure, it will use those files, as well as the baseline file created within reproduction.qmd
.
Run time: 4.975 minutes (will vary between machines)
Set up
# Set the seed and default dimensions for figures
= 200
SEED = 7
DEFAULT_WIDTH = 4
DEFAULT_HEIGHT
# Set file paths to save results
= "../outputs"
folder
<- file.path(folder, "fig2_baseline.csv.gz")
path_baseline_f2 <- file.path(folder, "sup_baseline_double.csv.gz")
path_double_sup <- file.path(folder, "sup_baseline_triple.csv.gz")
path_triple_sup
<- file.path(folder, "supplementary_figure.png") path_supfig
Run models
Set to true or false, depending on whether you want to run everything.
<- FALSE run
Run baseline with double and triple the number of ECR patients, for the supplementary figure.
if (isTRUE(run)) {
<- run_model(seed = SEED, ecr_pt = 58*2)
baseline_sup2 <- run_model(seed = SEED, ecr_pt = 58*3)
baseline_sup3 }
if (isTRUE(run)) {
# Save results
::fwrite(baseline_sup2, path_double_sup)
data.table::fwrite(baseline_sup3, path_triple_sup)
data.table
# Remove the dataframes from environment
rm(baseline_sup2, baseline_sup3)
}
Import results
Import the results, adding a column to each to indicate the scenario.
<- import_results(path_baseline_f2, "Baseline")
base_f2 <- import_results(path_double_sup, "Baseline (double)")
base_sup_double <- import_results(path_triple_sup, "Baseline (triple)") base_sup_triple
Supplementary figure
# Create sub-plots
<- create_plot(base_f2,
p1 group="resource",
title="Baseline",
ylab="Standardised density of patient in queue")
<- create_plot(base_sup_double,
p2 group="resource",
title="Doubling ECR patients",
xlab="Patient wait time (min)",
xlim=c(0, 300),
breaks_width=100)
<- create_plot(base_sup_triple,
p3 group="resource",
title="Tripling ECR patients",
xlim=c(0, 300))
# Arrange in a single figure
ggarrange(p1, p2, p3, nrow=1,
common.legend=TRUE, legend="bottom",
labels=c("A", "B", "C"))
Warning: Removed 1 row containing non-finite outside the scale range (`stat_density()`).
Removed 1 row containing non-finite outside the scale range (`stat_density()`).
Removed 1 row containing non-finite outside the scale range (`stat_density()`).
Removed 1 row containing non-finite outside the scale range (`stat_density()`).
Warning: Removed 4 rows containing non-finite outside the scale range
(`stat_density()`).
Removed 4 rows containing non-finite outside the scale range
(`stat_density()`).
Warning: Removed 3 rows containing non-finite outside the scale range
(`stat_density()`).
Removed 3 rows containing non-finite outside the scale range
(`stat_density()`).
ggsave(path_supfig, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT)
Time elapsed
if (isTRUE(run)) {
<- Sys.time()
end.time <- round((end.time - start.time), 3)
elapsed.time
elapsed.time }