11
\title{The Beta-Binomial Distribution}
13
Density, distribution function, and random
14
generation for the beta-binomial distribution.
18
dbetabin(x, size, prob, rho, log = FALSE)
19
pbetabin(q, size, prob, rho, log.p = FALSE)
20
rbetabin(n, size, prob, rho)
21
dbetabin.ab(x, size, shape1, shape2, log = FALSE)
22
pbetabin.ab(q, size, shape1, shape2, log.p = FALSE)
23
rbetabin.ab(n, size, shape1, shape2)
26
\item{x, q}{vector of quantiles.}
27
% \item{p}{vector of probabilities.}
28
\item{size}{number of trials.}
29
\item{n}{number of observations.
30
Must be a positive integer of length 1.}
32
the probability of success \eqn{\mu}{mu}.
33
Must be in the unit open interval \eqn{(0,1)}.
37
the correlation parameter \eqn{\rho}{rho}.
38
Must be in the unit open interval \eqn{(0,1)}.
41
\item{shape1, shape2}{
42
the two (positive) shape parameters of the standard
43
beta distribution. They are called \code{a} and \code{b} in
44
\code{\link[base:Special]{beta}} respectively.
49
If \code{TRUE} then all probabilities \code{p} are given as \code{log(p)}.
54
\code{dbetabin} and \code{dbetabin.ab} give the density,
55
\code{pbetabin} and \code{pbetabin.ab} give the distribution function, and
56
% \code{qbetabin} and \code{qbetabin.ab} gives the quantile function, and
57
\code{rbetabin} and \code{rbetabin.ab} generate random deviates.
62
The beta-binomial distribution is a binomial distribution whose
63
probability of success is not a constant but it is generated from a
64
beta distribution with parameters \code{shape1} and \code{shape2}.
65
Note that the mean of this beta distribution is
66
\code{mu = shape1/(shape1+shape2)}, which therefore is the
67
mean or the probability of success.
69
See \code{\link{betabinomial}} and \code{\link{betabin.ab}},
70
the \pkg{VGAM} family functions for
71
estimating the parameters, for the formula of the probability density
72
function and other details.
76
\code{pbetabin} and \code{pbetabin.ab} can be particularly slow.
77
The functions here ending in \code{.ab} are called from those
78
functions which don't.
79
The simple transformations
80
\eqn{\mu=\alpha / (\alpha + \beta)}{mu=alpha/(alpha+beta)} and
81
\eqn{\rho=1/(1 + \alpha + \beta)}{rho=1/(1+alpha+beta)} are used,
82
where \eqn{\alpha}{alpha} and \eqn{\beta}{beta} are the two
87
\code{\link{betabinomial}},
88
\code{\link{betabin.ab}}.
93
N = 9; xx = 0:N; s1 = 2; s2 = 3
94
dy = dbetabin.ab(xx, size = N, shape1 = s1, shape2 = s2)
95
barplot(rbind(dy, dbinom(xx, size = N, prob = s1/(s1+s2))),
96
beside = TRUE, col = c("blue","green"), las = 1,
97
main = paste("Beta-binomial (size=",N,", shape1=",s1,
98
", shape2=",s2,") (blue) vs\n",
99
" Binomial(size=", N, ", prob=", s1/(s1+s2), ") (green)", sep = ""),
100
names.arg = as.character(xx), cex.main = 0.8)
101
sum(dy*xx) # Check expected values are equal
102
sum(dbinom(xx, size = N, prob = s1/(s1+s2))*xx)
103
cumsum(dy) - pbetabin.ab(xx, N, shape1 = s1, shape2 = s2)
105
y = rbetabin.ab(n = 10000, size = N, shape1 = s1, shape2 = s2)
107
barplot(rbind(dy, ty/sum(ty)),
108
beside = TRUE, col = c("blue","red"), las = 1,
109
main = paste("Beta-binomial (size=",N,", shape1=",s1,
110
", shape2=",s2,") (blue) vs\n",
111
" Random generated beta-binomial(size=", N, ", prob=", s1/(s1+s2),
112
") (red)", sep = ""), cex.main = 0.8,
113
names.arg = as.character(xx))
116
\keyword{distribution}