[R] Possible bug with MCMCpack metropolis sampler

dcervone dcervone at gmail.com
Sun Aug 5 04:38:45 CEST 2012


Hi,

I'm having issues with what I believe is a bug in the MCMCpack's
MCMCmetrop1R function. I have code that basically looks like this:

posterior.sampler <- function(data, prior.mu){
   log.posterior <- function(theta) log.likelihood(data, theta) +
log.prior(prior.mu, theta)
   post.samples <- MCMCmetrop1R(log.posterior, theta.init=prior.mu,
burnin=100, mcmc=1000, thin=40, tune=1, verbose=0, logfun=T,
optim.method="BFGS")
   return(post.samples)
}

x <- c(1,1,1)
posterior.sampler(mydata, x)

After calling posterior.sampler, the value for x is different from what I
started with. Perhaps even more interesting, is that if I create a copy of
x, say x2, before running posterior.sampler, x2 is modified as well. And I
have checked that calling log.posterior is not what alters the value of x,
so that leads me to believe it must be MCMCmetrop1R. Also, if I use
"theta.init = c(1,1,1)" instead of "theta.init = prior.mu" then x is not
altered. All of the behavior I described persists if I just run the
MCMCmetorp1R call (with the variables renamed of course) on its own and not
as part of my posterior.sampler function.

Any idea what's going on?

Thanks,
Dan Cervone



--
View this message in context: http://r.789695.n4.nabble.com/Possible-bug-with-MCMCpack-metropolis-sampler-tp4639199.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list