## The Cigar-shaped distribution with independent t-proposal
CigarShapedFuncGenerator2 <-
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)
tDF <- 3
propNewFunc <-
function (block, currentDraw, ...)
{
proposalDraw <- currentDraw
proposalDraw[block] <- rt(1, tDF)
proposalDraw
}
logPropDensFunc <-
function (block, currentDraw, proposalDraw, ...)
dt(proposalDraw[block], tDF, log = TRUE)
list(logTarDensFunc = logTarDensFunc,
propNewFunc = propNewFunc,
logPropDensFunc = logPropDensFunc)
}
samplerObj <-
with(CigarShapedFuncGenerator2( ),
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))))
})Run the code above in your browser using DataLab