1
$\begingroup$

I am looking for group time series examples. I am working on two hierarchies and interested in interactions also. Couple of challenges I am facing

  1. I have 36 months data and many of the series has leading NAs as not for all the series data is observed from the beginning I am working on hierarchical time series data and interested in interactions also.
    Just to elaborate more - The 2 hierarchies are Geo hierarchy - Area -> Subregion -> Subsidiary and Business Hierarchy - Business sector -> Business Sub-sector Requirement is to do the predictions at area level, sector level and also wants to know how the sector A is likely to perform in Area1 After reading the couple of posts on hierarchical time series I got to know that group time series can solve this problem.

But I couldn't get any examples with code (R) on this, if any sample code is available that would help.

Also, I tried implementing but faced few challenges -

  1. I have 36 months data starting from Jan-2014 and many of the series data is not observed from Jan-2014 i.e it starts from Aug-2014, July-2015 so I have leading NAs for these series how to handle it as I am getting error in gts function while executing

  2. By default it supports only ("ets","arima") models for future predictions - what if I have to use other methods?

  3. while using the accuracy.gts function getting the

    error - Error in colnames<-(*tmp*, value = unlist(labels[levels])) : length of 'dimnames' [2] not equal to array extent

r-code --------------------------

library(hts)

data <- read.csv("test_data_gts.csv", header = TRUE)

traning_data <- data[ data$Month_Num<31, -1 ]

gy <- gts(traning_data, characters = list(c(4,4,4),c(5,4)) )


## after removing the columns with leading NAs , I can create the group time series but I dont want to exlude those columns 

na_cols <- c()
for( i in 2:dim(traning_data)[2]){
  if(any(is.na(traning_data[,i]))){ na_cols <- c( na_cols, i) }
}

traning_data_1 <- traning_data[ , -(na_cols)]

y <- gts(traning_data_1, characters = list(c(4,4,4),c(5,4)) )


## Continued with this series to explore on gts - forecast using forecast.gts

fcast <- forecast(y, h=6, method = "bu",fmethod= "ets" )

holdout_data <- data[data$Month_Num >30, -c(1,na_cols)]

h <- gts(holdout_data,characters = list(c(4,4,4),c(5,4)) )

accuracy.gts(fcast, h ) # gives error - Error in `colnames<-`(`*tmp*`, value = unlist(labels[levels])) : length of 'dimnames' [2] not equal to array extent 

Sample data set

$\endgroup$
2
  • 1
    $\begingroup$ Please register &/or merge your accounts (you can find information on how to do this in the My Account section of our help center), then you will be able to edit & comment on your own question. $\endgroup$
    – Silverfish
    Commented Aug 24, 2017 at 9:09
  • $\begingroup$ (1) gy <- gts(traning_data, characters = list(c(8,4),c(5,4)) ) should fix the error message. The first 4 letters A013 in the column headers are repeated for the dataset, which makes it invalid to create a grouping variable. (2) To fit models other than ets and arima, please see ?combinef. $\endgroup$
    – Earo Wang
    Commented Aug 31, 2017 at 12:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.