[R] How to avoid the NaN errors in dnbinom?
francogrex at mail.com
Wed Oct 24 12:33:25 CEST 2007
Thanks Jim, I corrected the error by avoiding negative K values:
I am not sure about the general code to determine the parameters though,
sometimes it gives the expected values (determined in advance by rnbinom)
and sometimes it's way off.
> Your problems is that your code is generating NaN and 'err' is set to
> NaN and therefore the 'while (err > eps)' fails since NaN is not a
> logical variable.
> You should learn to use debug or the browser. I put the following
> statement in your code:
> if (is.nan(err)) browser() # added statement
> that caught the error and the printed out the values of some of your
> Called from: mixnbinom(y, 10, 7, 20, 12, 0.8)
> Browse> old.parms
>  8.233552e+00 5.225557e+00 -2.487524e+05 1.512247e+01 9.668136e-01
> Warning message:
> In dnbinom(x, size, prob, log) : NaNs produced
> Browse> new.parms
>  NaN NaN NaN NaN NaN
> This shows that 'new.parms' at that point was all NaN. You need to
> check your logic since is does say that "In dnbinom(x, size, prob,
> log) : NaNs produced".
View this message in context: http://www.nabble.com/How-to-avoid-the-NaN-errors-in-dnbinom--tf4680211.html#a13383142
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help