mh {hacks}R Documentation

Metropolis Hastings Algorithm

Description

Computes random variables from an unnormalized distribution using the Metropolis Hastings algorithm.

Usage

mh(FUN, n = 10000, mean = 0, sd = 1)

Arguments

FUN a function desribing the unnormalized distribution.
n the number of iterations to perform.
mean The initial value for computing the random variables. This is the mean of the proposal distribution.
sd The standard deviation of the proposal distribution.

Details

This implementation of the Metropolis Hastings algorithm uses the normal distribution for the prosal distribution.

Author(s)

Nathan Stephens

Examples

set.seed(2037)
f <- function(x) 0.1*((1+(x-10)^2)/3)^-2
x <- mh(f)
par(mfrow=c(2,1))
plot(density(x), main = 'Normalized Distribution')
plot(x,type='l', main = 'Sampled Values')

[Package hacks version 0.1-9 Index]