Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Metropolis-hastings in R

  1. Mar 5, 2012 #1
    Hi everyone I'm in my final year of university and doing a project on MCMC mainly for applications to bayesian statistics, I think I understand the concept of it so far however I'm struggling to actually make examples.

    I'm trying to model Poisson(2) with a random walk metropolis hastings algorithm in R but really don't know where to even start as I've never used R and just confusing myself.

    Code (Text):
    theta <- 0
    alpha<-function(theta,phi) min(lik(phi)/lik(theta),1)
    b<-runif(1, min=0, max=1)
    for(i in 1: 100)

        if( alpha(theta,phi) < b)
        theta = c(theta, theta.star)
    I know this is wrong but I don't think I'm too far off, could anyone point me in the right direction? :)

    Last edited: Mar 5, 2012
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted