Reputation: 43
When combining forecasts using combinef() the resulting hts time series has level names which are like A, AA, AB... It doesn't retain the level names from the supplied hts time series.
In the example below, bottom level names are "A10A" & "A10B", while the resulting bottom names are "AA","BB".
Is there a way to retain the original level names in the combined forecast object?
library(forecast)
library(hts)
abc <- ts(5 + matrix(sort(rnorm(20)), ncol = 2, nrow = 10))
colnames(abc) <- c("A10A", "A10B")
y <- hts(abc, characters = c(3, 1))
h <- 12
ally <- aggts(y)
allf <- matrix(NA, nrow = h, ncol = ncol(ally))
for(i in 1:ncol(ally))
allf[,i] <- forecast(auto.arima(ally[,i]), h = h)$mean
allf <- ts(allf)
y.f <- combinef(allf, get_nodes(y), weights = NULL, keep = "gts", algorithms = "lu")
Upvotes: 3
Views: 156
Reputation: 31800
At the end of your code, add the following lines:
colnames(allf) <- colnames(ally)
colnames(y.f$bts) <- colnames(y$bts)
y.f$nodes <- y$nodes
y.f$labels <- y$labels
Upvotes: 1