hts R package forecasted values

103 views Asked by At

I was using the hts R package for hierarchical forecasting and I want to obtain or extract the forecasted values into a data frame, for example:

library(hts)
data <- window(htseg2, start = 1992, end = 2002)
test <- window(htseg2, start = 2003)
fcasts <- as.data.frame(forecast(data, h = 5, method = "bu"))
plot(fcasts)

enter image description here which plots the forecasted values in dotted lines, implying that somehow they can be extracted however, the fcasts object does not store such information.

Thank you

1

There are 1 answers

0
Rob Hyndman On BEST ANSWER

The forecasts are saved efficiently, but if you want all of them, they can be computed using allts() and then converted to a data frame as follows.

as.data.frame(allts(forecast(data, h = 5, method = "bu")))