如何在多层次结构中使用“hts”?

时间:2012-11-27 07:25:55

标签: r hierarchy time-series forecasting

我正在预测大量的时间序列(5,000+)。如果我在更高级别进行预测,然后将预测分配到每个SKU,我想使用分层方法执行此操作。我认为有必要这样做,以便放大到较低的地理细节水平,同时在更高的层次(自上而下)进行预测。

例如,下面您将看到我正在考虑的结构示例。

Total
  => Europe
     => Netherlands
        => RegionA
           => Client_A_in_Netherlands
              => SKU1
              => SKU2
              => SKU3
           => Client_Q_in_Netherlands
              => SKU15
     => Germany1
        => (...)
           => ClientY_in_Germany
              => SKU89
  => Africa
     => South Africa
        => (...)
           => Client_Z_in_SouthAfrica
              => SKU792

我想在大陆层面(即欧洲或非洲)水平进行自上而下的预测。然后将适当的份额分配给国家/地区,然后分配给该国家/地区的客户,然后分配给SKU。

在'hts'包的文档中,有一个关于如何使用两级层次结构执行此操作的示例。我想知道是否有人可以建议如何使用多级层次结构来做到这一点?

2 个答案:

答案 0 :(得分:8)

我们在nodes包(v4 +)中引入了一个新概念hts来替换旧的gmatrix。为了说明nodes的用法,这里是一个包含4个级别(不包括总计)和24个底部时间序列的层次结构示例。

bts <- ts(matrix(rnorm(240), nrow = 10, ncol = 24)) 
nodes <- list(2, rep(2, 2), rep(2, 4), rep(3, 8))
hts(bts, nodes = nodes)

nodes的每个元素都指定每个节点在该级别拥有的子节点数。

树形图如下所示:

=> A
  => AA
    => AAA
      => 3 bottom time series
    => AAB
      => 3 bottom time series
  => AB
    => ABA
      => 3 bottom time series
    => ABB
      => 3 bottom time series
=> B
  => BA
    => BAA
      => 3 bottom time series
    => BAB
      => 3 bottom time series
  => BB
    => BBA
      => 3 bottom time series
    => BBB
      => 3 bottom time series

答案 1 :(得分:3)

文档有点简洁,但在定义hts

时可以使用多级层次结构

In the pdf file link to the reference manual对于'hts'包,您会找到对该论文的引用。具体来说,在pdf的第7页上,引用了 htseg1

R上。 J Hyndman,R。A. Ahmed,G。Athanasopoulos和H.L. Shang(2011)Optimal combination 分层时间序列的预测。 计算统计和数据分析 55(9),2579-2589 http://robjhyndman.com/papers/hierarchical/

该链接(免费在线版本是一份工作文件)有3个级别的示例,这与您的大陆|客户端示例非常相似。 http://robjhyndman.com/papers/Hierarchical6.pdf(见第14页第6节,标题为数值模拟)

希望有所帮助。

相关问题