-
Notifications
You must be signed in to change notification settings - Fork 1
/
fig_epi_assessment.R
115 lines (104 loc) · 3.63 KB
/
fig_epi_assessment.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
suppressPackageStartupMessages({
require(data.table)
require(RSQLite)
require(ggplot2)
require(ggh4x)
})
.debug <- "~/Dropbox/Covid-WHO-vax/outputs"
.args <- if (interactive()) sprintf(c(
"%s/epi_quantile_ext.rds",
"%s/config_ext.sqlite",
"%s/test.png"
), .debug) else commandArgs(trailingOnly = TRUE)
epi.dt <- readRDS(.args[1])
setkeyv(epi.dt,c("id","age","qtile","anni_year"))
agg.dt <- epi.dt[, .(
age="all", cases = sum(cases), deaths = sum(death_o),
del.cases = sum(cases.del), del.deaths = sum(death_o.del)
), by=setdiff(key(epi.dt),"age")]
readDBtable <- function(
fl, tbl = "scenario",
drv = RSQLite::SQLite(), flags = SQLITE_RO
) {
conn <- dbConnect(drv, fl, flags = flags)
res <- data.table(dbReadTable(conn, tbl))
dbDisconnect(conn)
res
}
scn <- readDBtable(.args[2])[, .(
id, strategy, vax_eff, nat_imm_dur_days, vax_imm_dur_days,
start_timing, vax_delay, doses_per_day, strategy_str, from_age
)]
full.dt <- agg.dt[scn, on=.(id)]
base.scn <- scn.focus[nat_imm_dur_days == 365 & doses_per_day == 4000]
base.pl <- agg.dt[base.scn, on=.(id)][!is.na(nat_imm_dur_days)]
scale_x_anni_year <- function(
name = "Years Since Initial Vaccination",
breaks = 1:10,
...
) scale_x_continuous(name, breaks, ...)
p <- ggplot(
base.pl[qtile == "md"][strategy != "none" & (strategy_str == 365 & doses_per_day == 8000)]) +
aes(
anni_year, del.deaths,
color = vax_eff, linetype = factor(from_age), group = interaction(vax_eff, from_age)
) +
facet_nested(
start_timing + vax_imm_dur_days ~ doses_per_day,
labeller = labeller(
doses_per_day = function(dpd) sprintf(
c("Initial Doses Per Day\n= %s", rep("\n%s", length(dpd)-1)),
dpd
),
vax_imm_dur_days = function(dur) sprintf(c(
"Vaccine Immunity\nDuration =%s",
rep("\n%s", length(dur)-1)
), round(as.numeric(dur)/365, digits = 1)),
start_timing = function(st) as.Date(as.integer(st), origin = "1970-01-01")
)
) +
geom_line() +
# geom_line(
# aes(color = "no vaccine", linetype = "no vaccine"),
# data = base.pl[
# qtile == "md" & strategy == "none", .(
# deaths, anni_year, start_timing,
# vax_imm_dur_days = Inf, doses_per_day = 8000
# )
# ]
# ) +
# geom_line(
# aes(color = "no vaccine", linetype = "no vaccine"),
# data = base.pl[
# qtile == "md" & strategy == "none", .(
# deaths, anni_year, start_timing,
# vax_imm_dur_days = 365, doses_per_day = 8000
# )
# ]
# ) +
# geom_line(
# aes(color = "no vaccine", linetype = "no vaccine"),
# data = base.pl[
# qtile == "md" & strategy == "none", .(
# deaths, anni_year, start_timing,
# vax_imm_dur_days = 912, doses_per_day = 8000
# )
# ]
# ) +
# geom_line(
# aes(color = "no vaccine", linetype = "no vaccine"),
# data = base.pl[
# qtile == "md" & strategy == "none", .(
# deaths, anni_year, start_timing,
# vax_imm_dur_days = 1825, doses_per_day = 8000
# )
# ]
# ) +
scale_x_anni_year() +
scale_y_continuous(labels = scales::label_number_si()) +
scale_color_continuous(guide = "legend", breaks = base.pl[qtile == "md"][strategy != "none", sort(unique(vax_eff))]) +
coord_cartesian(expand = FALSE) +
theme_minimal() +
theme(
legend.position = "bottom"
)