mu.true<-0.5 nu2.true<-0.5 N<-50 loglambda<-mu.true+rnorm(N,0,nu2.true) lambda<-exp(loglambda) x<-rpois(N,lambda) print(mean(x)) print(var(x)) plot(x) plot(density(x)) mu<-log(mean(x)) eps<-rep(0,N) nu2<-1 rw.var<-1 sumx<-sum(x) tau2<-1000 mu.save<-nu2.save<-eps.save<-NULL mu.save2<-nu2.save2<-eps.save2<-NULL for (i in 1:100) { mu.star<-rnorm(1,mu,rw.var) logalpha<-sumx*mu.star-sum(exp(mu.star+eps))-mu.star*mu.star/tau2/2 logalpha<-logalpha-sumx*mu+sum(exp(mu+eps))+mu*mu/tau2/2 alpha<-exp(logalpha) if (runif(1)