tr06-beta-binomial: The Beta-Binomial Distribution

BetaBinomialR Documentation

The Beta-Binomial Distribution

Description

Density, distribution function, quantile function, and random generation for the beta-binomial distribution. A variable with a beta-binomial distribution is distributed as binomial distribution with parameters N and p, where the probability p of success iteself has a beta distribution with parameters u and v.

Usage

dbb(x, N, u, v, log = FALSE)
pbb(q, N, u, v)
qbb(p, N, u, v)
rbb(n, N, u, v)

Arguments

x

vector of qauntiles

q

vector of quantiles

p

vector of probabilities

n

number of observations

N

number of trials ( a positive integer)

u

first positive parameter of the beta distribution

v

second positive parameter of the beta distribution

log

A logical value; if true, values are returned on the log scale

Details

The beta-binomial distribution with parameters N, u, and v has density given by

choose(N, x) * Beta(x + u, N - x + v) / Beta(u,v)

for u > 0, v > 0, a positive integer N, and any nonnegative integer x. Although one can express the integral in closed form using generalized hypergeometric functions, the implementation of distribution function used here simply relies on the the cumulative sum of the density.

The mean and variance of the beta-binomial distribution can be computed explicitly as

μ = \frac{Nu}{u+v}

and

σ^2 = \frac{Nuv(N+u+v)}{(u+v)^2 (1+u+v)}

Value

dbb gives the density, pbb gives the distribution function, qbb gives the quantile function, and rbb generates random deviates.

Author(s)

Kevin R. Coombes <krc@silicovore.com>

See Also

dbeta for the beta distribution and dbinom for the binomial distribution.

Examples

# set up parameters
w <- 10
u <- 0.3*w
v <- 0.7*w
N <- 12
# generate random values from the beta-binomial
x <- rbb(1000, N, u, v)

# check that the empirical summary matches the theoretical one
summary(x)
qbb(c(0.25, 0.50, 0.75), N, u, v)

# check that the empirpical histogram matches te theoretical density
hist(x, breaks=seq(-0.5, N + 0.55), prob=TRUE)
lines(0:N, dbb(0:N, N, u,v), type='b')

TailRank documentation built on Jan. 13, 2023, 3:02 a.m.