Suppose I perform an experiment where the data have a $Poisson(\lambda)$ sampling density. My uncertainty about $\lambda$ using a Gamma prior density with parameters $\alpha$ and $\beta$. I also describe our uncertainty about $\alpha$ and $\beta$ using independent Gamma prior densities.
I'm trying to implement an MCMC algorithm to calculate posterior densities for $\lambda$, $\alpha$, and $\beta$. What is wrong with my code below? I'm getting an acceptance ratio of 0.
obs <- rpois(50, 5)
m <- 100000
x <- matrix(NA, nrow=m, ncol=3)
x[1,] <- c(5, 1, 1)
accept <- 0
sd1 <- 2
sd2 <- 2
sd3 <- 2
post <- function(lambda, alpha, beta) {
prod(dpois(x, lambda))*dgamma(lambda,
alpha,beta)*dgamma(alpha,1,1)*dgamma(beta,1,1)}
for(i in 2:m){
xc <- c(rnorm(2, x[i-1,1]-sd1,x[i-1,1]+sd1),runif(1,x[i-1,2]-sd2,x[i-
1,2]+sd2), runif(1,x[i-1,3]-sd3, x[i-1,3]+sd3))
if (post(xc[1], xc[2], xc[3])/post(x[i-1,1],x[i-1,2], x[i-1,3]) > runif(1)){
x[i,] <- xc; accept <- accept + 1
} else{
x[i,] <- x[i-1,]
}
}
accept/m