Skip to content

Commit 1cb5157

Browse files
committed
Update STM_03.R
Minor update on comments of code
1 parent 366e0dd commit 1cb5157

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

analysis/STM_03.R

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ m_M_tunnels_sum_trt2 <- cbind(H = m_M_tunnels_trt2[, "H"],
235235
D = m_M_tunnels_trt2[, "D"])
236236

237237
## Store the cohort traces in a list
238-
l_m_M <- list(m_M_tunnels_sum,
239-
m_M_tunnels_sum,
240-
m_M_tunnels_sum_trt2,
241-
m_M_tunnels_sum_trt2)
238+
l_m_M <- list(m_M_tunnels_sum, # Cohort trace for Usual Care
239+
m_M_tunnels_sum, # Cohort trace for New Treatment 1, same as Usual Care
240+
m_M_tunnels_sum_trt2, # Cohort trace for New Treatment 2
241+
m_M_tunnels_sum_trt2) # Cohort trace for New Treatment 1 & 2, same as New Treatment 1
242242
names(l_m_M) <- v_names_str
243243

244244
#### Plot Outputs ####
@@ -399,6 +399,8 @@ plot(df_cea, label = "all") +
399399
expand_limits(x = max(table_cea$QALYs) + 0.5)
400400

401401
###################### Probabalistic Sensitivty Analysis #####################
402+
# Source functions that contain the model and CEA output
403+
source('R/Functions STM_03a.R')
402404

403405
# Function to generate PSA input dataset
404406
generate_psa_params <- function(n_sim = 1000, seed = 071818){
@@ -435,7 +437,7 @@ generate_psa_params <- function(n_sim = 1000, seed = 071818){
435437
return(df_psa)
436438
}
437439

438-
# Number of simulations
440+
# Number of PSA samples
439441
n_sim <- 1000
440442

441443
# Generate PSA input dataset
@@ -444,7 +446,8 @@ df_psa_input <- generate_psa_params(n_sim = n_sim)
444446
head(df_psa_input)
445447

446448
# Histogram of parameters
447-
ggplot(melt(df_psa_input, variable.name = "Parameter"), aes(x = value)) +
449+
ggplot(melt(df_psa_input, variable.name = "Parameter"),
450+
aes(x = value)) +
448451
facet_wrap(~Parameter, scales = "free") +
449452
geom_histogram(aes(y = ..density..)) +
450453
theme_bw(base_size = 16)
@@ -462,16 +465,13 @@ df_e <- as.data.frame(matrix(0,
462465
colnames(df_e) <- v_names_str
463466

464467
## Conduct probabilistic sensitivity analysis
465-
# Source functions that contain the model and CEA output
466-
source('functions/Functions STM_03a.R')
467-
468468
# Run Markov model on each parameter set of PSA input dataset
469469
for(i in 1:n_sim){
470470
l_out_temp <- calculate_ce_out(df_psa_input[i, ])
471471
df_c[i, ] <- l_out_temp$Cost # HUGE PROBLEM HERE
472472
df_e[i, ] <- l_out_temp$Effect
473473
# Display simulation progress
474-
if(i/(n_sim/10) == round(i/(n_sim/10),0)) { # display progress every 10%
474+
if(i/(n_sim/100) == round(i/(n_sim/100), 0)) { # display progress every 5%
475475
cat('\r', paste(i/n_sim * 100, "% done", sep = " "))
476476
}
477477
}
@@ -481,6 +481,9 @@ l_psa <- make_psa_obj(cost = df_c,
481481
effectiveness = df_e,
482482
parameters = df_psa_input,
483483
strategies = v_names_str)
484+
l_psa$strategies <- v_names_str
485+
colnames(l_psa$effectiveness)<- v_names_str
486+
colnames(l_psa$cost)<- v_names_str
484487

485488
# Vector with willingness-to-pay (WTP) thresholds.
486489
v_wtp <- seq(0, 200000, by = 10000)
@@ -506,14 +509,19 @@ plot(df_cea_psa, label = "all") +
506509
ceac_obj <- ceac(wtp = v_wtp, psa = l_psa)
507510
# Regions of highest probability of cost-effectiveness for each strategy
508511
summary(ceac_obj)
512+
# ceac_obj$Strategy <- ordered(ceac_obj$Strategy, levels = v_names_str)
513+
509514
# CEAC & CEAF plot
510-
plot(ceac_obj)
515+
plot(ceac_obj, txtsize = 16, xlim = c(0, NA)) +
516+
theme(legend.position = "bottom")
511517

512518
## Expected Loss Curves (ELCs)
513519
elc_obj <- calc_exp_loss(wtp = v_wtp, psa = l_psa)
514520
elc_obj
521+
515522
# ELC plot
516-
plot(elc_obj, log_y = FALSE)
523+
plot(elc_obj, log_y = FALSE, txtsize = 16, xlim = c(0, NA)) +
524+
theme(legend.position = "bottom")
517525

518526
## Expected value of perfect information (EVPI)
519527
evpi <- calc_evpi(wtp = v_wtp, psa = l_psa)

0 commit comments

Comments
 (0)