-
Notifications
You must be signed in to change notification settings - Fork 6
/
02_rtestim_infections.R
47 lines (41 loc) · 1.36 KB
/
02_rtestim_infections.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
remotes::install_github("dajmcdon/rtestim")
library(rtestim)
url <- "https://raw.githubusercontent.com/cmilando/RtEval/main/all_data.RDS"
all_data <- readRDS(url(url))
case_choice <- "daily_infections"
#rt estimation
rtestim <- estimate_rt(
observed_counts = all_data$cases$daily_infections,
x = all_data$cases$day,
delay_distn = all_data$serial$Px
)
#approximate confidence bands
rtestim_cb <- confband(rtestim, lambda = rtestim$lambda[37])
#lambda: the selected lambda. May be a scalar value,
# or in the case of cv_poisson_rt objects, "lambda.min" or "lambda.max"
#create dataframe
plot_rtestim <- data.frame(
package = "rtEstim",
date = all_data$cases$day,
Rt_median = rtestim_cb$fit,
Rt_lb = rtestim_cb$`2.5%`,
Rt_ub = rtestim_cb$`97.5%`
)
library(tidyverse)
as_tibble(plot_rtestim) %>%
ggplot() +
geom_hline(yintercept = 1, linetype = "11") +
# *******
# this is the true r(t), back-calculated
geom_line(aes(x = Day, y = Rt_calc), data = all_data$rt) +
# *******
geom_ribbon(aes(x = date, ymin = Rt_lb, ymax = Rt_ub, fill = package), alpha = 0.25) +
geom_line(aes(x = date, y = Rt_median, color = package)) +
coord_cartesian(ylim = c(0, 5)) +
xlab("Days") +
ylab("Rt") +
theme(
axis.text = element_text(size = 10),
axis.title = element_text(size = 14)
)
saveRDS(plot_rtestim, file = 'plot_objects/plot_data_rtestim_infections.RDS')