如何使用hts :: combinef()获得自上而下的预测? [英] How to get top down forecasts using `hts::combinef()`?
问题描述
我正在尝试将hts
包中的预测对帐方法与以前的现有预测进行比较.我无法使用forecast.gts
函数,因为没有计算上容易处理的方式来创建用户定义的函数,该函数返回预测对象中的值.因此,我使用软件包中的combinef()
函数重新分配了预测.我已经能够使用适当的weights
来获取wls
和nseries
方法,并且ols
版本是默认版本.我能够使用以下方法获得自下而上"的方法:
I am trying to compare forecast reconciliation methods from the hts
package on previously existing forecasts. The forecast.gts
function is not available to me since there is no computationally tractable way to create a user defined function that returns the values in a forecast object. Because of this, I am using the combinef()
function in the package to redistribute the forecasts. I have been able to work of the proper weights
to get the wls
and nseries
methods, and the ols
version is the default. I was able to get the "bottom up" method using:
# Creates sample forecasts, taken from `combinef()` example
library(hts)
h <- 12
ally <- aggts(htseg1)
allf <- matrix(NA, nrow = h, ncol = ncol(ally))
for(i in 1:ncol(ally))
allf[,i] <- forecast(auto.arima(ally[,i]), h = h, PI = FALSE)$mean
allf <- ts(allf, start = 51)
# create the weight vector
numTS <- ncol(allf) # Get the total number of series
numBaseTS <- sum(tail(htseg1$nodes, 1)[[1]]) # Get the number of bottom level series
# Create weights of 0 for all aggregate ts and 1 for the base level
weightVals <- c(rep(0, numTS - numBaseTS), rep(1, numBaseTS))
y.f <- combinef(allf, htseg1$nodes, weights = weightVals)
我希望像使第一个权重1
和其余的0
之类的东西可以给我三个自上而下的预测之一,但这只会导致一堆0
s或NaN
值取决于您如何看待它.
I was hoping that something like making the first weight 1
and the rest 0
might give me one of the three top down forecast, but that just results in a bunch of 0
s or NaN
values depending on how you try to look at it.
combinef(allf, htseg1$nodes, weights = c(1, rep(0, numTS - 1)))
我知道自上而下的方法并不是手动计算最困难的事情,并且我可以编写一个函数来执行此操作,但是hts
包中是否有任何工具可以帮助解决此问题?我想保持数据格式一致,以简化分析.最具体地说,我想获得自上而下的预测比例"或tdfp
方法.
I know the top down methods aren't the hardest thing to compute manually, and I can just write a function to do that, but are there any tools in the hts
package that can help with this? I'd like to keep the data format consistent to simplify my analysis. Most specifically, I would like to get the "top down forcasted proportions" or tdfp
method.
推荐答案
当前未导出使用自上而下"方法协调预测的功能.也许我应该导出它们,以使自上而下"的结果在下一个版本中像combinef()
一样易于处理.解决方法如下:
The functions to reconcile the forecasts using the "top-down" method are currently not exported. Probably I should export them to make the "top-down" results as tractable as combinef()
in the next version. The workaround is as follows:
hts:::TdFp(allf, nodes = htseg1$nodes)
希望有帮助.
这篇关于如何使用hts :: combinef()获得自上而下的预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!