更新时间:2023-02-18 12:55:42
我之所以发布,是因为仔细查看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