I have a hierarchical data. The data has the following levels (top to down):
I am forecasting using r
library hts
. To increase accuracy I would like to use thief
library (also nnfor::mlp.thief
and nnfor::elm.thief
functions). I added these functions to forecast.hts()
in the following way,
loopfn <- function(x, ...) {
out <- list()
if (is.null(FUN)) {
if (fmethod == "ets") {
models <- forecast::ets(x, lambda = lambda, ...)
out$pfcasts <- forecast::forecast(models, h = h, PI = FALSE)$mean
} else if (fmethod == "arima") {
models <- forecast::auto.arima(x, lambda = lambda, xreg = xreg,
parallel = FALSE, ...)
out$pfcasts <- forecast::forecast(models, h = h, xreg = newxreg)$mean
} else if (fmethod == "rw") {
models <- forecast::rwf(x, h = h, lambda = lambda, ...)
out$pfcasts <- models$mean
} else if (fmethod == "thief"){
models <- thief::thief(x, h = h , usemodel = usemodel, ...)
out$pfcasts <- models$mean
}else if (fmethod == "mlp.thief"){
models <- nnfor::mlp.thief(x, h = h , ...)
out$pfcasts <- models$mean
} else if (fmethod == "elm.thief"){
models <- nnfor::elm.thief(x, h = h , ...)
out$pfcasts <- models$mean
}
} else { # user defined function to produce point forecasts
models <- FUN(x, ...)
if (is.null(newxreg)) {
out$pfcasts <- forecast(models, h = h)$mean
} else {
out$pfcasts <- forecast(models, h = h, xreg = newxreg)$mean
}
}
if (keep.fitted) {
out$fitted <- stats::fitted(models)
}
if (keep.resid) {
out$resid <- stats::residuals(models)
}
return(out)
}
Would there be any theoretical problem to do so? In fact, it increases forecast accuracy.
considering the following literature I do not see any problem though Hyndman et.al. 2017 and Hyndman et.al. 2011
I could use any function with the argument FUN =
The function has to be forecast object.