Skip to content

Commit c97c8eb

Browse files
committed
flu forecast, reweighing
1 parent c6e63eb commit c97c8eb

File tree

6 files changed

+101
-30
lines changed

6 files changed

+101
-30
lines changed

R/forecasters/ensemble_linear_climate.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ ensemble_climate_linear <- function(
2121
max_climate_ahead_weight = 0.90,
2222
min_climate_quantile_weight = 0.1,
2323
max_climate_quantile_weight = 1) {
24-
browser()
2524
last_data <- min(forecasts$target_end_date)
2625
forecast_date <- min(forecasts$forecast_date)
27-
latency <- as.integer(forecast_date - last_data) / 7
28-
aheads <- aheads + latency
26+
latency <- ceiling(as.integer(forecast_date - last_data) / 7)
27+
aheads <- seq(min(aheads), max(aheads) + latency)
2928
forecasts %<>% filter(grepl("climate|linear", forecaster)) %>% mutate(forecast_date = last_data)
3029
weights <-
3130
make_ahead_weights(aheads, min_climate_ahead_weight, max_climate_ahead_weight) %>%

scripts/covid_geo_exclusions.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ forecast_date,forecaster,geo_value,weight
1313
2024-10-01, climate_quantile_extrapolated, all, 0
1414
2024-10-01, climate_linear, hi, 0.0001
1515
##################
16+
# Oct 15: no data, default to climate linear
17+
##################
18+
2025-10-15, all, mp, 0
19+
2025-10-15, windowed_seasonal, all, 0.001
20+
2025-10-15, windowed_seasonal_extra_sources, all, 0.1
21+
2025-10-15, climate_linear, all, 2
22+
2025-10-15, linear, all, 3
23+
2025-10-15, linearlog, all, 0
24+
2025-10-15, climate_base, all, 3
25+
2025-10-15, climate_geo_agged, all, 0
26+
2025-10-15, climate_quantile_extrapolated, all, 0
27+
2025-10-15, climate_linear, hi, 0.0001
28+
##################
1629
# Oct 8: no data, default to climate linear
1730
##################
1831
2025-10-08, all, mp, 0

scripts/covid_nssp_geo_exclusions.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ forecast_date,forecaster,geo_value,weight
1212
2024-10-01, climate_geo_agged, all, 0
1313
2024-10-01, climate_quantile_extrapolated, all, 0
1414
##################
15+
# Oct 15: no data, massively weight climate linear
16+
##################
17+
2025-10-15, all, mp, 0
18+
2025-10-15, windowed_seasonal, all, 1
19+
2025-10-15, windowed_seasonal_extra_sources, all, 0.001
20+
2025-10-15, climate_linear, all, 4
21+
2025-10-15, linear_no_population_scale, all, 3
22+
2025-10-15, linearlog, all, 0
23+
2025-10-15, climate_base, all, 3
24+
2025-10-15, climate_geo_agged, all, 0
25+
2025-10-15, climate_quantile_extrapolated, all, 0
26+
##################
1527
# Oct 8: no data, massively weight climate linear
1628
##################
1729
2025-10-08, all, mp, 0

scripts/flu_geo_exclusions.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ forecast_date,forecaster,geo_value,weight
1212
2024-10-01, climate_geo_agged, all, 0
1313
2024-10-01, climate_quantile_extrapolated, all, 0
1414
##################
15+
# Oct 15: no data, massively weight climate linear
16+
##################
17+
2025-10-15, all, mp, 0
18+
2025-10-15, windowed_seasonal, all, 0.01
19+
2025-10-15, windowed_seasonal_extra_sources, all, 0.01
20+
2025-10-15, climate_linear, all, 5
21+
2025-10-15, linear, all, 2
22+
2025-10-15, linearlog, all, 0
23+
2025-10-15, climate_base, all, 2
24+
2025-10-15, climate_geo_agged, all, 0
25+
2025-10-15, climate_quantile_extrapolated, all, 0
26+
##################
1527
# April 30th
1628
##################
1729
2025-04-30, all, mp, 0

scripts/flu_hosp_prod.R

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,56 @@ g_windowed_seasonal_extra_sources <- function(epi_data, ahead, extra_data, ...)
122122
filter(geo_value %nin% c("mo", "us", "wy"))
123123
fcst
124124
}
125+
g_baseline_forecaster <- function(epi_data, ahead, extra_data, ...) {
126+
# all of the forecasts are made in the last ahead
127+
if (ahead < 3) {
128+
return(tibble(geo_value = character(), forecast_date = Date(), target_end_date = Date(), quantile_value = numeric(), value = numeric()))
129+
}
130+
real_forecast_date <- attributes(epi_data)$metadata$as_of
131+
last_data <- epi_data$time_value %>% max()
132+
latency_weeks <- as.integer(real_forecast_date - last_data) / 7
133+
fcst <- epi_data %>%
134+
cdc_baseline_forecaster(
135+
"value",
136+
args_list = cdc_baseline_args_list(aheads = 1:(3 + latency_weeks))
137+
) %>%
138+
`$`(predictions) %>%
139+
pivot_quantiles_longer(.pred_distn) %>%
140+
select(
141+
geo_value, forecast_date,
142+
target_end_date = target_date,
143+
value = .pred_distn_value,
144+
quantile = .pred_distn_quantile_level
145+
) %>%
146+
mutate(
147+
forecast_date = floor_date(forecast_date, "weeks", week_start = 7) + 3,
148+
target_end_date = floor_date(target_end_date, "weeks", week_start = 7) + 3
149+
) %>%
150+
mutate(
151+
ahead = as.integer(target_end_date - forecast_date),
152+
forecast_date = real_forecast_date
153+
)
154+
## fcst %>%
155+
## group_by(geo_value, forecast_date, target_end_date, quantile) %>%
156+
## count() %>%
157+
## arrange(desc(n))
158+
fcst
159+
}
160+
ids <- c(
161+
"cdc_baseline",
162+
"linear",
163+
"linear_no_population_scale",
164+
"windowed_seasonal",
165+
"windowed_seasonal_extra_sources",
166+
"climate_base",
167+
"climate_geo_agged",
168+
"seasonal_nssp_latest"
169+
)
170+
list_of_empty_lists <- lapply(1:length(ids), \(x) list())
125171
g_forecaster_params_grid <- tibble(
126-
id = c(
127-
"linear",
128-
"linear_no_population_scale",
129-
"windowed_seasonal",
130-
"windowed_seasonal_extra_sources",
131-
"climate_base",
132-
"climate_geo_agged",
133-
"seasonal_nssp_latest"
134-
),
172+
id = ids,
135173
forecaster = rlang::syms(c(
174+
"g_baseline_forecaster",
136175
"g_linear",
137176
"g_linear_no_population_scale",
138177
"g_windowed_seasonal",
@@ -141,24 +180,8 @@ g_forecaster_params_grid <- tibble(
141180
"g_climate_geo_agged",
142181
"g_windowed_seasonal_extra_sources"
143182
)),
144-
params = list(
145-
list(),
146-
list(),
147-
list(),
148-
list(),
149-
list(),
150-
list(),
151-
list()
152-
),
153-
param_names = list(
154-
list(),
155-
list(),
156-
list(),
157-
list(),
158-
list(),
159-
list(),
160-
list()
161-
)
183+
params = list_of_empty_lists,
184+
param_names = list_of_empty_lists
162185
)
163186

164187

scripts/flu_nssp_geo_exclusions.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ forecast_date,forecaster,geo_value,weight
1111
2024-10-01, climate_base, all, 0.5
1212
2024-10-01, climate_geo_agged, all, 0
1313
2024-10-01, climate_quantile_extrapolated, all, 0
14+
##################
15+
# Oct 15: no data, massively weight climate linear
16+
##################
17+
2025-10-15, all, mp, 0
18+
2025-10-15, windowed_seasonal, all, 0.01
19+
2025-10-15, windowed_seasonal_extra_sources, all, 0.001
20+
2025-10-15, climate_linear, all, 5
21+
2025-10-15, linear, all, 2
22+
2025-10-15, linearlog, all, 0
23+
2025-10-15, climate_base, all, 2
24+
2025-10-15, climate_geo_agged, all, 0
25+
2025-10-15, climate_quantile_extrapolated, all, 0

0 commit comments

Comments
 (0)