gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:34:14 24 4
gpt4 key购买 nike

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

最佳答案

我发帖是因为在仔细查看 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

关于r - 将不同的预测方法传递给 R 中的分层时间序列预测?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28670174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com