memdux
memdux

Reputation: 11

Error when using forecast.hts method tdfp

I am using HTS package in R to evaluate which is the best level in the hierarchy to execute sales forecast.

The issue i have is when executing forecast using tdfp (so top down using bottom forecast to disaggregate). The rest of the models are working ok.

Many thanks in advance for your help

Steps for re-construction: The error meessage i have is:

"Error en rowsum.default(flist[[j + 1L]], repcount) : incorrect length for 'group'"

Files to reproduce the error can be found in (hopefully it works, i am not an expert): https://github.com/memdux/hts_error.git

To reproduce the error you can use the below code:

require("forecast")
require("hts")

dates_input= read.csv("test_data_dates.csv",sep =";", dec = ".")
soh= read.csv("test_data_values.csv",sep =";", dec = ".")

soh_matrix = as.matrix(soh)

ts_soh = ts(soh_matrix, 
            start=c(2012, 01), 
            end=c(2015, 01), 
            frequency=12) 

y <- hts(ts_soh, characters = c(2, 3, 4, 3, 5))

train = window(y, start = c(2012,1), end = c(2014, 9))
test = window(y, start = c(2014,10), end = c(2015, 1))

fcst_hts_3 = forecast.gts(train, h = 4, method = "tdfp", fmethod = "arima")
# Same error if using forecast (no gts) and / or ets as forecast method

Upvotes: 1

Views: 219

Answers (1)

VaughanR
VaughanR

Reputation: 355

I also have hit this issue in hts v5.1.4. It seems that TdFp function does not like a common top level label in the characters parameter. In my case all labels started with "R03" and the characters parameter started with c(3,2,...). When I removed this substring from the labels and changed the characters parameter to c(2,...) it all worked fine.

In the first case the hts the object variable had:

$ nodes:List of 5
 ..$ Level 1: int 1
 ..$ Level 2: 'table' int[1(1d)] 10
...
$ labels: List of 6
 ..$ Level 0: chr "Total"
 ..$ Level 1: chr "R03"

whilst in the second case it was:

$ nodes  :List of 4
  ..$ Level 1: int 10
  ..$ Level 2: 'table' int [1:10(1d)] 5 4 4 4 ...
...
$ labels :List of 5
  ..$ Level 0: chr "Total"
  ..$ Level 1: chr [1:10] "AC" "AK" "AL" "BA" ...

Upvotes: 2

Related Questions