Question

I'm trying to create the node structure for a hts—can anyone help me get this right?

The hierarchy I am working with has 4 levels (excluding total).

Category => Sub_category => Product_type => Product

I can simplify it to the following for reproducibility:

structure <- data.frame(H1 = rep(1:2, rep(12, 2)),
                        H2 = rep(1:4, rep(6, 4)),
                        H3 = rep(1:8, rep(3, 8)),
                        H4 = 1:24)

Given the above structure, how can I construct the node argument for hts()? I've read the documentation but still can't quite get my head around it for structures with more than 2 levels. There's an old question along these lines, for which the answer is now out of date (I think).

Many thanks.

Était-ce utile?

La solution

According to the structure data frame, it uses the following node structure:

nodes <- list(2, rep(2, 2), rep(2, 4), rep(3, 8)) 

Each element of the list gives the number of children for each node at that level.

It becomes clearer if a tree plot can be drawn before making a list of 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

I hope that helps in constructing a node structure with more than 2 levels.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top