Hi,

I am a biologist and I am trying to get my head around MCMC. I have found enough information to understand MCMC in the Bayesian framework but I cannot find much information on frequentist MCMCs.

What would be the equivalent of the following R code in using ML MCMC?

It is an example I found online and it is not homework.

n is the sample size and the mean of x is 3.508. A random variable X is assumed to be normally distributed where mu is unknown and sigma=0.01. The prior on the mu parameter is represented with a normal distribution with pmu=3.5 and psigma=1.

Thanks in advance.

M

Code:`w = 1000`

mu = 3.508

sigma = 0.01

n = 10

f <- function(theta, mu = 3.508, sigma = 0.01, n = 10){

z <- exp( - n/2/sigma^2 * (theta - mu)^2)}

z

z <- rep(0, n)

p <- rep(0, w+n)

theta <- 3.5

pmu <- 3.5

psigma <- 1

for(i in 1:(w + n)) {

new <- theta + rnorm(1, 0, 0.01)}

prob<-(dnorm(new,pmu,psigma)*f(new)) /(dnorm(theta,pmu,psigma)*f(theta))

alpha <- min(prob, 1)

p[i] <- alpha

if(runif(1) < alpha) theta <- new

if(i > w) z[i - w] <- theta