BetaBin: The Beta-Binomial Distribution

dBetaBinR Documentation

The Beta-Binomial Distribution

Description

Mass function, distribution function, quantile function, and random generation for the beta-binomial distribution.

Usage

dBetaBin(x, size, mu, theta = NULL, phi = NULL, log = FALSE)

qBetaBin(prob, size, mu, theta = NULL, phi = NULL, log.prob = FALSE)

pBetaBin(q, size, mu, theta = NULL, phi = NULL, log.prob = FALSE)

rBetaBin(n, size = NULL, mu = NULL, theta = NULL, phi = NULL)

Arguments

x, q

a vector of quantiles.

size

the total number of trials.

mu

the mean parameter. It must lie in (0, 1).

theta

the overdispersion parameter. It must lie in (0, 1).

phi

the precision parameter, an alternative way to specify the overdispersion parameter theta. It must be a real positive value.

log

logical; if TRUE, probabilities are returned on log-scale.

prob

a vector of probabilities.

log.prob

logical; if TRUE, probabilities prob are given as log(prob).

n

the number of values to generate. If length(n) > 1, the length is taken to be the number required.

Details

The beta-binomial distribution has probability mass function

f_{BB}(x;\mu,\phi)={n\choose x} \frac{\Gamma{(\phi)}}{\Gamma{(\mu\phi)}\Gamma{((1-\mu)\phi)}} \frac{\Gamma{(\mu\phi+x)}\Gamma{((1-\mu)\phi + n - x)}}{\Gamma{(\phi + n)}},

for x \in \lbrace 0, 1, \dots, n \rbrace, where 0<\mu<1 identifies the mean and \phi=(1-\theta)/\theta >0 is the precision parameter.

Value

The function dBetaBin returns a vector with the same length as x containing the probability mass values. The function pBetaBin returns a vector with the same length as q containing the values of the distribution function. The function qBetaBin returns a vector with the same length as prob containing the quantiles. The function rBetaBin returns a vector of length n containing the generated random values.

References

Ascari, R., Migliorati, S. (2021). A new regression model for overdispersed binomial data accounting for outliers and an excess of zeros. Statistics in Medicine, 40(17), 3895–3914. doi:10.1002/sim.9005

Examples

dBetaBin(x = 5, size = 10, mu = .3, phi = 10)
dBetaBin(x = 5, size = 10, mu = .3, theta = 1/(10+1))

qBetaBin(prob = .5, size = 10, mu = .3, phi = 10)
qBetaBin(prob = .5, size = 10, mu = .3, theta = 1/(10+1))

pBetaBin(q = 5, size = 10, mu = .3, phi = 10)
pBetaBin(q = 5, size = 10, mu = .3, theta = 1/(10+1))

rBetaBin(n = 100, size = 40, mu = .5, theta = .4)
rBetaBin(n = 100, size = 40, mu = .5, phi = 1.5)


FlexReg documentation built on Sept. 9, 2025, 5:49 p.m.