ellisp / forecastHybrid

Convenient functions for ensemble forecasts in R combining approaches from the {forecast} package
GNU General Public License v3.0
79 stars 23 forks source link

Using forecastHybrid with hts #74

Closed amarchin closed 7 years ago

amarchin commented 7 years ago

I was trying to use forecastHybrid with hierarchical time series and external regressors but I cannot figure out how to do that. I am trying in this way:

library(hts)
library(forecastHybrid )

forecast(htseg1, a.args = list(xreg = data.frame(1:10)), models = "aet", 
xreg = data.frame(11:20), FUN = hybridModel)

But I got the following error:

Error in forecast.Arima(object$auto.arima, h = h, xreg = xreg, level = level) : No regressors provided

dashaub commented 7 years ago

Strange, I thought I remembered "hts" supporting custom functions, but it looks like it only allows ETS, ARIMA, and RW models.

@earowang is this correct?

earowang commented 7 years ago

The forecast function in hts does support user-defined functions. It's a bug in the hts package due to the use of xreg argument. hybridModel currently works without the external regressors.

In order to work around the issue, I would use hybridModel for each hierarchical series and then use combinef() to reconcile the forecasts. Please check out the examples in the combinef() documentation.

amarchin commented 7 years ago

Thanks for the answer, I wasn't aware of the combinef() function. I think this workaround can solve my problem.