-
Notifications
You must be signed in to change notification settings - Fork 2
/
EpiNow2.Rmd
126 lines (109 loc) · 2.88 KB
/
EpiNow2.Rmd
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
116
117
118
119
120
121
122
123
124
125
126
## _EpiNow2_
```{r lockfile-rt, include = FALSE, message = FALSE}
renv::use("EpiNow2@1.3.4")
```
```{r rt-load-pkg}
library(EpiNow2)
```
### Explanations
### Results
```{r rt-wrappers-prep}
generation_time <- generation_time_opts(
dist_spec(pmf = density(si, at = si_x))
)
```
#### Global transmissibility
These analyses present results for the global incidence, i.e. without
stratification. Results include:
* a graph of the estimates of $R_t$ of the observed data over time, with
associated 95% credibility intervals
* a table summarising these results for the last `r params$r_estim_window` days
```{r rt-estim-global}
# Warning, this step will take 2 cores of your computer and may be running
# for a long time!
res_epinow2_global <- dat_i_day %>%
regroup() %>%
dplyr::mutate(
confirm = count,
date = as.Date(date_index),
.keep = "unused"
) %>%
epinow(
generation_time = generation_time,
stan = stan_opts(samples = 1e3, chains = 2),
rt = rt_opts(gp_on = "R0"),
horizon = 0,
CrIs = c(0.5, 0.95),
return_output = TRUE,
verbose = FALSE,
logs = NULL
)
```
```{r rt-plot-global}
plot(res_epinow2_global, "R") +
scale_x_date(breaks = scales::pretty_breaks(n = 8), date_label = "%d %b %Y") +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
labs(
x = "",
y = "Instantaneous reproduction number (Rt)",
title = "Estimates of Rt (EpiNow2)"
)
```
```{r rt-table-global}
res_epinow2_global$estimates$summarised %>%
dplyr::filter(variable == "R") %>%
tail(params$r_estim_window) %>%
dplyr::select(date, mean, median, lower_95, upper_95) %>%
mutate(
"mean $R$" = round(mean, 2),
"median $R$" = round(median, 2),
"95% ci" = sprintf(
"[%1.2f ; %1.2f]",
lower_95,
upper_95
),
.keep = "unused"
) %>%
kbl() %>%
kable_paper("striped", font_size = 18, full_width = FALSE)
```
#### Transmissibility by group
```{r rt-estim-group, message = FALSE}
res_epinow2_group <- dat_i_day %>%
dplyr::rename(
confirm = .data[["count"]],
date = date_index,
region = .data[[group_var]]
) %>%
regional_epinow(
generation_time = generation_time_opts(generation_time),
stan = stan_opts(samples = 1e3, chains = 2),
rt = rt_opts(gp_on = "R0"),
horizon = 0,
CrIs = c(0.5, 0.95),
return_output = TRUE,
verbose = FALSE,
logs = NULL
)
```
```{r rt-plot-group}
res_epinow2_group$summary$plots$R
```
```{r rt-plot-estimates-group}
# Missing for now
```
```{r rt-table-group}
res_epinow2_group$summary$summarised_results$data %>%
dplyr::filter(metric == "Effective reproduction no.") %>%
dplyr::select(region, mean, median, lower_95, upper_95) %>%
dplyr::mutate(
"95% ci" = sprintf(
"[%1.2f ; %1.2f]",
lower_95,
upper_95
),
.keep = "unused"
) %>%
kbl() %>%
kable_paper("striped", font_size = 18, full_width = FALSE)
```