ets: Error in ets(timeseries, model = "MAM") : Nonseasonal data

3.3k Views Asked by At

I'm trying to create a forecast using an exponential smoothing method, but get the error "nonseasonal data". This is clearly not true - see code below. Why am I getting this error? Should I use a different function (it should be able to perform simple, double, damped trend, seasonal, Winters method)?

library(forecast)

timelen<-48 # use 48 months
dates<-seq(from=as.Date("2008/1/1"), by="month", length.out=timelen)

# create seasonal data
time<-seq(1,timelen)
season<-sin(2*pi*time/12)
constant<-40
noise<-rnorm(timelen,mean=0,sd=0.1)
trend<-time*0.01
values<-constant+season+trend+noise

# create time series object
timeseries<-as.ts(x=values,start=min(dates),end=max(dates),frequency=1)
plot(timeseries)

# forecast MAM
ets<-ets(timeseries,model="MAM") # ANN works, why MAM not?
ets.forecast<-forecast(ets,h=24,level=0.9)
plot(ets.forecast)

Thanks&kind regards

1

There are 1 best solutions below

0
agenis On BEST ANSWER

You should use ts simply to create a time series from a numeric vector. See the help file for more details.

Your start and end values aren't correctly specified. And setting the frequency at 1 is not a valid seasonality, it's the same as no seasonality at all.

Try:

timeseries <- ts(data=values, frequency=12)
ets <- ets(timeseries, model="MAM")
print(ets)
#### ETS(M,A,M) 
#### Call:
####   ets(y = timeseries, model = "MAM") 
####   ...

enter image description here

The question in your comments, why ANN works is because the third N means no seasonnality, so the model can be computed even with a non-seasonal timeseries.