【问题标题】:How to get top down forecasts using `hts::combinef()`?如何使用`hts::combinef()`获得自上而下的预测?
【发布时间】:2017-03-28 00:09:57
【问题描述】:

我正在尝试将 hts 包中的预测协调方法与以前存在的预测进行比较。 forecast.gts 函数对我不可用,因为没有计算上易于处理的方法来创建返回预测对象中的值的用户定义函数。因此,我使用包中的combinef() 函数来重新分配预测。我已经能够使用正确的weights 来获得wlsnseries 方法,并且ols 版本是默认的。我能够使用“自下而上”的方法:

# 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 这样的东西可能会给我三个自上而下的预测之一,但这只会导致一堆 0s 或 NaN 值取决于你如何看待它。

combinef(allf, htseg1$nodes, weights = c(1, rep(0, numTS - 1)))

我知道自上而下的方法并不是最难手动计算的,我可以编写一个函数来做到这一点,但是hts 包中是否有任何工具可以帮助解决这个问题?我想保持数据格式一致以简化我的分析。最具体地说,我想获得“自上而下的预测比例”或tdfp 方法。

【问题讨论】:

    标签: r time-series hierarchy forecasting


    【解决方案1】:

    目前未导出使用“自上而下”方法协调预测的功能。可能我应该导出它们以使“自上而下”的结果在下一个版本中像 combinef() 一样易于处理。解决方法如下:

    hts:::TdFp(allf, nodes = htseg1$nodes)
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2020-10-23
      • 2018-12-27
      • 1970-01-01
      • 2016-07-12
      • 2022-01-01
      • 1970-01-01
      • 2019-03-12
      • 2021-10-26
      • 2016-05-07
      相关资源
      最近更新 更多