demoMCMC | R Documentation |
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.
demoMCMC(y = 20, N = 50, niter = 25000, mu.ltheta = 0, sd.ltheta = 100,
prop.sd = 1, init = 0, quiet = FALSE, show.plots = TRUE)
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. |
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. |
Adapted from code in Ntzoufras (2009), p. 48.
Ntzoufras, I. (2009) Bayesian Modeling Using WinBUGS, Wiley, Hoboken NJ.
Schaub, M., Kéry, M. (2022), Integrated Population Models, Academic Press, section 2.5.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.