thief_reconcile: Temporal hierarchy reconciliation of previously fitted...

Description Usage Arguments Details References See Also Examples

View source: R/thief_reconcile.R

Description

This function fits ensemble univariate forecast models on all levels of temporal aggregation for a series and reconciles the supplied univariate forecast object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
thief_reconcile(
  y,
  original_forecast,
  forecast_residuals = NULL,
  lambda = NULL,
  frequency,
  return_aggregates = FALSE,
  prior_aggregates = NULL,
  max_agg = NULL
)

Arguments

y

Either a xts matrix or ts object. The outcome series to be modelled. NAs are currently not supported

original_forecast

Either a forecast or list object, the latter of which must contain slots named forecast (containing the mean, upper interval and lower interval forecasts) and residuals (containing residuals for the fitted forecast model)

forecast_residuals

Optional vector of residuals from the forecast, if the forecast is a matrix representing the forecast distribution

lambda

numeric. The Box Cox power transformation parameter for all series. Must be between -1 and 2 inclusive. If y contains zeros, lambda will be set to max(c(0.7, lambda)) to ensure stability of forecasts

frequency

integer. The seasonal frequency in y

return_aggregates

Logical. If TRUE, the forecasts and residuals for the aggregate series will also be returned

prior_aggregates

Optional result of a previous call to thief_reconcile that contains the forecasts and residuals from the temporal aggregate forecasts for the same y. If supplied, forecasts for the temporal aggregates will not be calculated again prior to reconciliation, saving on computation.

max_agg

(optional) integer specifying the maximum number of temporal aggregation levels to use when reconciling, via the structural scaling method. Useful if higher levels of aggregation are unlikely to have 'seen' recent changes in series dynamics and will likely then result in poor forecasts as a result. Default is NULL, meaning that all levels of aggregation are used

Details

Series in y are aggregated at all possible levels up to annual using tsaggregates. ensemble_base is used on all levels of aggregation to find a weighted ensemble of nine univariate forecast models that minimises mean absolute scaled error. Forecasts are then reconciled using reconcilethief and are optionally constrained using non-negative optimisation if there are no negative values in y. Adjustments to the original supplied forecast are incorporated and this adjusted forecast is returned

References

Athanasopoulos, G., Hyndman, R., Kourentzes, N., and Petropoulos, F. Forecasting with temporal hierarchies. (2017) European Journal of Operational Research 262(1)

See Also

reconcilethief

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(mvforecast)
data("ixodes_vets_dat")

#Fit a univariate model to one of the series in the ixodes data
y <- ixodes_vets_dat$y_train[,1]
xts.to.ts <- function(x, freq = 52) {
start_time <- floor((lubridate::yday(start(x)) / 365) * freq)
ts(as.numeric(x), start = c(lubridate::year(start(x)), start_time), freq = freq)}

original_forecast <- forecast(auto.arima(xts.to.ts(y, freq = 52)), h = 52)
reconciled <- thief_reconcile(y = y, original_forecast = original_forecast, frequency = 52)

#Plot the original and reconciled forecasts
reconciled <- thief_reconcile(y = y, original_forecast = original_forecast, frequency = 52)
autoplot(original_forecast)
autoplot(reconciled)

nicholasjclark/mvforecast documentation built on Dec. 22, 2021, 2:11 a.m.