Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

MCbinomialbeta

Monte Carlo Simulation from a Binomial Likelihood with a Beta Prior


Description

This function generates a sample from the posterior distribution of a binomial likelihood with a Beta prior.

Usage

MCbinomialbeta(y, n, alpha = 1, beta = 1, mc = 1000, ...)

Arguments

y

The number of successes in the independent Bernoulli trials.

n

The number of independent Bernoulli trials.

alpha

Beta prior distribution alpha parameter.

beta

Beta prior distribution beta parameter.

mc

The number of Monte Carlo draws to make.

...

further arguments to be passed

Details

MCbinomialbeta directly simulates from the posterior distribution. This model is designed primarily for instructional use. π is the probability of success for each independent Bernoulli trial. We assume a conjugate Beta prior:

π \sim \mathcal{B}eta(α, β)

y is the number of successes in n trials. By default, a uniform prior is used.

Value

An mcmc object that contains the posterior sample. This object can be summarized by functions provided by the coda package.

See Also

Examples

## Not run: 
posterior <- MCbinomialbeta(3,12,mc=5000)
summary(posterior)
plot(posterior)
grid <- seq(0,1,0.01)
plot(grid, dbeta(grid, 1, 1), type="l", col="red", lwd=3, ylim=c(0,3.6),
  xlab="pi", ylab="density")
lines(density(posterior), col="blue", lwd=3)
legend(.75, 3.6, c("prior", "posterior"), lwd=3, col=c("red", "blue"))

## End(Not run)

MCMCpack

Markov Chain Monte Carlo (MCMC) Package

v1.5-0
GPL-3
Authors
Andrew D. Martin [aut], Kevin M. Quinn [aut], Jong Hee Park [aut,cre], Ghislain Vieilledent [ctb], Michael Malecki[ctb], Matthew Blackwell [ctb], Keith Poole [ctb], Craig Reed [ctb], Ben Goodrich [ctb], Ross Ihaka [cph], The R Development Core Team [cph], The R Foundation [cph], Pierre L'Ecuyer [cph], Makoto Matsumoto [cph], Takuji Nishimura [cph]
Initial release
2021-01-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.