[R-sig-ME] NLMINB() produces NaN!

Ken Beath ken at kjbeath.com.au
Thu May 7 01:31:25 CEST 2009


On Wed, May 6, 2009 6:19 pm, H c wrote:
> I am having the same problem as one Rebecca Sela(see bellow).
>
>
> On 21/12/2007 12:07 AM, Rebecca Sela wrote:
>>* I am trying to optimize a likelihood function using NLMINB.  After
>> running without a problem for quite a few iterations (enough that my
>> intermediate output extends further than I can scroll back), it tries a
>> vector of parameter values NaN.  This has happened with multiple Monte
>> Carlo datasets, and a few different (but very similar) likelihood
>> functions.  (They are complicated, but I can send them to someone if
>> desired.)*
>
> Instead I try to use optim() for my optimization needs but it fails
> when finding the 0/0:
>
> "
>
> Error in optim(c(phi[, k]), maxphi, lower = 0.01, upper = 0.99, method
> = "L-BFGS-B") :
>   L-BFGS-B needs finite values of 'fn'
> In addition: There were 50 or more warnings (use warnings() to see the
> first 50)
>
> "
>
>
> Any suggestions?

I think you have a different problem to the original poster.

It looks like your function cannot be calculated for some values that
optim passes to it. This can easily happen. Some optimisers (eg nlm) seem
to cope with this, but produce lots of annoying warnings. My solution is
to check at the end of the likelihood function for finite or NAN and
replace with the maximum real value. eg

if (is.nan(ll) || is.infinite(ll)) ll <- .Machine$double.xmax

Ken




More information about the R-sig-mixed-models mailing list