I have the following full conditionals distributions: $$ X_2|X_1=x_1\sim Bin(x_1,p)\\ X_1|X_2=x_2\sim NegBin(x_2,p) $$ So I'm using the following code to generate a sample from each one:
Gibbs2 <- function(x1,x2,p,niter){
lambda = matrix(0, nrow=niter)
betax= matrix(0, nrow=niter)
lambda[1]= x1
betax[1]= x2
for (i in 2:niter) {
lambda[i]= rbinom(1, betax[i-1],p)
betax[i]= rnbinom(1, lambda[i],p)
}
return(theta = list(lambda=lambda,betax=betax))
Using the function returns the following:
> cadenas2<-Gibbs2(20,40,0.5,100)
There were 50 or more warnings (use warnings() to see the first 50)
But when I change the function to both distributions being binomial, so using rbinom for both cases, then it works. Does anyone know what's wrong with my code? Why does rnbinom produce such error?