@@ -177,36 +177,48 @@ can <- readRDS(
177177 ) %>%
178178 group_by(version, geo_value) %>%
179179 arrange(time_value) %>%
180- mutate(cr_7dav = RcppRoll::roll_meanr(case_rate, n = 7L))
180+ mutate(cr_7dav = RcppRoll::roll_meanr(case_rate, n = 7L)) #%>%
181+ #filter(geo_value %in% c('Alberta', "BC"))
181182can <- as_epi_archive(can)
183+ can_latest <- epix_as_of(can, max_version = max(can$DT$version))
182184
183- can_k_week_ahead <- function(ahead = 7) {
184- can %>%
185- epix_slide(fc = arx_forecaster(
186- y = cr_7dav, key_vars = geo_value, time_value = time_value,
187- args = arx_args_list(ahead = ahead)),
188- n = 120, ref_time_values = fc_time_values, group_by = geo_value) %>%
189- mutate(target_date = time_value + ahead)
185+ can_k_week_ahead <- function(x, ahead = 7, as_of = TRUE) {
186+ if(as_of){
187+ can %>%
188+ epix_slide(fc = arx_forecaster(
189+ y = cr_7dav, key_vars = geo_value, time_value = time_value,
190+ args = arx_args_list(intercept = FALSE,ahead = ahead)),
191+ n = 120, ref_time_values = fc_time_values) %>%
192+ mutate(target_date = time_value + ahead, geo_value = fc_key_vars, as_of = as_of)
193+ }
194+ else{
195+ can_latest %>%
196+ epi_slide(fc = arx_forecaster(
197+ y = cr_7dav, key_vars = geo_value, time_value = time_value,
198+ args = arx_args_list(intercept = FALSE,ahead = ahead)),
199+ n = 120, ref_time_values = fc_time_values) %>%
200+ mutate(target_date = time_value + ahead, geo_value = fc_key_vars, as_of = as_of)
201+ }
190202}
191203
192- can_fc <- purrr:::map_dfr(c(7,14,21,28), ~ can_k_week_ahead(.x))
204+ can_fc <- bind_rows(purrr:::map_dfr(c(7,14,21,28), ~ can_k_week_ahead(can, ahead = .x, as_of = TRUE)),
205+ purrr:::map_dfr(c(7,14,21,28), ~ can_k_week_ahead(can_latest, ahead = .x, as_of = FALSE)))
193206```
194207
195208The 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.
196209
197210``` {r plot-can-fc, message = FALSE, warning = FALSE, fig.width = 9, fig.height = 12}
198- can_latest <- epix_as_of(can, max_version = max(x$DT$version))
199211ggplot(can_fc, aes(x = target_date, group = time_value)) +
200212 coord_cartesian(xlim = lubridate::ymd(c("2020-12-01", NA))) +
201213 geom_line(data = can_latest, aes(x = time_value, y = cr_7dav),
202214 inherit.aes = FALSE, color = "gray50") +
203215 geom_ribbon(aes(ymin = fc_q0.05, ymax = fc_q0.95, fill = geo_value), alpha = 0.4) +
204216 geom_line(aes(y = fc_point)) + geom_point(aes(y = fc_point), size = 0.5) +
205217 geom_vline(aes(xintercept = time_value), linetype = 2, alpha = 0.5) +
206- facet_wrap(~geo_value, scales = "free", ncol = 3 ) +
218+ facet_wrap(paste('as_of: ', as_of) ~geo_value,scales = "free",ncol = 4 ) +
207219 scale_x_date(minor_breaks = "month", date_labels = "%b %y") +
208220 labs(x = "Date", y = "Reported COVID-19 case rates") +
209- theme(legend.position = "none")
221+ theme(legend.position = "none")
210222```
211223
212224## Goals for ` epipredict `
0 commit comments