# Starting out with forecast package in R

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 ...

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

-

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.

-
Thanks Rob. 2 quick things though. I converted by zoo object to ts using as.ts. That didn't seem to do the trick as I got the same error. I then backed all the way up created a new object from the raw CSV, converted to ts using ts(object). Functions ets and auto.arima both found model, but I got an error when trying to plot the fitted auto.arima object (Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ). Thanks again for your help! –  Btibert3 Dec 6 '10 at 14:08
UPDATE. Sorry, for the multiple comments. From the comment above, I didn't add the frequency portion, but that seemed to work for the auto.arima (and subsequently generated a great looking forecast) using the plot as found in your help. You can probably tell I am new to R, but can you tell me why you add 4 in the start for April and not 5? –  Btibert3 Dec 6 '10 at 14:33
Weekly data is trouble anyhow, in my experience. Monthly data can have length-of-month issues and trading-day issues, but at least there are always 12 months in the year. And there are quite a few tools that aren't set up to handle weekly data, so you narrow your options considerably. I switched to monthly and saved myself a lot of grief. –  Wayne Dec 6 '10 at 20:20
You need to drop the frequency component in the zoo object. So as.ts() won't work. There is no plot method for Arima objects. For the start argument, Jan 1 is 2009, so Jan 2 is 2009+1/365, etc. –  Rob Hyndman Dec 6 '10 at 22:08