metro: Basic Metropolis algorithm

Description Usage Arguments Author(s) Examples

Description

This is a basic Metropolis algorithm

Usage

1
metro(f, param = list(x = 0), to.move = TRUE, n = 10000, sd = 1)

Arguments

f

a function computing log-densities

param

a list of named parameters passed on to 'f'; parameters must be given their initial values

to.move

a logical or an integer vector indicating which parts of 'param' should be moved in the MCMC

n

a number of iterations for the MCMC

sd

the standard deviation of the proposal normal distribution

Author(s)

Thibaut Jombart t.jombart@imperial.ac.uk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## try with a basic normal density
f1 <- function(x){dnorm(x, log=TRUE)}
mc1 <- metro(f1)
head(mc1)
tail(mc1)
plot(mc1)

## change initial point
mc2 <- metro(f1, list(x=-10))
plot(mc2)

## try with a mixture of densities
fmix <- function(x){log(dnorm(x, mean=-3)+dnorm(x, mean=1, sd=.5))}
mc3 <- metro(fmix, list(x=0))
plot(mc3)

## try harder example
fmix2 <- function(x){log(dnorm(x, mean=-5)+dnorm(x, mean=5, sd=.5))}
mc4 <- metro(fmix2, list(x=0), sd=3, n=1e4)
plot(mc4)

thibautjombart/fancysamplers documentation built on May 31, 2019, 9:56 a.m.