Error with neg_binomial_2_log_rng

393 views
Skip to first unread message

Christopher Peterson

unread,
Feb 22, 2016, 11:10:48 AM2/22/16
to Stan users mailing list

I've been having a problem with generating negative binomial samples in a model I've been working on.

Error : Exception thrown at line 195: stan::math::neg_binomial_2_log_rng: Random number that came from gamma distribution is 4.37454e+33, but must be less than 1.07374e+09"
error occurred during calling the sampler; sampling not done

This particular error frequently arises with initialization; I can work around that by changing the seed in rstan.  However, I recently encountered it again right after the model finished warmup.  Could someone with a better understanding of stan's internals explain to me what may be causing this (e.g., whether it's the mu or phi parameters that are getting too large?).  I imagine the phi is to blame.

Currently, the reciprocal of phi has a folded cauchy prior; the intention behind this is shrink the negative binomial overdispersion towards that of a Poisson.  Is this causing the problem?  The code is rather long and complex, but I can attempt to make a simpler version of necessary.

Would it be easier to just cut this part of the code and do the PP check in R post-hoc, where I can manually deal with exceptions?

Bob Carpenter

unread,
Feb 22, 2016, 4:06:58 PM2/22/16
to stan-...@googlegroups.com
The problem is going to arise when you try to generate a RNG
that will overflow the integer sizes (the max allowable value is
roughly 2^31). You can modify the code to catch cases where
the parameters give some chance of overflowing and just return -1
there in the generated quantities block. I'll make a note of
that in the manual, but it's going to be buried so deep nobody's
likely to see it:

https://github.com/stan-dev/stan/issues/1709#issuecomment-187382422

You didn't send enough of your program (ideally send ***all*** of
it) for us to diagnose what the root cause is. But the answer is
probably that you want more reasonable priors and/or inits. Or
you want to guard against the problem with a conditional in the
generated quantities.

If you're generating int variates on the scale of 2^31, you
probably have bigger problems. At that point, normal approximations
are pretty darn good.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages