@@ -181,36 +181,48 @@ can <- readRDS(
181181 ) %>%
182182 group_by(version, geo_value) %>%
183183 arrange(time_value) %>%
184- mutate(cr_7dav = RcppRoll::roll_meanr(case_rate, n = 7L))
184+ mutate(cr_7dav = RcppRoll::roll_meanr(case_rate, n = 7L)) #%>%
185+ #filter(geo_value %in% c('Alberta', "BC"))
185186can <- as_epi_archive(can)
187+ can_latest <- epix_as_of(can, max_version = max(can$DT$version))
186188
187- can_k_week_ahead <- function(ahead = 7) {
188- can %>%
189- epix_slide(fc = arx_forecaster(
190- y = cr_7dav, key_vars = geo_value, time_value = time_value,
191- args = arx_args_list(ahead = ahead)),
192- n = 120, ref_time_values = fc_time_values, group_by = geo_value) %>%
193- mutate(target_date = time_value + ahead)
189+ can_k_week_ahead <- function(x, ahead = 7, as_of = TRUE) {
190+ if(as_of){
191+ can %>%
192+ epix_slide(fc = arx_forecaster(
193+ y = cr_7dav, key_vars = geo_value, time_value = time_value,
194+ args = arx_args_list(intercept = FALSE,ahead = ahead)),
195+ n = 120, ref_time_values = fc_time_values) %>%
196+ mutate(target_date = time_value + ahead, geo_value = fc_key_vars, as_of = as_of)
197+ }
198+ else{
199+ can_latest %>%
200+ epi_slide(fc = arx_forecaster(
201+ y = cr_7dav, key_vars = geo_value, time_value = time_value,
202+ args = arx_args_list(intercept = FALSE,ahead = ahead)),
203+ n = 120, ref_time_values = fc_time_values) %>%
204+ mutate(target_date = time_value + ahead, geo_value = fc_key_vars, as_of = as_of)
205+ }
194206}
195207
196- can_fc <- purrr:::map_dfr(c(7,14,21,28), ~ can_k_week_ahead(.x))
208+ can_fc <- bind_rows(purrr:::map_dfr(c(7,14,21,28), ~ can_k_week_ahead(can, ahead = .x, as_of = TRUE)),
209+ purrr:::map_dfr(c(7,14,21,28), ~ can_k_week_ahead(can_latest, ahead = .x, as_of = FALSE)))
197210```
198211
199212The figure below shows the results for all of the provinces. Note that we are showing the 7-day averages rather than the reported case numbers due to highly variable provincial reporting mismatches.
200213
201214``` {r plot-can-fc, message = FALSE, warning = FALSE, fig.width = 9, fig.height = 12}
202- can_latest <- epix_as_of(can, max_version = max(x$DT$version))
203215ggplot(can_fc, aes(x = target_date, group = time_value)) +
204216 coord_cartesian(xlim = lubridate::ymd(c("2020-12-01", NA))) +
205217 geom_line(data = can_latest, aes(x = time_value, y = cr_7dav),
206218 inherit.aes = FALSE, color = "gray50") +
207219 geom_ribbon(aes(ymin = fc_q0.05, ymax = fc_q0.95, fill = geo_value), alpha = 0.4) +
208220 geom_line(aes(y = fc_point)) + geom_point(aes(y = fc_point), size = 0.5) +
209221 geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) +
210- facet_wrap(~geo_value, scales = "free", ncol = 3 ) +
222+ facet_wrap(paste('as_of: ', as_of) ~geo_value,scales = "free",ncol = 4 ) +
211223 scale_x_date(minor_breaks = "month", date_labels = "%b %y") +
212224 labs(x = "Date", y = "Reported COVID-19 case rates") +
213- theme(legend.position = "none")
225+ theme(legend.position = "none")
214226```
215227
216228## Goals for ` epipredict `
0 commit comments