Learn R Programming

VGAM (version 1.0-1)

Betabinom: The Beta-Binomial Distribution

Description

Density, distribution function, and random generation for the beta-binomial distribution and the inflated beta-binomial distribution.

Usage

dbetabinom(x, size, prob, rho = 0, log = FALSE)
pbetabinom(q, size, prob, rho, log.p = FALSE)
rbetabinom(n, size, prob, rho = 0)
dbetabinom.ab(x, size, shape1, shape2, log = FALSE, Inf.shape = 1e6)
pbetabinom.ab(q, size, shape1, shape2, log.p = FALSE)
rbetabinom.ab(n, size, shape1, shape2, .dontuse.prob = NULL)
dozibetabinom(x, size, prob, rho = 0, pstr0 = 0, pstrsize = 0, log = FALSE)
pozibetabinom(q, size, prob, rho, pstr0 = 0, pstrsize = 0, 
              lower.tail = TRUE, log.p = FALSE)
rozibetabinom(n, size, prob, rho = 0, pstr0 = 0, pstrsize = 0)
dozibetabinom.ab(x, size, shape1, shape2, pstr0 = 0, pstrsize = 0, log = FALSE)
pozibetabinom.ab(q, size, shape1, shape2, pstr0 = 0, pstrsize = 0,
              lower.tail = TRUE, log.p = FALSE)
rozibetabinom.ab(n, size, shape1, shape2, pstr0 = 0, pstrsize = 0)

Arguments

x, q
vector of quantiles.
size
number of trials.
n
number of observations. Same as runif.
prob
the probability of success $\mu$. Must be in the unit closed interval $[0,1]$.
rho
the correlation parameter $\rho$. Usually must be in the unit open interval $(0,1)$, however, the value 0 is sometimes supported (if so then it corresponds to the usual binomial distribution).
shape1, shape2
the two (positive) shape parameters of the standard beta distribution. They are called a and b in beta respectively.
log, log.p, lower.tail
Same meaning as runif.
Inf.shape
Numeric. A large value such that, if shape1 or shape2 exceeds this, then it is taken to be Inf. Also, if shape1 or shape2 is less than its reciprocal, then it might be loosely though
.dontuse.prob
An argument that should be ignored and unused.
pstr0
Probability of a structual zero (i.e., ignoring the beta-binomial distribution). The default value of pstr0 corresponds to the response having a beta-binomial distribuion inflated only at size.
pstrsize
Probability of a structual maximum value size. The default value of pstrsize corresponds to the response having a beta-binomial distribution inflated only at 0.

Value

  • dbetabinom and dbetabinom.ab give the density, pbetabinom and pbetabinom.ab give the distribution function, and rbetabinom and rbetabinom.ab generate random deviates. dozibetabinom and dozibetabinom.ab give the inflated density, pozibetabinom and pozibetabinom.ab give the inflated distribution function, and rozibetabinom and rozibetabinom.ab generate random inflated deviates.

Details

The beta-binomial distribution is a binomial distribution whose probability of success is not a constant but it is generated from a beta distribution with parameters shape1 and shape2. Note that the mean of this beta distribution is mu = shape1/(shape1+shape2), which therefore is the mean or the probability of success.

See betabinomial and betabinomialff, the VGAM family functions for estimating the parameters, for the formula of the probability density function and other details.

For the inflated beta-binomial distribution, the probability mass function is $$P(Y = y) =(1 - pstr0 - pstrsize) \times BB(y) + pstr0 \times I[y = 0] + pstrsize \times I[y = size]$$ where $BB(y)$ is the probability mass function of the beta-binomial distribution with the same shape parameters (pbetabinom.ab), pstr0 is the inflated probability at 0 and pstrsize is the inflated probability at 1. The default values of pstr0 and pstrsize mean that these functions behave like the ordinary Betabinom when only the essential arguments are inputted.

See Also

betabinomial, betabinomialff, Ozibeta.

Examples

Run this code
set.seed(1); rbetabinom(10, 100, prob = 0.5)
set.seed(1);     rbinom(10, 100, prob = 0.5)  # The same since rho = 0

N <- 9; xx <- 0:N; s1 <- 2; s2 <- 3
dy <- dbetabinom.ab(xx, size = N, shape1 = s1, shape2 = s2)
barplot(rbind(dy, dbinom(xx, size = N, prob = s1 / (s1+s2))),
        beside = TRUE, col = c("blue","green"), las = 1,
        main = paste("Beta-binomial (size=",N,", shape1=", s1,
                   ", shape2=", s2, ") (blue) vs\n",
        " Binomial(size=", N, ", prob=", s1/(s1+s2), ") (green)", sep = ""),
        names.arg = as.character(xx), cex.main = 0.8)
sum(dy * xx)  # Check expected values are equal
sum(dbinom(xx, size = N, prob = s1 / (s1+s2)) * xx)
cumsum(dy) - pbetabinom.ab(xx, N, shape1 = s1, shape2 = s2)  # Should be all 0

y <- rbetabinom.ab(n = 10000, size = N, shape1 = s1, shape2 = s2)
ty <- table(y)
barplot(rbind(dy, ty / sum(ty)),
        beside = TRUE, col = c("blue", "orange"), las = 1,
        main = paste("Beta-binomial (size=", N, ", shape1=", s1,
                     ", shape2=", s2, ") (blue) vs\n",
        " Random generated beta-binomial(size=", N, ", prob=", s1/(s1+s2),
        ") (orange)", sep = ""), cex.main = 0.8,
        names.arg = as.character(xx)) 

set.seed(208); N <- 1000000; size = 20;
pstr0 <- 0.2; pstrsize <- 0.2
k <- rozibetabinom.ab(N, size, s1, s2, pstr0, pstrsize)
hist(k, probability = TRUE, border = "blue",
     main = "Blue = inflated; orange = ordinary beta-binomial",
     breaks = -0.5 : (size + 0.5))
sum(k == 0) / N  # Proportion of 0
sum(k == size) / N  # Proportion of size
lines(0 : size,
      dbetabinom.ab(0 : size, size, s1, s2), col = "orange")
lines(0 : size, col = "blue",
      dozibetabinom.ab(0 : size, size, s1, s2, pstr0, pstrsize))

Run the code above in your browser using DataLab