Learn R Programming

rmutil (version 1.1.10)

Beta Binomial: Beta Binomial Distribution

Description

These functions provide information about the beta binomial distribution with parameters m and s: density, cumulative distribution, quantiles, and random generation. Compared to the parameterization of `VGAM::pbetabinom.ab`, m = alpha/(alpha+beta) and s = (alpha+beta). See examples.

The beta binomial distribution with total \(= n\) and prob \(= m\) has density $$p(y) = \frac{B(y+\sigma \mu, n-y+\sigma*(1-\mu)) {n \choose y} }{B(s m,s (1-m))}% $$ for \(y = 0, \ldots, n\) where \(B()\) is the beta function.

Usage

dbetabinom(y, size, m, s, log=FALSE)
pbetabinom(q, size, m, s)
qbetabinom(p, size, m, s)
rbetabinom(n, size, m, s)

Arguments

y

vector of frequencies

q

vector of quantiles

p

vector of probabilities

n

number of values to generate

size

vector of totals

m

vector of probabilities of success; Compared to the parameterization of `VGAM::pbetabinom.ab`, m = alpha/(alpha+beta) where shape1=alpha and shape2=beta. See examples.

s

vector of overdispersion parameters; Compared to the parameterization of `VGAM::pbetabinom.ab`, s = (alpha+beta) where shape1=alpha and shape2=beta. See examples.

log

if TRUE, log probabilities are supplied.

Author

J.K. Lindsey

See Also

dbinom for the binomial, ddoublebinom for the double binomial, and dmultbinom for the multiplicative binomial distribution.

Examples

Run this code
# compute P(45 < y < 55) for y beta binomial(100,0.5,1.1)
sum(dbetabinom(46:54, 100, 0.5, 1.1))
pbetabinom(54,100,0.5,1.1)-pbetabinom(45,100,0.5,1.1)
pbetabinom(2,10,0.5,1.1)
qbetabinom(0.33,10,0.5,1.1)
rbetabinom(10,10,0.5,1.1)
## compare to VGAM
if (FALSE) {
# The beta binomial distribution with total = n and prob = m has density
# 
# p(y) = B(y+s m,n-y+s (1-m)) Choose(n,y) / B(s m,s (1-m))
# 
# for y = 0, …, n where B() is the beta function.

## in `rmutil` from the .Rd file (excerpt above), the "alpha" is s*m
## in `rmutil` from the .Rd file (excerpt above), the "beta"  is s*(1-m)

## in `VGAM`, rho is 1/(1+alpha+beta)

qq = 2.2
zz = 100

alpha = 1.1
beta  = 2
VGAM::pbetabinom.ab(q=qq, size=zz, shape1=alpha, shape2=beta)

## for VGAM `rho`
rr = 1/(1+alpha+beta)
VGAM::pbetabinom   (q=qq, size=zz, prob=mm, rho = rr)

## for rmutil `m` and `s`:
mm = alpha / (alpha+beta)
ss = (alpha+beta)
rmutil::pbetabinom(q=qq, size=zz, m=mm, s=ss )
}

Run the code above in your browser using DataLab