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

时间:2015-02-23 02:36:24

标签: r time-series forecasting hierarchical

我有一个分级时间序列,其中底层系列都表现出间歇性需求。使用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 <- ?

3 个答案:

答案 0 :(得分:5)

我发帖是因为仔细看了一下hts文档(在这里插入当之无愧的RTFM)后,我想我找到了一个使用hts combinef()函数的解决方法,可以用来优化结合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

答案 1 :(得分:2)

“有没有一种聪明的方法可以将不同的预测方法传递给forecast.gts(),而不必撕掉代码?” - 几乎肯定不是。 forecast.gts()不允许您将family参数的预测方法插入glm()及类似内容。

最简单的方法是运行MAPA预测,然后自己重​​新实现最佳组合。这真的不是那么难,我在hts包出现之前自己做了几次。查看hts包中的引用;其中大部分都可以作为Rob Hyndman网站上的预印本。

将最优组合方法与间歇性需求预测相结合的一个关键问题是,最优组合可能会产生预测。这些在这里使用的GLS意义上可能是“最佳的”,但它们对需求毫无意义。我的解决方案是在pcls()包中使用mgcv进行实际核对,以便将解决方案(即底层协调预测)限制为非负。

答案 2 :(得分:1)

我在过去使用MAPA预测和combinef的小型实验中成功运行。斯蒂芬关于负面预测的观点仍然存在问题。您可能有兴趣在tsintermittent包中查看iMAPA,该包专门用于生成间歇性需求时间序列的预测。与MAPA相比,人们实现了Croston的方法,SBA和指数平滑以在各种时间聚合级别中进行选择。

我非常有兴趣了解您的结果。也许E. Spiliotis等人在去年的ISF中提出了相关研究。 Examining the effect of temporal aggregation on forecasting accuracy for hierarchical energy consumption time series

相关问题