Description Usage Arguments Value Author(s) Examples
Attempts to create a good proposal distribution for updating a state vector. The function returned implements a multivariate normal proposal distribution with fixed covariance (suitable for use with metropolis), where the covariance is selected based on an initial run of the markov chain. Magic numbers are taken from Matt Schofields lecture notes.
1 2 |
target |
target log-density |
init |
initial value. chosing a good one is probably important. |
sigma |
starting covariance, default is identity matrix |
blocksize |
number of iterations to run between updates of covariance |
nblocks |
number of times the covariance gets updated |
bar |
print progress bar? |
a multivariate proposing function
Grady Weyenberg
1 2 3 4 5 6 7 8 | ## define a multivariate target density
tgt <- function(state)
-mahalanobis(as.vector(state),colMeans(iris[1:4]),var(iris[1:4]))/2
## adapt.normal attempts to create a good proposal distribution
mvn.prop <- adapt.normal(tgt, rep(0,4), nblocks=20)
environment(mvn.prop)$sigma #the proposal covariance
g.ch <- iterate(1000, metropolis(tgt, mvn.prop), rep(0,4))
mean(sapply(g.ch[-1],attr,"accept")) #acceptance rate for mvn.prop
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.