Mhstep = function(bold,lupold,v,w,t,x) { # takes a Metropolis-Hastings step for the log-linear Poisson model # with one covariate, a Gaussian prior, and a Gaussian random walk # proposal # INPUTS: # bold = 2-vector of old value # lupold = scalar of log unnormed post at bold # v = 2-vector of prior variances # w = 2-vector of variances for metropolis-hastings steps # t = suff stat # x = n-vector of predictors # OUTPUTS: # bnew = 2-vector of new values # lupnew = scalar of log unnormed post at bnew bnew = bold + rnorm(2,0,sqrt(w)) lupnew = Lup(bnew,v,t,x) dlup = lupnew - lupold if(dlup<0) { alpha = exp(dlup) if(runif(1) > alpha) { bnew = bold lupnew = lupold } } mhout = list(bnew=bnew,lupnew=lupnew) return(mhout) }