Description Usage Arguments Author(s) Examples
This is a basic Metropolis algorithm
1 |
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 |
Thibaut Jombart t.jombart@imperial.ac.uk
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.