Generate a sample from a probability distribution with the Metropolis algorithm.
multivariate.metropolis.sample(target.dist, x0, sample.size, tuning=1)
univar.metropolis.sample(target.dist, x0, sample.size, tuning=1)
A list with elements X
, evals
, and reject.rate
.
See compare.samplers
for more information on X
and
evals
. reject.rate
is the fraction of proposals
not accepted.
Target distribution; see make.dist
.
Numeric vector containing initial state.
Sample size requested.
Proposal standard deviation
These two functions implement variants of the Metropolis algorithm
for sampling a target distribution, following the interface
used by compare.samplers
.
multivariate.metropolis.sample
uses spherically symmetric
Gaussian proposals with marginal standard deviation equal to the
tuning
parameter. univar.metropolis.sample
updates
each coordinate in sequence using univariate Gaussian proposals
with standard deviation equal to the tuning
parameter.
So that these two functions are roughly comparable, with a
\(p\)-dimensional target distribution,
multivariate.metropolis.sample
performs \(p\) accept-reject
steps each time between observations, so that both functions
evaluate the log density a number of times roughly equal to \(p\)
times the sample size. While there are often efficiency optimizations
possible when only one coordinate is updated,
univar.metropolis.sample
does not support these; these two
samplers are included for comparison rather than for practical use.
compare.samplers
,
adaptive.metropolis.sample