ensemble_forecasts: Combine several models' forecasts into one

View source: R/ensemble.R

ensemble_forecastsR Documentation

Combine several models' forecasts into one

Description

Averages (simple or inverse-error-weighted) several already-fit models' forecasts – no re-fitting. Models that don't share every ds are handled by renormalizing weights per-row over whichever models actually have a value there.

Usage

ensemble_forecasts(
  forecasts,
  method = c("mean", "inverse_error"),
  errors = NULL
)

Arguments

forecasts

A named list of ds/yhat tibbles (names are the model labels).

method

"mean" (the default) weights every model equally; "inverse_error" weights each model by 1/errors[[name]]. A model missing from errors, or with a non-positive/NA error, falls back to equal weight rather than dividing by zero.

errors

Required for method = "inverse_error": a named list or vector of each model's own test error (e.g. RMSE or MASE, from safe_compute_metrics() – not re-derived here), keyed by the same names as forecasts.

Value

A tibble with columns ds and yhat – the combined forecast.

Examples

ds <- as.Date("2024-01-01") + 0:2
forecasts <- list(
  A = tibble::tibble(ds = ds, yhat = c(10, 10, 10)),
  B = tibble::tibble(ds = ds, yhat = c(20, 20, 20))
)
ensemble_forecasts(forecasts, method = "mean")
ensemble_forecasts(forecasts, method = "inverse_error", errors = list(A = 1, B = 5))

forecastsuite documentation built on Oct. 18, 2026, 5:08 p.m.