Learn R Programming

ProbBayes (version 1.1)

metropolis: Metropolis sampling of a continuous distribution

Description

Implements Metropolis sampling for an arbitrary continuous probability distribution

Usage

metropolis(logpost, current, C, iter, ...)

Arguments

logpost

function definition of the log probability function

current

starting value of algorithm

C

half-width of proposal interval

iter

number of iterations

...

other inputs needed in logpost function

Value

S

vector of simulated values

accept_rate

acceptance rate of algorithm

Examples

Run this code
# NOT RUN {
lpost <- function(theta, s){
  dnorm(s$ybar, theta, s$se, log = TRUE) +
    dcauchy(theta, s$loc, s$scale, log = TRUE)
}
s <- list(ybar = 20,
          se = 0.4,
          loc = 10,
          scale = 2)
post <- metropolis(lpost, 10, 20, 100, s)
# }

Run the code above in your browser using DataLab