How to use ‘hts’ with multi-level hierarchies?

非 Y 不嫁゛ 提交于 2019-12-06 01:46:49

问题


I am forecasting on a large set of time series (5,000+). I would like to do this with a hierarchical approach were I do the forecasting at a higher level and then allocate the forecast down to each SKU. I see a need for doing this in order to zoom into a lower geographic level of detail, while doing the forecasting on a higher level (top-down).

For example, below you see a sample of the structure that I am thinking about.

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

I would like to do the top-down forecast at continent level (i.e. Europe or Africa) level. Then allocate the appropriate share to the countries, then to the clients within that country and then to the SKU.

In the documentation of the ‘hts’ package there is an example on how to do this with a two-level hierarchy. I was wondering whether somebody could advise on how to do this with a multi-level hierarchy?


回答1:


We introduced a new concept nodes into the hts package (v4+) to replace the old gmatrix. To illustrate the usage of nodes, here's an example of a hierarchy with 4 levels (excluding total) and 24 bottom time series.

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)

Each element of nodes specifies the number of children each node has at that level.

The tree plot is shown below:

=> 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



回答2:


The documentation is a bit terse, but you can use multi-level hierarchies when defining hts

In the pdf file link to the reference manual for the 'hts' package, you will find a reference to the paper. Specifically, on Page 7 of the pdf, where htseg1 is referenced:

R. J Hyndman, R. A. Ahmed, G. Athanasopoulos and H.L. Shang (2011) Optimal combination forecasts for hierarchical time series. Computational Statistics and Data Analysis, 55(9), 2579–2589. http://robjhyndman.com/papers/hierarchical/

That link (the free online version which is a working paper) has an example with 3 levels, which is very similar to your continent|country|client example. http://robjhyndman.com/papers/Hierarchical6.pdf (See Section 6, page 14 which is titled Numerical Simulations)

Hope that helps.



来源:https://stackoverflow.com/questions/13579292/how-to-use-hts-with-multi-level-hierarchies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!