# Error in optim - Auto.arima R

I am new to R and forecasting .I have data for a certain product. It contains value sales and its promotions. The data is weekly and there are about 104 data points.

I converted the sales into a ts object and created seasonaldummy's to capture seasonality.

actual_val = ts(sku1$Sal , frequency = 52) dummy_val = seasonaldummy(actual_val)  The dummy's were later combined with the promo variables to create external regressors xreg_val for the model. Those promotions which were not held for this sku were removed before combining the two. model_value <- try(auto.arima(actual_val , xreg = xreg_val ) , silent = TRUE)  I have received the following error Error in optim(init[mask], armaCSS, method = optim.method, hessian = FALSE, non-finite value supplied by optim  I could not understand where exactly I have gone wrong in this. Attaching a sample of the data. Kindly help me with this https://drive.google.com/file/d/0B6sOv1da0JMeb01XYW92UzRSZ0U/view?usp=sharing • There is no SALES column in your csv file. – user81847 Nov 11 '15 at 9:03 • There is a column named 'Sal' which is Sales – Abhishek Shetty Nov 11 '15 at 9:19 ## 1 Answer The following works in the sense that it returns a valid model: library(forecast) sku1 <- read.csv("Sample.csv") actual_val = ts(sku1$Sal , frequency = 52)
dummy_val = seasonaldummy(actual_val)
model_value <- auto.arima(actual_val , xreg = dummy_val )


Perhaps your problem is that you haven't defined xreg_val.

However, it isn't a sensible model as you use 51 degrees of freedom for seasonality but have only two years of daily data. I suggest you use Fourier terms instead:

seas <- fourier(actual_val, K=10)
model_value <- auto.arima(actual_val , xreg = seas , lambda=0)
plot(forecast(model_value, xreg=fourierf(actual_val, h=52, K=10), lambda=0))

• Thanks Prof Hyndman. How do I decide what value of K to use for fourier terms? Is there a formal way or code of arriving at a suitable value of K? – Abhishek Shetty Nov 13 '15 at 9:11
• Minimize the AIC – Rob Hyndman Nov 13 '15 at 23:10