[R] a question on R optimization functions

Ben Bolker bbolker at gmail.com
Fri Mar 25 20:23:27 CET 2011


Paul Gilbert <pgilbert <at> bank-banque-canada.ca> writes:

> 
> It seems more likely that the return value from your function 
> is NA or NaN or Inf. This might then result in an
> NA parameter value being calculated for the next step. 
> This is possible, for example,  because the line
> search extends outside the feasible region. You can
>  re-write your function to check for that case and
> return a large negative value (or positive if minimizing),
>  or stop() if that is more appropriate.
> 
> Paul
> 

  But it seems likely that if that happens the optimizer (optim,
nlminb, whatever) would get to a state within the next few steps
where it would stop with an error.

  Ravi suggests 'trace', which is a good idea.  Having this
happen in the middle of batch runs is a nuisance -- it rules
out a lot of the interactive debugging tools -- but you can
also use the old-fashioned, low-tech solution of adding lots
of cat(...,"\n") statements to your objective function to see
what's going on.



More information about the R-help mailing list