The source's function name suggests a log return value, and (c)(i) asks for , while the wording here and in (c)(iv) asks for the acceptance probability. We use the literal probability-returning convention and explicitly exponentiate the result of (c)(i):
mylogapp <- function(x, u, v, sigma_inv) {
  d <- v - u
  log_ratio <- as.numeric(crossprod(d, sigma_inv %*% (x - (u + v) / 2)))
  log_alpha <- min(0, log_ratio)
  exp(log_alpha)
}
Thus mylogapp returns , and (c)(iv) compares it directly with a uniform distribution draw. Taking the minimum before exponentiating prevents overflow. The arguments are assumed to be valid neighbouring states. A log-returning convention would instead return log_alpha and compare log(runif(1)) with it; the two conventions implement the same Metropolis–Hastings algorithm, provided the caller uses the matching comparison.

Articles by others on the same topic (0)

There are currently no matching articles.