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

CV of an hybrid model with xreg. #96

Open ASLlohmann opened 3 years ago

ASLlohmann commented 3 years ago

Hi, I don't know if there is a problem but it seems that the cvfunction struggle to handle the xregargument if we choose an hybridModelas FUN

y=ts(rnorm(100), start=c(1999,1), frequency=12)
x=ts(rnorm(100), start=c(1999,1), frequency=12)

When I run this code:

cv.1=forecastHybrid::cvts(y, FUN=hybridModel, models="an",
  rolling = TRUE,
  windowSize = 84 ,a.args=list(xreg=cbind(x)),
  maxHorizon = 1)

I get this error message:

Error during wrapup: task 1 failed - "variable lengths differ (found for 'xregg')"
Error: no more error handlers available (recursive errors?); invoking 'abort' restart

Any idea of the problem ?

Edit : I just found the solution to the problem.

cv = cvts(y, FUN = function(z, xreg = xreg), 
  forecastHybrid::hybridModel(z,models = "an")}, 
  xreg=as.matrix(x),rolling = TRUE,  windowSize = 84, 
  maxHorizon = 1,  horizonAverage = FALSE)

This is quite tricky, probably it could be nice to add an example in the R/Rd files.

Using custom model functions with xreg.

cvmodCustom=cvts(series, FUN=function(y, xreg=xreg){hybridModel(y, models="an")}, xreg=x)