将不同的预测方法传递给R中的层次时间序列预测?

use*_*317 5 r time-series hierarchical forecasting

我有一个分层的时间序列,其中底层系列都表现出间歇性的需求.使用Hyndman的HTS软件包在层次结构中实现最佳组合似乎是有利的.使用Kourentzes的MAPA包进行间歇性需求的多重聚合预测似乎也是有利的.从本质上讲,我想做的事情如下:

forecast(my_hts, method='comb', fmethod='MAPA')

但是,我不清楚是否/如何将两者结合起来,因为forecast.gts()只接受fmethod=c("ets", "arima", "rw").

是否有一种聪明的方法可以传递不同的预测方法forecast.gts()而不必撕掉代码?

举例澄清我的意思:

library(hts)
library(MAPA)
set.seed(1)

#note intermittent demand of bottom level time series
x <- ts(rpois(365, lambda=0.05), frequency=365, start=2014)
y <- ts(rpois(365, lambda=0.07), frequency=365, start=2014)

#it's easy to make a MAPA forecast for the top-level time series
#but this isn't an optimal hierarchical forecast
mapasimple(x+y)

#it's also easy to make this a HTS and make an optimal hierarchical forecast
#but now I cannot use MAPA
z <- hts(data.frame(x,y)))
z_arima <- forecast(z, fmethod="arima")
z_rw <- forecast(z, fmethod="rw")
z_ets <- forecast(z, fmethod="ets")

#z_MAPA <- ?
Run Code Online (Sandbox Code Playgroud)

use*_*317 5

我发帖是因为仔细看了一下hts文档(在这里插入了当之无愧的RTFM)后,我想我找到了一个使用combinef()hts函数的解决方法,它可以用来优化组合forecast.gts()环境之外的预测.在接受答案之前,我会暂时搁置一段时间,以便其他人可以告诉我,如果我错了.

fh <- 8

library(hts)
library(MAPA)
set.seed(1)

x <- ts(rpois(365, lambda=0.05), frequency=365, start=2014)
y <- ts(rpois(365, lambda=0.07), frequency=365, start=2014)

my_hts <- hts(data.frame(x,y))

ally <- aggts(my_hts)

allf <- matrix(NA, nrow = fh, ncol = ncol(ally))

for(i in 1:ncol(ally)){
    allf[,i] <- mapafor(ally[,i], 
                        mapaest(ally[,i], outplot=0), 
                        fh = fh, 
                        outplot=0)$outfor
}

allf <- ts(allf)

y.f <- combinef(allf, my_hts$nodes, weights=NULL, keep="bottom")

#here's what the non-reconciled, bottom-level MAPA forecasts look like
print(allf[1,1:2])

 Series 1   Series 2
1 0.1343304 0.06032574

#here's what the reconciled MAPA bottom-level forecasts look like
#notice that they're different
print(y.f[1,])

[1] 0.06030926 0.07402938
Run Code Online (Sandbox Code Playgroud)