Skip to content

Commit 9afe855

Browse files
authored
Predict without geo-pooling
Added slide with function to perform ARX without geo-pooling
1 parent d428894 commit 9afe855

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

slides/day2-afternoon.qmd

+32-32
Original file line numberDiff line numberDiff line change
@@ -997,34 +997,6 @@ pred_arx_geo_pool <- usa_archive_dv |> epix_slide(
997997
)
998998
```
999999

1000-
```{r arx-no-geo-pooling}
1001-
ma_archive_dv <- usa_archive_dv$DT |> filter(geo_value == "ma") |> as_epi_archive()
1002-
ny_archive_dv <- usa_archive_dv$DT |> filter(geo_value == "ny") |> as_epi_archive()
1003-
tx_archive_dv <- usa_archive_dv$DT |> filter(geo_value == "tx") |> as_epi_archive()
1004-
1005-
pred_arx_no_geo_pool <- function(archive, ahead = 28, lags = 0){
1006-
archive |>
1007-
epix_slide(
1008-
~ arx_forecaster(epi_data = .x,
1009-
outcome = "deaths",
1010-
predictors = c("deaths", "doctor_visits"),
1011-
trainer = linear_reg() |> set_engine("lm"),
1012-
args_list = arx_args_list(
1013-
lags = lags,
1014-
ahead = ahead,
1015-
quantile_levels = c(0.1, 0.9))
1016-
)$predictions |>
1017-
pivot_quantiles_wider(.pred_distn),
1018-
.before = w,
1019-
.versions = fc_time_values
1020-
)}
1021-
1022-
pred_no_geo_pool_28 <- rbind(pred_arx_no_geo_pool(ca_archive_dv),
1023-
pred_arx_no_geo_pool(ma_archive_dv),
1024-
pred_arx_no_geo_pool(ny_archive_dv),
1025-
pred_arx_no_geo_pool(tx_archive_dv))
1026-
```
1027-
10281000

10291001
```{r arx-geo-pooling-plot-ca, eval=FALSE}
10301002
## Predictions (geo-pooling): California
@@ -1097,6 +1069,35 @@ rbind(getAccuracy(ca,
10971069
"TX"))
10981070
```
10991071

1072+
## Predict without geo-pooling
1073+
1074+
```{r arx-no-geo-pooling}
1075+
#| echo: true
1076+
pred_arx_no_geo_pool <- function(archive, ahead = 28, lags = 0){
1077+
archive |>
1078+
epix_slide(
1079+
~ group_by(.x, geo_value) |>
1080+
group_map(.keep = TRUE, function(group_data, group_key) {
1081+
arx_forecaster(epi_data = group_data,
1082+
outcome = "deaths",
1083+
predictors = c("deaths", "doctor_visits"),
1084+
trainer = linear_reg() |> set_engine("lm"),
1085+
args_list = arx_args_list(
1086+
lags = lags,
1087+
ahead = ahead,
1088+
quantile_levels = c(0.1, 0.9))
1089+
)$predictions |>
1090+
pivot_quantiles_wider(.pred_distn)
1091+
}) |>
1092+
list_rbind(),
1093+
.before = w,
1094+
.versions = fc_time_values
1095+
)}
1096+
1097+
pred_no_geo_pool_28 <- pred_arx_no_geo_pool(usa_archive_dv$DT |>
1098+
filter(geo_value %in% c("ca", "ma", "ny", "tx")) |>
1099+
as_epi_archive())
1100+
```
11001101

11011102
## Predictions (without geo-pooling, $h=28$)
11021103

@@ -1166,10 +1167,9 @@ pred_arx_geo_pool_7 <- usa_archive_dv |>
11661167
.versions = fc_time_values
11671168
)
11681169
1169-
pred_no_geo_pool_7 <- rbind(pred_arx_no_geo_pool(ca_archive_dv, ahead = 7),
1170-
pred_arx_no_geo_pool(ma_archive_dv, ahead = 7),
1171-
pred_arx_no_geo_pool(ny_archive_dv, ahead = 7),
1172-
pred_arx_no_geo_pool(tx_archive_dv, ahead = 7))
1170+
pred_no_geo_pool_7 <- pred_arx_no_geo_pool(usa_archive_dv$DT |>
1171+
filter(geo_value %in% c("ca", "ma", "ny", "tx")) |>
1172+
as_epi_archive(), ahead = 7)
11731173
```
11741174

11751175

0 commit comments

Comments
 (0)