0

I think this is similar post to this post passing forecasting method to hts

The example given there is for MAPE package. Is it possible to use the croston function in the forecast package in a similar way?

I simply tried

all_ts <- aggts(bts)
  allf <- matrix(NA, nrow = 3, ncol = ncol(all_ts))
  for(i in 1:ncol(all_ts)){
       allf[,i] <- croston(all_ts[,i],h = 3)  
  }

But that gives me an error saying number of items to replace is not a multiple of replacement length.

Community
  • 1
  • 1
Thisara Watawana
  • 344
  • 4
  • 15

1 Answers1

2

Look at the structure of the object returned by croston. It is not a simple vector. The following code is an example that works.

library(hts)
nodes <- list(2, c(3, 2))
abc <- ts(5 + matrix(sort(rnorm(500)), ncol = 5, nrow = 100))
bts <- hts(abc, nodes)
all_ts <- aggts(bts)
allf <- matrix(NA, nrow = 3, ncol = ncol(all_ts))
for(i in 1:ncol(all_ts)){
  allf[,i] <- croston(all_ts[,i],h = 3)$mean
}
y.f <- combinef(allf, bts$nodes)
Rob Hyndman
  • 30,301
  • 7
  • 73
  • 85
  • Thank you very much for the prompt respond sir. I think this is what I wanted to know. However when I run this code I will get the same forecasted value for all three time periods. I still couldn't identify what went wrong. – Thisara Watawana Sep 16 '15 at 14:00
  • You wanted Croston's method. That's the way it works. – Rob Hyndman Sep 16 '15 at 22:22