demoMCMC {IPMbook} | R Documentation |
Demonstration of a random-walk sampler for a single parameter
Description
Generates an MCMC chain for the probability of success on the logit scale, ltheta = logit(theta)
, for binomial data with y successes in N trials. The prior for ltheta
is a Normal distribution with mean mu.ltheta
and SD sd.ltheta
. Proposal values are drawn from a Normal distribution with mean = current value and SD = prop.sd.
Usage
demoMCMC(y = 20, N = 50, niter = 25000, mu.ltheta = 0, sd.ltheta = 100,
prop.sd = 1, init = 0, quiet = FALSE, show.plots = TRUE)
Arguments
y |
number of successes. |
N |
number of trials. |
niter |
the number of MCMC draws required. |
mu.ltheta |
the mean of the Normal prior distribution for logit(theta). |
sd.ltheta |
the SD of the Normal prior distribution for logit(theta). |
prop.sd |
the SD of the Normal distribution for the proposals. |
init |
initial value for logit(theta). |
quiet |
if TRUE, console output is suppressed. |
show.plots |
if FALSE, plotting is suppressed. |
Value
A list with the values of the input arguments and the following additional elements:
ltheta |
a vector with the MCMC draws. |
acc.prob |
the proportion of proposed values accepted. |
Author(s)
Adapted from code in Ntzoufras (2009), p. 48.
References
Ntzoufras, I. (2009) Bayesian Modeling Using WinBUGS, Wiley, Hoboken NJ.
Schaub, M., Kéry, M. (2022), Integrated Population Models, Academic Press, section 2.5.
Examples
require(graphics)
# Default settings
str(tmp <- demoMCMC(y = 20, N = 50, niter = 25000,
mu.ltheta = 0, sd.ltheta = 100, prop.sd = 1, init = 0))
# Show convergence
str(tmp <- demoMCMC(prop.sd = 0.1, init = 10))
# Show convergence: no convergence
str(tmp <- demoMCMC(prop.sd = 0.1, init = 100))
# Very, very small step size: very inefficient
str(tmp <- demoMCMC(prop.sd = 0.01))
# Very small step size: inefficient
str(tmp <- demoMCMC(prop.sd = 0.1))
# Default step size: pretty good for this case
str(tmp <- demoMCMC(prop.sd = 1))
# Larger than default step size: efficiency goes down again
str(tmp <- demoMCMC(prop.sd = 10))
# Muuuuch larger ..... brrrrr !
str(tmp <- demoMCMC(prop.sd = 100))