Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 927
Jochem Avatar asked Nov 27 '12 07:11

Jochem


2 Answers

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
like image 125
Earo Wang Avatar answered Oct 02 '22 18:10

Earo Wang


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.

like image 44
Ram Narasimhan Avatar answered Oct 02 '22 18:10

Ram Narasimhan