Solved – R forecast ets initial level and trend

excelforecastingrsmoothing

I am trying to understand how the ets function of R in the forecast package computes initial level $l_0$, and initial trend $b_0$. I was under the impression that they are set to the intercept and slope of the whole data, but it seems it's not true. I would appreciate any explanation on this.

Also, Excel 2016 introduced FORECAST.ETS function, whose results don't seem to match those produced by R's ets function. What would be possible explanations for the discrepancies in the results.

Another thing is that when I apply ets on airpass dataset, it doesn't detect seasonality period (12) correctly. The model it picks is ETS(M,A,N), and when I force it to use model="AAA" it shows the following error message: "Error in ets(airpass, model = "AAA") : Nonseasonal data."

Any help is really appreciated.

Best Answer

You have three different questions.

  1. This is not really an answer, admittedly... have you looked at the source code of ets()? By simply typing ets, it appears like the actual model fitting is done by a function etsmodel that is not publicly exposed. Stepping through source code line by line is an extremely helpful exercise. If you still have questions, I'd recommend you ask a specific question in the R tag at StackOverflow. Best to read their help center first and show how far you have come on your own.

  2. Excel's FORECAST.ETS appears to do triple exponential smoothing with additive trend, seasonality and error. This is different from R's ets(), which calculates an equivalent state space model. Differences could arise from ets() choosing a different model, but even if it also uses an AAA model, smoothing parameters could be optimized differently (possibly even with differences in numerical optimization routines), or initializations could be different. For the R function, you can inspect the code. For the Excel one, you can't.

  3. When I type ets(AirPassengers), I get an (M, A, M) model, so seasonality is modeled multiplicatively. The built-in dataset AirPassengers seems to contain the same numbers as the one you link to. My suspicion is that when you simply use the sequence of numbers you linked to, you did not specify that these are monthly data. For instance, if I do this:

    foo <- ts(read.table("http://homepage.stat.uiowa.edu/~kchan/TSA/Datasets/airpass.dat",header=TRUE)[,1],frequency=12,start=1949)

(note frequency=12!), then ets(foo) again gives my an (M, A, M) model. Which is actually not surprising, since

all.equal(foo,AirPassengers)
[1] TRUE