| MetropolisHastings {EMC} | R Documentation |
Given a target density function and an asymmetric proposal distribution, this function produces samples from the target using the Metropolis Hastings algorithm.
Below sampDim refers to the dimension of the sample space.
MetropolisHastings(nIters,
startingVal,
logTarDensFunc,
propNewFunc,
logPropDensFunc,
MHBlocks = NULL,
MHBlockNTimes = NULL,
nThin = 1,
saveFitness = FALSE,
verboseLevel = 0,
...)
nIters |
|
startingVal |
|
logTarDensFunc |
|
propNewFunc |
|
logPropDensFunc |
|
MHBlocks |
|
MHBlockNTimes |
|
nThin |
|
saveFitness |
|
verboseLevel |
|
... |
optional arguments to be passed to |
propNewFunc and logPropDensFuncThe
propNewFunc and the logPropDensFunc are called
multiple times by varying the block argument over
1:length(MHBlocks), so these functions should know how to
generate a proposal from the currentDraw or to evaluate the
proposal density depending on which block was passed as the
argument. See the example section for sample code.
MHBlocks and MHBlockNTimesBlocking is an
important and useful tool in MCMC that helps speed up sampling and
hence mixing. Example: Let sampDim = 6. Let we want to
sample dimensions 1, 2, 4 as one block, dimensions 3 and 5 as
another and treat dimension 6 as the third block. Suppose we want
to sample the three blocks mentioned above 1, 5 and 10 times in
each iteration, respectively. Then we could set MHBlocks =
list(c(1, 2, 4), c(3, 5), 6) and MHBlockNTimes = c(1, 5,
10)
saveFitnessThe term fitness refers to the
negative of the logTarDensFunc values. By default, the
fitness values are not saved, but one can do so by setting
saveFitness = TRUE.
Below nSave refers to ceil(nIters / nThin). This
function returns a list with the following components:
draws |
|
acceptRatios |
|
detailedAcceptRatios |
|
nIters |
the |
nThin |
the |
nSave |
as defined above. |
startingVal |
the |
time |
the time taken by the run. |
The effect of leaving the default value NULL for some of the
arguments above are as follows:
MHBlocks
| as.list(1:sampDim).
|
MHBlockNTimes
| rep(1, length(MHBlocks)).
|
Gopi Goswami goswami@stat.harvard.edu
Jun S. Liu (2001). Monte Carlo strategies for scientific computing. Springer.
randomWalkMetropolis,
parallelTempering, evolMonteCarlo
## Not run:
samplerObj <-
with(CigarShapedFuncGenerator2(-13579),
MetropolisHastings(nIters = 5000,
startingVal = c(0, 0),
logTarDensFunc = logTarDensFunc,
propNewFunc = propNewFunc,
logPropDensFunc = logPropDensFunc,
verboseLevel = 2))
print(samplerObj)
print(names(samplerObj))
with(samplerObj,
{
print(detailedAcceptRatios)
print(dim(draws))
plot(draws,
xlim = c(-3, 5),
ylim = c(-3, 4),
pch = '.',
ask = FALSE,
main = as.expression(paste('# draws:', nIters)),
xlab = as.expression(substitute(x[xii], list(xii = 1))),
ylab = as.expression(substitute(x[xii], list(xii = 2))))
})
## End(Not run)