binobp {Bolstad} | R Documentation |
Binomial sampling with a beta prior
Description
Evaluates and plots the posterior density for pi, the probability of a success in a Bernoulli trial, with binomial sampling and a continous beta(a,b) prior.
Usage
binobp(x, n, a = 1, b = 1, ret = FALSE)
Arguments
x |
the number of observed successes in the binomial experiment. |
n |
the number of trials in the binomial experiment. |
a |
parameter for the beta prior - must be greater than zero |
b |
parameter for the beta prior - must be greater than zero |
ret |
this argument is deprecated. |
Value
A list will be returned with the following components:
posterior |
the posterior density of pi given x
and n - i.e. the beta(a+x,b+n-x) density |
likelihood |
the likelihood of x given pi and
n, i.e. the binomial(n,pi) density |
prior |
the prior density of pi, i.e. the
beta(a,b) density |
pi |
the values of pi for which the posterior density was evaluated |
mean |
the posterior mean |
var |
the posterior variance |
sd |
the posterior std. deviation |
quantiles |
a set of quantiles from the posterior |
See Also
binodp
binogcp
Examples
## simplest call with 6 successes observed in 8 trials and a beta(1,1) uniform
## prior
binobp(6,8)
## 6 successes observed in 8 trials and a non-uniform beta(0.5,6) prior
binobp(6,8,0.5,6)
## 4 successes observed in 12 trials with a non uniform beta(3,3) prior
## plot the stored prior, likelihood and posterior
results = binobp(4,12,3,3)
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,ylim=c(0,0.25),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")
[Package
Bolstad version 0.2-17
Index]