将不同的预测方法传递给R?中的分层时间序列预测 [英] Passing different forecasting method to hierarchical time series forecast in R?

查看:141
本文介绍了将不同的预测方法传递给R?中的分层时间序列预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分层的时间序列,其最底层的序列都显示出间歇性的需求.使用Hyndman的HTS软件包在层次结构内实现最佳组合似乎是有利的.将Kourentzes的MAPA软件包用于间歇性需求的多次聚合预测似乎也很有利.本质上,我想做类似的事情:

I have a hierarchical time series, the bottom level series of which all exhibit intermittent demand. It seems advantageous to use Hyndman's HTS package for optimal combination within the hierarchy. It also seems advantageous to use Kourentzes' MAPA package for multiple aggregation prediction of the intermittent demand. In essence, I want to do something like:

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

但是,由于forecast.gts()仅接受fmethod=c("ets", "arima", "rw").

是否有一种巧妙的方法可以将不同的预测方法传递给forecast.gts()而不必删除代码?

Is there a clever way to pass different forecasting methods to forecast.gts() without having to tear up the code?

阐明我的意思的示例:

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 <- ?

推荐答案

我之所以发布,是因为仔细查看hts文档(在此处插入当之无愧的RTFM)之后,我认为我发现了使用函数,可用于最佳组合forecast.gts()环境之外的预测.在接受答案之前,我会花一会儿时间,以便其他人可以告诉我我是否错了.

I'm posting because after a closer look at the hts documentation (insert well-deserved RTFM here), I think I found a work-around using the combinef() function from hts, which can be used to optimally combine forecasts outside of the forecast.gts() environment. I'll leave it up for a while before accepting as an answer so others can tell me if I'm wrong.

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

这篇关于将不同的预测方法传递给R?中的分层时间序列预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆