Skip to content

I want to find the best arima model using AIC criterion, but having problems

4 messages · BSanders, Paul Teetor, Matthieu Stigler

#
I'm running a loop for trying to find the best ARIMA seasonal model.  I'm
experimenting with different orders of AR, MA and differencing.., but when I
run my loops, I'm getting an error such as
"Error in optim(init[mask], armafn, method = optim.method, hessian = TRUE, 
: 
  non-finite finite-difference value [3]
"
and R exits the loop, however, it isn't finished.  Is there a way to make R
continuing what it should?

My code looks like this below :

count = 0
for(i in 0:7){
for(j in 0:2) {
for(k in 0:1)  {
for(l in 0:1)   {
for(m in 0:2)    {
for(n in 0:1)  {
for(o in 1:2)   {
model = arima(y, order=c(i,j,k), seasonal=list(order=c(l,m,n), period=7*o))
if (count == 0){
     aicmin = model$aic
     bestmodel = model
     }
if ((count != 0)&& (model$aic < aicmin)){
     aicmin = model$aic
     bestmodel = model
     diff1 = j
     diff2 = m
     seas = o*7
     }

count = count+1
}
}
}
}
}
}
}
print(bestmodel)
print(count)
print(diff1)
print(diff2)
print(seas)
#
HI think too for this purpose auto.arima model might be good.

Concerning your loop, the problem is not in your loop I believe, but 
simply that numerical procedure in arima() does not converge (i have 
seen this problem quite often). You might try using rather method=CSS 
(the usual least square).

Le 17. 01. 11 13:26, Paul Teetor a ?crit :
#
I hadn't used the auto.arima. Thanks for showing me that.  I'm having
troubles with including an xreg variable, and when it does accept the xreg
variable, it won't accept the newxreg for predictions.  

auto.arima isnt' really tailored for handling seasonal models.  I have to
save my data as a time series with frequency 7, but then when I do this, I
can't include xreg, I get the following error : 

Error in attr(x, "tsp") <- value : 
  invalid time series parameters specified



In some ways, I like my own code better if it would just keep plugging
along...