## The Cigar-shaped distribution with (symmetric) normal-proposal
CigarShapedFuncGenerator1 <-
function (seed = 13579)
{
set.seed(seed)
dd <- 2
ARDisp <-
function (rho)
{
tmp <- rep(1, dd)
diag((1 - rho) * tmp) + rho * tmp %*% t(tmp)
}
means <- c(1, 1)
disp <- ARDisp(-0.95)
logTarDensFunc <-
function (draw, ...)
dmvnorm(draw, means, disp, log = TRUE)
proposalSD <- c(1, 2)
propNewFunc <-
function (block, currentDraw, ...)
{
proposalDraw <- currentDraw
proposalDraw[block] <- rnorm(1, currentDraw[block], proposalSD[block])
proposalDraw
}
list(logTarDensFunc = logTarDensFunc,
propNewFunc = propNewFunc)
}
samplerObj <-
with(CigarShapedFuncGenerator1( ),
randomWalkMetropolis(nIters = 5000,
startingVal = c(0, 0),
logTarDensFunc = logTarDensFunc,
propNewFunc = propNewFunc,
verboseLevel = 1))
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))))
})Run the code above in your browser using DataLab