Errors in optim when fitting arima model in R I'm using the arima method of stats package of R with my time series of 17376 elements. My goal is to get the value of the AIC criterion, I 've observed in my first test this:
 ts <- arima(serie[,1], order = c(2,1,1), seasonal = list(order=c(2,0,1),period = 24), 
         method = "CSS", optim.method = "BFGS",)
> ts$coef
           ar1        ar2        ma1       sar1       sar2       sma1 
     0.8883730 -0.0906352 -0.9697230  1.2047580 -0.2154847 -0.7744656 
    > ts$aic
[1] NA

As you can see, AIC is not defined. About AIC, "Help" in R said that it could only be used with "ML". However, it happens:
> ts <- arima(serie[,1], order = c(2,1,1), seasonal = list(order=c(2,0,1),period = 24), 
          method = "ML", optim.method = "BFGS",)

Error en optim(init[mask], armafn, method = optim.method, hessian = TRUE,  : 
  non-finite finite-difference value [1]

Plus: warning messages lost
In log(s2) : There have been NaNs

I don't understand what is happening. Also I would like to know more about the parameter "fitting method".
 A: Edited: if you down-vote this can you please explain why? I'm new here. 
I'm had the same problem. I looked around online and found a solution suggested elsewhere on Cross Validated. I figured I'd share here in case anyone wanted it. 
I just added a "method="CSS"" to my model and it worked. For example:  
model = Arima(x, order=c(1,1,1), seasonal=list(order=c(1,1,1), period=12), xreg=xreg, 
              method="CSS") 

Here's the reference:
auto.arima and Arima (forecast package)
A: Fitting the ARIMA model with Maximum Likelihood (method = "ML") requires optimising (minimising) the ARIMA model negative log-likelihood over the parameters. This turns out to be a constrained optimisation problem as the parameters must result in a stationary model. This nonlinear constraint is accounted for with the negative log-likelihood returning Inf (infinity) if the the constraint is not satisfied. If the MLE is near the boundary of the constraint evaluation of the negative log-likelihood near the MLE could return infinity. As the hessian is obtained with numerical differentiation by evaluating the negative log-likelihood near the MLE this can result in the non-finite finite difference error you obtained. So if the hessian is not required put hessian = FALSE. Otherwise, this error depends on the MLE solution so an alternative optimisation algorithm (Nelder-Mead) might return an MLE sufficiently far from the boundary of the constrain that the error is avoided.
A: You seem to have problem with algorithms convergence. This happens sometimes with numerical optimization.
Here is link to wikipedia article on this particular optimization method:
http://en.wikipedia.org/wiki/Broyden%E2%80%93Fletcher%E2%80%93Goldfarb%E2%80%93Shanno_algorithm 
