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


  • $\begingroup$ There is no SALES column in your csv file. $\endgroup$ – user81847 Nov 11 '15 at 9:03
  • $\begingroup$ There is a column named 'Sal' which is Sales $\endgroup$ – Abhishek Shetty Nov 11 '15 at 9:19

The following works in the sense that it returns a valid model:

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))
| cite | improve this answer | |
  • $\begingroup$ 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? $\endgroup$ – Abhishek Shetty Nov 13 '15 at 9:11
  • $\begingroup$ Minimize the AIC $\endgroup$ – Rob Hyndman Nov 13 '15 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.