Solved – Starting out with forecast package in R

forecastingrtime series

I am new to forecasting in R and am trying to automatically fit an ARIMA model to what I believe is a univariate dataset.

> str(p1.z)
'zoo' series from 2009-04-05 to 2010-10-31
  Data: int [1:83] 360 570 540 585 570 690 495 660 510 690 ...
  Index: Class 'Date'  num [1:83] 14339 14346 14353 14360 14367 ...

>  head(p1.z) 
  2009-04-05 2009-04-12 2009-04-19 2009-04-26 2009-05-03 2009-05-10 
         360        570        540        585        570        690

But when I try to fit the model, I get the error as seen below.

> p1.arima <- auto.arima(p1.z)
Error in nsdiffs(xx) : Non seasonal data

It is my understanding that the forecast package and the auto.arima function would be able to fit my data seasonal or not. I am trying to learn time series forecasting and am using a dataset that appears to be ideal for this sort of task . Also, the function ets() was able to find a model.

Any help you can provide will be greatly appreciated

Best Answer

ets() and auto.arima() are not really set up to handle zoo objects. Although ets() is not returning an error, it will be ignoring any seasonality. auto.arima() is failing because it is confused by the zoo object with apparent seasonality. I will try to include better checking in a future version.

When using the forecast package, use ts objects instead. In this example,

x <- ts(x)
auto.arima(x)
ets(x)

That will ignore the frequency component of x. It looks like weekly data, so

x <- ts(x,start=2009+(31+28+31+4)/365,f=52)

will capture the frequency (and start period). However, note that ets() will not handle weekly data and will return an error with this latter formulation.