attr_names <- EpiModelWHAMPDX::attr_names
suppressPackageStartupMessages(library(tidyverse))
suppressPackageStartupMessages(library(magrittr))
suppressPackageStartupMessages(library(cowplot))
suppressPackageStartupMessages(library(ggrepel))
library(EpiModelWHAMPDX)
sim_dat <- readRDS("../../EpiModel/AE/sim_epimodel3/sim_on_2021-03-23_at_2033.rds")
options(dplyr.summarise.inform = FALSE)
knitr::opts_chunk$set(echo = TRUE, message = FALSE,
warning = FALSE, fig.width = 8)
print_many_plots <- function(testing_plots, num_hash = 3,
targ_df = EpiModelWHAMPDX::WHAMP.targs){
big_temp <- paste0(c(rep("#", num_hash),
" %s {.tabset .tabset-fade .tabset-pills} ", "
", "
"), collapse = "")
sml_temp <- paste0(c("\n\n", rep("#", num_hash + 1), " %s ", "
", "
"), collapse = "")
for (ms_idx in 1:length(testing_plots)) {
sub_plot_info <- testing_plots[[ms_idx]]
if (is.null(sub_plot_info$plt_type)) {
plt_type <- "line"
}else{plt_type <- sub_plot_info$plt_type}
meas_data <- make_epi_plot_data(sim_dat, sub_plot_info)
if (!is.null(sub_plot_info$sec_title)) {
this_meas_name <- sub_plot_info$sec_title
}else{
this_meas_name <- sub_plot_info$plot_name
}
cat(sprintf(big_temp, this_meas_name))
this_targ <- targ_df %>%
filter(sub_plot_info$name == measure)
for (ct_idx in seq(attr_names)) {
this_cat <- names(attr_names)[ct_idx]
cat(sprintf(sml_temp, this_cat))
print(EpiModelWHAMPDX::plot_epi(
meas_data, this_cat, this_targ,
plot_type = plt_type, year_range = c(1980, 2030)))
cat("\n\n")
}
}
}
cur_targs <- readRDS("../../Data/EpiModelSims/WHAMP.dx.targs.rds")
prep_awareness <- list(
prep.aware = list(name = "prep.aware",
sec_title = "Proportion that are PrEP aware",
plot_name = "Proportion PrEP aware",
plot_cap = "Among all undiagnosed individuals",
plot_ylab = "Proportion",
plt_type = "line",
vars = c("num.prep.aware.", "num.", "diag.i.num."),
sum_fun = function(x, y, z) { x / (y - z) }
)
)
print_many_plots(prep_awareness, targ_df = cur_targs)
rolling_year_sum <- function(x, years = 1, avg = FALSE){
val <- data.table::frollsum(fill(data.frame(x), "x")$x, years * 52)
if (avg) {val <- val / (years * 52)}
return(val)
}
prep_init <- list(
prep.init = list(name = "prep.initialize",
sec_title = "Rate of PrEP Initiation (per Person Year)",
plot_name = "PrEP Init Rate",
plot_cap = "Among all PrEP aware individuals who have never use PrEP",
plot_ylab = "Rate",
plt_type = "line",
vars = c("just.first.init.", "first.init.elig."),
sum_fun = function(x, y) {
rolling_year_sum(x) / rolling_year_sum(y, avg = TRUE)
}
)
)
print_many_plots(prep_init, targ_df = cur_targs)
prep_intr <- list(
prep.intr = list(name = "prep.intruption",
sec_title = "Rate of PrEP discontiuation",
plot_name = "PrEP Discontiuation Rate",
plot_cap = "Among all PrEP users",
plot_ylab = "Rate",
plt_type = "line",
vars = c("num.jst.stop.prep.", "num.prep.current."),
sum_fun = function(x, y) {
rolling_year_sum(x) / rolling_year_sum(y, avg = TRUE)
}
)
)
print_many_plots(prep_intr, targ_df = cur_targs)
prep_ever <- list(
prep.aware = list(name = "prep.ever",
sec_title = "Proportion that ever used PrEP",
plot_name = "Proportion ever PrEP",
plot_cap = "Among all undiagnosed individuals",
plot_ylab = "Proportion",
plt_type = "line",
vars = c("num.prep.ever.", "diag.i.num.", "num."),
sum_fun = function(x, y, z) { x / (z - y) }
)
)
print_many_plots(prep_ever, targ_df = cur_targs)
prep_cur <- list(
prep.aware = list(name = "prep.current",
sec_title = "Proportion that currently use PrEP",
plot_name = "Proportion currently on PrEP",
plot_cap = "Among all undiagnosed individuals",
plot_ylab = "Proportion",
plt_type = "line",
vars = c("num.prep.current.", "diag.i.num.", "num."),
sum_fun = function(x, y, z) { x / (z - y) }
)
)
print_many_plots(prep_cur, targ_df = cur_targs)
prep_time_tot <- list(
prep.reinit.time = list(name = "prep.fstart.mos",
sec_title = "Time from starting PrEP",
plot_name = "Months from PrEP start",
plot_cap = "Among individuals who have started PrEP",
plot_ylab = "Months",
plt_type = "line",
vars = c("mean.ts.first.prep."),
sum_fun = function(x) {x / 4}
)
)
print_many_plots(prep_time_tot, targ_df = cur_targs)
prep_discont <- list(
prep.aware = list(name = "prep.discont",
sec_title = "Proportion that have ever discontinued PrEP",
plot_name = "Proportion ever discontinued PrEP",
plot_cap = "Among individuals who have ever used prep",
plot_ylab = "Proportion",
plt_type = "line",
vars = c("num.prep.ever.discont.", "num.prep.ever."),
sum_fun = function(x, y) { x / y }
)
)
print_many_plots(prep_discont, targ_df = cur_targs)
prep_reint_time <- list(
prep.reinit.time = list(name = "prep.int.mos",
sec_title = "Time from disconinuation to reinitiation",
plot_name = "Time to Reinitiate",
plot_cap = "Among individuals who have discontinued and reinitiated PrEP",
plot_ylab = "Months",
plt_type = "line",
vars = c("mean.last.int.time."),
sum_fun = function(x) {x / 4}
)
)
print_many_plots(prep_reint_time, targ_df = cur_targs)
prep_stopped <- list(
prep.aware = list(name = "prep.stop",
sec_title = "Proportion who currently stopped PrEP",
plot_name = "Proportion stopped PrEP",
plot_cap = "Among individuals who have ever used prep",
plot_ylab = "Proportion",
plt_type = "line",
vars = c("num.prep.stopped.", "num.prep.ever."),
sum_fun = function(x, y) { x / y }
)
)
print_many_plots(prep_stopped, targ_df = cur_targs)
prep_reint <- list(
prep.reint = list(name = "prep.reint",
sec_title = "Proportion reinitiated after discontinuation",
plot_name = "Proportion einitiated PrEP",
plot_cap = "Among individuals who have ever discontinued PrEP",
plot_ylab = "Proportion",
plt_type = "line",
vars = c("num.reinit.", "num.prep.ever.discont."),
sum_fun = function(x, y) { x / y }
)
)
print_many_plots(prep_reint, targ_df = cur_targs)
Open the first code chunk below to see the construction rule (this should match the second code chunk).
# prop.of.neg.on.prep <- neg.prep.num / (num - i.num)
# (prepStats == 1 & status = 0) / (status == 0) =
prop.prep <- list(
"prop.pre" = list(name = "prop.prep",
plot_name = "Proportion of HIV- on PrEP",
plt_type = "line",
vars = c("neg.prep.num.", "num.", "i.num."),
sum_fun = function(x, y, z) x / (y - z)
)
)
print_many_plots(prop.prep, num_hash = 2)
Open the first code chunk below to see the construction rule (this should match the second code chunk).
# prop.of.hiv.supr <- any.prep.ind / (num - i.num) =
# (prepIndic == 1 & status == 0) / (status == 0)
prop.hivn.ind <- list(
list(name = "prop.hivn.ind",
plot_name = "Proportion of HIV- who are PrEP indicated",
plt_type = "line",
vars = c("any.prep.ind.", "num.", "i.num."),
sum_fun = function(x, y, z) x/(y - z))
)
print_many_plots(prop.hivn.ind)
Open the first code chunk below to see the construction rule (this should match the second code chunk).
# prop.of.ind.on.prep <- on.prep.and.ind / any.prep.ind =
# (prepIndic == 1 & status == 0 & prepStat == 1) / (prepIndic == 1 & status == 0)
prop.ind.on.prep <- list(
list(name = "prop.ind.on.prep",
plot_name = "Proportion of PrEP indicated on PrEP",
vars = c("on.prep.and.ind.", "any.prep.ind."),
sum_fun = function(x, y) x / y,
plt_type = "line")
)
print_many_plots(prop.ind.on.prep)