Learn R Programming

ProbBayes (version 1.1)

random_walk: Metropolis sampling of a discrete distribution

Description

Implements Metropolis sampling for an arbitrary discrete probability distribution

Usage

random_walk(pd, start, num_steps)

Arguments

pd

function containing discrete probability function on the integers 1, 2, ...

start

starting value of algorithm

num_steps

number of iterations of algorithm

Value

A vector of simulated values

Examples

Run this code
# NOT RUN {
# random walk through a binomial distribution
pd <- function(x){
  dbinom(x, size = 10, prob = 0.5)
}
start <- 4
num_steps <- 50
out <- random_walk(pd, start, num_steps)
# }

Run the code above in your browser using DataLab