[R] optim fails when using arima

Spencer Graves spencer.graves at pdf.com
Fri Aug 1 14:10:39 CEST 2008

<in line> 

> Hi all,
> I´m using the arima() function to study a time series but it gives me 
> the following error:
> Error en optim(init[mask], armafn, method = "BFGS", hessian = TRUE, 
> control = optim.control,  :
>   non-finite finite-difference value [3]
> I know that I can change the method of the arima() to "CSS" instead of 
> "ML" but I'm specially interested in using maximum likelihood.
> I have read that using the Nelder-Mead method in the optim() function 
> could avoid this error but I think that it is not possible to change 
> the method of "optim" from arima().
      The arguments for 'arima' includes 'optim.control', which the 
'arima' help page describes as a "List of control parameters for 
'optim'."  Unfortunately, the following attempt to use this failed: 

arima(lh, order = c(1,0,0), optim.control=list(method="Nelder-Mead"))

Warning messages:  In optim(init[mask], armafn, method = "BFGS", hessian 
= TRUE, control = optim.control,  :
  unknown names in control: method

      If it were my problem, I might start by downloading the source for 
the R "stats" package from CRAN or listing 'arima' and copying it into a 
script file.  A 'search' for "optim" in
the code for 'arima' revealed that it is called in 4 different places.  
I then added the following lines to the start of 'optim' and changed all 
4 calls to 'optim' so they said 'method = optimMtd' instead of 'method = 

      optimMtd <- 'BFGS'
    else {
      optimMtd <- optim.control$method
      optim.control$method <- NULL

      When I tried this, I found that I had to search for "R_" and 
replace it by "stats:::R_" because of object names hidden in the 
"namespace" for the "stats" package.  When I did this, 'optim' ran 
successfully and gave almost identical answers to the default "BFGS" 
'optim' method, differing by one digit on the last decimal place in one 
of the summary numbers from "arima(lh, order = c(1,0,0))". 

      If you try this, please let us know if it solves your problem. 

      Hope this helps. 
      Spencer Graves
> Does anyone have an idea of how could I solve this problem?
> Thanks and regards,
> Maider Mateos
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list