powered by
Implements Metropolis sampling for an arbitrary discrete probability distribution
random_walk(pd, start, num_steps)
function containing discrete probability function on the integers 1, 2, ...
starting value of algorithm
number of iterations of algorithm
A vector of simulated values
# 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