Posterior predictive samples in R using a negative binomial model fitted with Stan

Hi
I’v fitted a neg binom model using Stan’s function neg_binomial_2_lpmf(y | mu, phi). phi is the precision. Now I would like to create posterior predictive samples in R using rnbinom(n, size, prob, mu). It seems clear that the mu from neg_binomial_2_lpmf is the same as for rnbinom. Then, I guess I provide size, the “dispersion parameter” according to the rnbinom help file. But how is the link between the precision phi and the dispersion parameter size? The help file says “The variance is mu + mu^2/size”. I can solve variance = mu+mu^2/size = 1/precision = 1/phi for size, but then I get negative values for size, hence something is wrong here. Is phi simply 1/size?
many thanks, Pius

Nooo! You would like to create posterior predictive samples in a generated quantities block in Stan! Switching between probability distributions like this is error prone anyway. You can avoid that with generated quantities!

I got \phi = n which agrees with you. \phi is required to be positive in Stan and n is required to be positive in R, so where does the negative size come from?