0

I want to use optimal comination method of hts package in r to get hierarchical forecasts with single exponential smoothing (SES) forecasting method, I read in the manual that avaialble forecast methods are ets, arima and rw. I'm wondering if it is possible to use other forecast methods like SES? I tried to use the following code but I get an error.

library(forecast)    
library(hts)

mydata <- matrix(rnorm(103*2, mean = 200, sd = 20), nrow = 103, ncol = 2)

data <- hts(mydata)
tdata=window(data,1,70)# training data
test=window(data,71,103)# test data
alldata <- aggts(tdata)

allf <- matrix(NA, nrow = 33, ncol = ncol(alldata))#all forecast 

for(i in 1:ncol(alldata))
  allf[,i] <- ses((alldata[,i]), h = 33)$mean# generate forecasts usign SES

tdata.f <- combinef(allf, data$nodes, weights = NULL, keep = "gts")
Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
Roji
  • 113
  • 6

1 Answers1

1

?ets tells you how to specify a model with additive error, no trend and no seasonality, which is SES in state space form. Adding the parameter model="ANN" should work. This will be passed on to ets().

Stephan Kolassa
  • 7,953
  • 2
  • 28
  • 48
  • Thank you Stephan, YES I have tried model="ANN", fmethod = "ets(model="ANN")", But it is not working – Roji Dec 07 '14 at 14:07
  • @Roji You should post a working example your code failure. Try using the `infantgts` dataset from the `hts` package in your example, so we can reproduce it. – Zach Dec 07 '14 at 15:24
  • Actually, I have 420 series and would like to use optimal combination method to get forecasts in top and bottom level, so two levels are available, level0(one series) and level 1(420)series, I use these cods:mydata <- hts(mydata)# I have only two levels; level 0 with one series, level 1 with 420 series h=12 data=window(mydata,1,70) test=window(mydata,71,103) alldata <- aggts(data) allf <- matrix(NA, nrow = h, ncol = ncol(alldata)) for(i in 1:ncol(alldata)) allf[,i] <- forecast(ets((alldata[,i]),model="ANN"), h = h)$mean data.f <- combinef(allf, mydata$nodes, weights = NULL, keep = "gts") – Roji Dec 07 '14 at 15:25
  • When I run it, I get the following error: Error in nvec[i] <- dim(cc)[1L] : replacement has length zero – Roji Dec 07 '14 at 15:27
  • 1
    [Please read this Q&A closely.](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) Then edit your question to include a *minimal reproducible example*. Then comment here to notify me. Without a reproducible example, there is nothing we can do. – Stephan Kolassa Dec 07 '14 at 16:36
  • Thank you, I included a reproducible example – Roji Dec 08 '14 at 14:25
  • This is interesting. As far as I can tell, `combinef()` appears not to work for the simplest possible hierarchy (2 bottom series and a total). I edited your example slightly to make it *minimal* (2 instead of 420 series) and will point Rob Hyndman here. If he confirms that this is a bug, [please submit a bug report here](https://github.com/robjhyndman/hts/issues), including this example and a link here. – Stephan Kolassa Dec 08 '14 at 18:50
  • Thank you Stephan, inded I tried to use it for more than two levels and it is working – Roji Dec 08 '14 at 19:01
  • Turns out that updating to hts 4.4 solves the problem (I was using 4.2). – Stephan Kolassa Dec 08 '14 at 21:45