forecastHybrid icon indicating copy to clipboard operation
forecastHybrid copied to clipboard

CV of an hybrid model with xreg.

Open ASLlohmann opened this issue 4 years ago • 0 comments

Hi, I don't know if there is a problem but it seems that the cv function struggle to handle the xreg argument if we choose an hybridModel as 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)

ASLlohmann avatar Sep 24 '20 10:09 ASLlohmann