**A**n interesting question (with no clear motivation) on X validated wondering why a Gibbs sampler produces NAs… Interesting because multi-layered:

- The attached R code indeed produces NAs because it calls the Negative Binomial Neg(x¹,p) random generator with a zero success parameter, x¹=0, which automatically returns NAs. This can be escaped by returning a one (1) instead.
- The Gibbs sampler is based on a Bin(x²,p) conditional for X¹ and a Neg(x¹,p) conditional for X². When using the most standard version of the Negative Binomial random variate as the number of failures, hence supported on 0,1,2…. these two conditionals are incompatible, i.e., there cannot be a joint distribution behind, which makes the limiting behaviour of the Markov chain harder to study. It however seems to converge to a distribution close to zero.
- When using the less standard version of the Negative Binomial random variate as the number of attempts for the conditional on X², the two conditionals are compatible and correspond to a joint proportional to
, however this pmf does not sum up to a finite quantity, hence the resulting Markov chain is at best null recurrent, which seems to be the case for p different from ½. This is unclear for p=½.

*Related*

To

**leave a comment**for the author, please follow the link and comment on their blog:**R – Xi’an’s Og**.R-bloggers.com offers **daily e-mail updates** about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more…