简体   繁体   中英

R auto.arima error

I am new to R and have using auto.arima function with xreg . I found a code on the net and tried to replicate for my data. However, I am getting the following error messages:

Error in optim(init[mask], armaCSS, method = optim.method, hessian = FALSE,  : 
  non-finite value supplied by optim

Error in if (diffs == 1 & constant) { : argument is of length zero
In addition: Warning message:
In auto.arima(salesTS, xreg = xreg1) : Unable to calculate AIC offset

My code is as follows:

data <- read.csv("C:/Users/s.karkala.rao/Documents/Projects/ad-hoc/Hitesh/forARIMAX.csv", header=TRUE, stringsAsFactors=TRUE)
subdata <- subset(data, data$NG.code == "101451")
subdata <- subdata[, -1]
salesTS <- ts(subdata$Sales.Qty, frequency=7)
xreg1 <- subdata[,-1]
xreg1 <- xreg1[, -10]
xreg1 <- as.matrix(xreg1)
model <- auto.arima(salesTS, xreg=xreg1)

I have read some of the answers on the similar queries, but couldn't figure out the solution for my code. Please help.

One possible cause for this error is that your regressors are not linearly independent. Linear independence of regressors (aka full rank of the regression matrix) is typically required for regression procedures.

Examples of violating this assumption:

  1. Including a variable X and a constant multiple aX in your model.
  2. Including a column of all zeroes in your model. This is a special case of (1), where a=0.

If you don't want to check independence manually, you can use the rankMatrix function in the "Matrix" package. If your regressors are linearly independent, your matrix will have "full rank", meaning rank equal to the number of columns.

That is, the result of rankMatrix(xreg) should equal ncol(xreg) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM