R/metrop.R

metrop <- function (n, alpha) 
{
  vec=vector("numeric", n)
  x=0
  vec[1]=x
  for (i in 2:n) {
    can=x+runif(1, -alpha, alpha)
    aprob=dnorm(can)/dnorm(x)
    u=runif(1)
    if (u < aprob) 
      x=can
    vec[i]=x
  }
  vec
}


# eof

Try the smfsb package in your browser

Any scripts or data that you put into this service are public.

smfsb documentation built on Jan. 13, 2024, 3:02 a.m.