``` {r estimate-heigth} fd <- max(as.Date(forecast_dates))

n_models <- data %>% dplyr::filter(location_name %in% loc) %>% dplyr::group_by(forecast_date) %>% dplyr::summarise(n = length(unique(model))) %>% pull(n) %>% max()

ht <- max(ceiling(n_models / 2) * 1.5, 5)

```r

for (forecast_date in forecast_dates) {
  cat(paste0("\n\n### ", forecast_date, "{.tabset .tabset-fade} \n\n"))

    for (target in names(target_variables)) {
      cat("\n\n####", target, "\n\n")

      filter_both <- list(paste0("target_variable %in% '", target_variables[[target]], "'"), 
                          paste0("location_name %in% '", loc, "'"))
      filter_truth <- list(paste0("target_end_date > '", as.Date(forecast_date) - 7 * 10, "'"), 
                           paste0("target_end_date <= '", as.Date(forecast_date) + 7 * 4, "'"))
      filter_forecasts <- list(paste0("forecast_date == '", as.Date(forecast_date), "'"))

      nrow(data)


      plot <- scoringutils::plot_predictions(data,
                                             x = "target_end_date",
                                             filter_both = filter_both,
                                             filter_truth = filter_truth,
                                             filter_forecasts = filter_forecasts,
                                             facet_formula = ~ model,
                                             ncol = 2,
                                             # facet_formula = model ~ target_variable + loc,
                                             # facet_wrap_or_grid = "facet",
                                             allow_truth_without_pred = FALSE,
                                             scales = "free") + 
        # ggplot2::ggtitle(paste0("Predictions for incident ", target_variable,  "s")) + 
        ggplot2::theme(legend.position = "bottom", 
                       strip.placement = "outside") + 
        scale_y_continuous(labels = scales::comma) + 
        expand_limits(y = 0) + 
        coord_cartesian(ylim = c(0, NA)) 

      if (is.null(plot)) {
        print("no forecasts available")
      } else {
        plot <- plot + 
          labs(x = "Date")
        print(plot)
      }
    }
  }


epiforecasts/europe-covid-forecast documentation built on Jan. 15, 2025, 8:57 p.m.