title: ARIMA forecasting with auto.Arima() and xreg
body: <p>I am working on project to forecast sales of stores to learn forecasting.Till now I have successfully used simple auto.Arima() function for forecasting.But to make these forecast more accurate I can make use of covariates.I have defined covariates like holidays, promotion which affect on sales of store using xreg operator with the help of this post: 
  How to setup xreg argument in auto.arima() in R?</p>
  
  <p>But my code fails at line:</p>
  
  <p>ARIMAfit &lt;- auto.arima(saledata, xreg=covariates)</p>
  
  <p>and gives error saying:</p>
  
  <p>Error in model.frame.default(formula = x ~ xreg, drop.unused.levels = TRUE) : variable lengths differ (found for 'xreg') In addition: Warning message: In !is.na(x) &amp; !is.na(rowSums(xreg)) : longer object length is not a multiple of shorter object length</p>
  
  <p>Below is link to my Dataset: <a href="https://drive.google.com/file/d/0B-KJYBgmb044blZGSWhHNEoxaHM/view?usp=sharing" rel="noreferrer">https://drive.google.com/file/d/0B-KJYBgmb044blZGSWhHNEoxaHM/view?usp=sharing</a></p>
  
  <p>This is my code:</p>
  
  <pre><code>data = read.csv("xdata.csv")[1:96,]
  View(data)
  
  saledata &lt;- ts(data[1:96,4],start=1)
  View(saledata)
  
  saledata[saledata == 0] &lt;- 1
  View(saledata)
  
  covariates = cbind(DayOfWeek=model.matrix(~as.factor(data$DayOfWeek)),
                   Customers=data$Customers,
               Open=data$Open,
                   Promo=data$Promo,
               SchoolHoliday=data$SchoolHoliday)
  View(head(covariates))
  
  
  # Remove intercept
  covariates &lt;- covariates[,-1]
  View(covariates)
  
  require(forecast)
  ARIMAfit &lt;- auto.arima(saledata, xreg=covariates)//HERE IS ERROR LINE
  summary(ARIMAfit)
  </code></pre>
  
  <p>Also tell me how I can forecast for next 48 days.I know how to forecast using simple auto.Arima() and n.ahead but dont know how to do it when xreg is used.</p>