@@ -30,7 +30,7 @@ very_latent_locations <- list(list(
3030))
3131
3232forecaster_fns <- list2(
33- linear = function (epi_data , ahead , ... ) {
33+ linear = function (epi_data , ahead , extra_data , ... ) {
3434 epi_data %> %
3535 filter(source == " nhsn" ) %> %
3636 forecaster_baseline_linear(
@@ -43,27 +43,49 @@ forecaster_fns <- list2(
4343 # linearlog = function(...) {
4444 # forecaster_baseline_linear(..., log = TRUE)
4545 # },
46- climate_base = function (epi_data , ahead , ... ) {
46+ climate_base = function (epi_data , ahead , extra_data , ... ) {
4747 epi_data %> %
4848 filter(source == " nhsn" ) %> %
4949 climatological_model(ahead , ... )
5050 },
51- climate_geo_agged = function (epi_data , ahead , ... ) {
51+ climate_geo_agged = function (epi_data , ahead , extra_data , ... ) {
5252 epi_data %> %
5353 filter(source == " nhsn" ) %> %
5454 climatological_model(ahead , ... , geo_agg = TRUE )
5555 },
56- windowed_seasonal = function (epi_data , ahead , ... ) {
56+ windowed_seasonal = function (epi_data , ahead , extra_data , ... ) {
5757 scaled_pop_seasonal(
5858 epi_data ,
59- outcome = " value" , ahead = ahead * 7 , ... ,
59+ outcome = " value" ,
60+ ahead = ahead * 7 ,
61+ ... ,
62+ trainer = epipredict :: quantile_reg(),
6063 seasonal_method = " window" ,
6164 pop_scaling = FALSE ,
6265 lags = c(0 , 7 ),
6366 keys_to_ignore = very_latent_locations
6467 ) %> %
6568 mutate(target_end_date = target_end_date + 3 )
6669 },
70+ windowed_seasonal_extra_sources = function (epi_data , ahead , extra_data , ... ) {
71+ fcst <-
72+ epi_data %> %
73+ left_join(extra_data , by = join_by(geo_value , time_value )) %> %
74+ scaled_pop_seasonal(
75+ outcome = " value" ,
76+ ahead = ahead * 7 ,
77+ extra_sources = " nssp" ,
78+ ... ,
79+ seasonal_method = " window" ,
80+ trainer = epipredict :: quantile_reg(),
81+ drop_non_seasons = TRUE ,
82+ pop_scaling = FALSE ,
83+ lags = list (c(0 , 7 ), c(0 , 7 )),
84+ keys_to_ignore = very_latent_locations
85+ ) %> %
86+ mutate(target_end_date = target_end_date + 3 )
87+ fcst
88+ }
6789)
6890
6991# This is needed to build the data archive
@@ -81,6 +103,12 @@ rlang::list2(
81103 tar_target(name = ref_time_values , command = ref_time_values_ ),
82104 ),
83105 make_historical_flu_data_targets(),
106+ tar_target(
107+ current_nssp_archive ,
108+ command = {
109+ up_to_date_nssp_state_archive()
110+ }
111+ ),
84112 tar_target(
85113 joined_latest_extra_data ,
86114 command = {
@@ -161,6 +189,7 @@ rlang::list2(
161189 } else {
162190 train_data <- nhsn_latest_data
163191 }
192+ nssp <- current_nssp_archive %> % epix_as_of(min(forecast_date , current_nssp_archive $ versions_end ))
164193 full_data <- train_data %> %
165194 bind_rows(joined_latest_extra_data )
166195 attributes(full_data )$ metadata $ other_keys <- " source"
@@ -172,7 +201,7 @@ rlang::list2(
172201 forecast_res ,
173202 command = {
174203 full_data %> %
175- forecaster_fns [[forecasters ]](ahead = aheads ) %> %
204+ forecaster_fns [[forecasters ]](ahead = aheads , extra_data = nssp ) %> %
176205 mutate(
177206 forecaster = names(forecaster_fns [forecasters ]),
178207 geo_value = as.factor(geo_value )
@@ -236,7 +265,7 @@ rlang::list2(
236265 filter(geo_value %nin % geo_exclusions ) %> %
237266 ungroup() %> %
238267 # Ensemble with windowed_seasonal
239- bind_rows(forecast_res %> % filter(forecaster == " windowed_seasonal" )) %> %
268+ bind_rows(forecast_res %> % filter(forecaster == " windowed_seasonal" , forecaster == " windowed_seasonal_extra_sources " )) %> %
240269 group_by(geo_value , forecast_date , target_end_date , quantile ) %> %
241270 summarize(value = mean(value , na.rm = TRUE ), .groups = " drop" ) %> %
242271 sort_by_quantile()
0 commit comments