binomixp {Bolstad} | R Documentation |
Binomial sampling with a beta mixture prior
Description
Evaluates and plots the posterior density for \pi
, the probability
of a success in a Bernoulli trial, with binomial sampling when the prior
density for \pi
is a mixture of two beta distributions,
beta(a_0,b_0)
and beta(a_1,b_1)
.
Usage
binomixp(x, n, alpha0 = c(1, 1), alpha1 = c(1, 1), p = 0.5, ...)
Arguments
x |
the number of observed successes in the binomial experiment. |
n |
the number of trials in the binomial experiment. |
alpha0 |
a vector of length two containing the parameters,
|
alpha1 |
a vector of length two containing the parameters,
|
p |
The prior mixing proportion for the two component beta priors. That
is the prior is |
... |
additional arguments that are passed to |
Value
A list will be returned with the following components:
pi |
the
values of |
posterior |
the posterior density of |
likelihood |
the likelihood function for |
prior |
the prior density of |
See Also
Examples
## simplest call with 6 successes observed in 8 trials and a 50:50 mix
## of two beta(1,1) uniform priors
binomixp(6,8)
## 6 successes observed in 8 trials and a 20:80 mix of a non-uniform
## beta(0.5,6) prior and a uniform beta(1,1) prior
binomixp(6,8,alpha0=c(0.5,6),alpha1=c(1,1),p=0.2)
## 4 successes observed in 12 trials with a 90:10 non uniform beta(3,3) prior
## and a non uniform beta(4,12).
## Plot the stored prior, likelihood and posterior
results = binomixp(4, 12, c(3, 3), c(4, 12), 0.9)$mix
par(mfrow = c(3,1))
y.lims = c(0, 1.1 * max(results$posterior, results$prior))
plot(results$pi,results$prior,ylim=y.lims,type='l'
,xlab=expression(pi),ylab='Density',main='Prior')
polygon(results$pi,results$prior,col='red')
plot(results$pi,results$likelihood,type='l',
xlab = expression(pi), ylab = 'Density', main = 'Likelihood')
polygon(results$pi,results$likelihood,col='green')
plot(results$pi,results$posterior,ylim=y.lims,type='l'
,xlab=expression(pi),ylab='Density',main='Posterior')
polygon(results$pi,results$posterior,col='blue')