#' Create ensemble using mean or median average.
#'
#' @param forecasts `data.frame` containing all the forecasts to be summarised
#' as an ensemble.
#' @param method One of `mean` (default) or `median`.
#'
#' @return ensemble model
#'
#' @importFrom dplyr group_by %>% summarise n
#' @importFrom stats median
#'
#' @autoglobal
#'
#' @export
create_ensemble_average <- function(forecasts,
method = c("mean", "median")) {
method <- match.arg(method)
# Mean
if (method == "mean") {
ensemble <- forecasts %>%
group_by(target_variable, horizon, temporal_resolution,
target_end_date, location, type, quantile) %>%
summarise(forecasts = n(),
value = mean(value),
.groups = "drop")
# Median
} else if (method == "median") {
ensemble <- forecasts %>%
group_by(target_variable, horizon, temporal_resolution,
target_end_date, location, type, quantile) %>%
summarise(forecasts = n(),
value = median(value),
.groups = "drop")
}
# Return ensemble
return(ensemble)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.