Skip to content

Commit c6e63eb

Browse files
committed
latency adjustment for climate_linear
1 parent 6ff4f46 commit c6e63eb

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

R/forecasters/ensemble_linear_climate.R

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
#' @importFrom rlang %||%
1414
#' @export
1515
ensemble_climate_linear <- function(
16-
forecasts,
17-
aheads,
18-
other_weights = NULL,
19-
probs = covidhub_probs(),
20-
min_climate_ahead_weight = 0.05,
21-
max_climate_ahead_weight = 0.90,
22-
min_climate_quantile_weight = 0.1,
23-
max_climate_quantile_weight = 1
24-
) {
16+
forecasts,
17+
aheads,
18+
other_weights = NULL,
19+
probs = covidhub_probs(),
20+
min_climate_ahead_weight = 0.05,
21+
max_climate_ahead_weight = 0.90,
22+
min_climate_quantile_weight = 0.1,
23+
max_climate_quantile_weight = 1) {
24+
browser()
25+
last_data <- min(forecasts$target_end_date)
26+
forecast_date <- min(forecasts$forecast_date)
27+
latency <- as.integer(forecast_date - last_data) / 7
28+
aheads <- aheads + latency
29+
forecasts %<>% filter(grepl("climate|linear", forecaster)) %>% mutate(forecast_date = last_data)
2530
weights <-
2631
make_ahead_weights(aheads, min_climate_ahead_weight, max_climate_ahead_weight) %>%
2732
left_join(
@@ -83,7 +88,8 @@ ensemble_climate_linear <- function(
8388
mutate(value = weight * value) %>%
8489
group_by(geo_value, forecast_date, target_end_date, quantile) %>%
8590
summarize(value = sum(value, na.rm = TRUE), .groups = "drop") %>%
86-
sort_by_quantile()
91+
sort_by_quantile() %>%
92+
mutate(forecast_date = .env$forecast_date)
8793
return(weighted_forecasts)
8894
}
8995

0 commit comments

Comments
 (0)