Re: [R] a question on R optimization functions

From: Ben Bolker <>
Date: Fri, 25 Mar 2011 12:08:45 +0000

Dajiang J. Liu <dajiang.liu <at>> writes:

> I use nlminb or optim for maximizing likelihood functions. Sometimes,
> the parameter values happen to be NA, then the program will hang there
> and iterate forever without stopping. No error message will be
> produced. So I can not use error catch method such as "try". Are there
> any suggestions how I can circumvent this problem? Maybe I can time a
> function, and if the time exceeds a threshold, it will be stopped. I
> am not sure if this is feasible in R. As a note, I am running
> simulations with thousands of replicates, so there needs to be a
> systematic way of doing this. Are there any suggestions on how to do
> this? Thank you very much!

   It would be very surprising (I suppose not impossible, but *very* surprising) if this behavior were generated by R's optimization functions; it would be much more likely for it to be an infinite loop/hang somewhere inside your objective function.

  See ?setTimeLimit (which will fail if the problem is inside C code that you have written ...)

  Ben Bolker mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 25 Mar 2011 - 12:12:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 25 Mar 2011 - 15:40:25 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive