Join us for
RADAR: AI Edition

extraDistr (version 1.10.0)

BetaBinom: Beta-binomial distribution

Description

Probability mass function and random generation for the beta-binomial distribution.

Usage

dbbinom(x, size, alpha = 1, beta = 1, log = FALSE)

pbbinom(q, size, alpha = 1, beta = 1, lower.tail = TRUE, log.p = FALSE)

rbbinom(n, size, alpha = 1, beta = 1)

Arguments

x, q

vector of quantiles.

size

number of trials (zero or more).

alpha, beta

non-negative parameters of the beta distribution.

log, log.p

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

lower.tail

logical; if TRUE (default), probabilities are P[Xx] otherwise, P[X>x].

n

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

Details

If pBeta(α,β) and XBinomial(n,p), then XBetaBinomial(n,α,β).

Probability mass function f(x)=(nx)B(x+α,nx+β)B(α,β)

Cumulative distribution function is calculated using recursive algorithm that employs the fact that Γ(x)=(x1)!, and B(x,y)=Γ(x)Γ(y)Γ(x+y), and that (nk)=i=1kn+1ii. This enables re-writing probability mass function as

f(x)=(i=1xn+1ii)(α+x1)!(β+nx1)!(α+β+n1)!B(α,β)

what makes recursive updating from x to x+1 easy using the properties of factorials

f(x+1)=(i=1xn+1ii)n+1x+1x+1(α+x1)!(α+x)(β+nx1)!(β+nx)1(α+β+n1)!(α+β+n)B(α,β)

and let's us efficiently calculate cumulative distribution function as a sum of probability mass functions

F(x)=k=0xf(k)

See Also

Examples

Run this code

x <- rbbinom(1e5, 1000, 5, 13)
xx <- 0:1000
hist(x, 100, freq = FALSE)
lines(xx-0.5, dbbinom(xx, 1000, 5, 13), col = "red")
hist(pbbinom(x, 1000, 5, 13))
xx <- seq(0, 1000, by = 0.1)
plot(ecdf(x))
lines(xx, pbbinom(xx, 1000, 5, 13), col = "red", lwd = 2)

Run the code above in your browser using DataLab