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
- 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 -
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 executingBy default it supports only ("ets","arima") models for future predictions - what if I have to use other methods?
while using the
accuracy.gts
function getting theerror - 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
gy <- gts(traning_data, characters = list(c(8,4),c(5,4)) )
should fix the error message. The first 4 lettersA013
in the column headers are repeated for the dataset, which makes it invalid to create a grouping variable. (2) To fit models other thanets
andarima
, please see?combinef
. $\endgroup$