Skip to contents

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

Usage

dzibetabinom(x, size, shape1, shape2, zeroprob = 0, log = FALSE)

pzibetabinom(
  q,
  size,
  shape1,
  shape2,
  zeroprob = 0,
  lower.tail = TRUE,
  log.p = FALSE
)

rzibetabinom(n, size, shape1, shape2, zeroprob = 0)

Arguments

x

integer vector of counts

size

number of trials (zero or more)

shape1, shape2

positive shape parameters of the mixing beta distribution

zeroprob

zero-inflation probability between 0 and 1

log

logical; return log-density if TRUE

q

vector of quantiles.

lower.tail

logical; if TRUE (default), probabilities are \(P[X \le q]\), otherwise \(P[X > q]\).

log.p

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

n

number of random values to return.

Value

dzibetabinom gives the probability mass function, pzibetabinom gives the distribution function, and rzibetabinom generates random deviates.

Details

This implementation allows for automatic differentiation with RTMB.

$$P(X=k;\,n,a,b,p_0) = p_0\,\mathbf{1}[k=0] + (1-p_0)\,P_{\mathrm{BB}}(k;\,n,a,b),$$ where \(p_0\) is zeroprob. The zeros are a mixture of structural zeros and zeros generated by the beta-binomial itself, so zeroprob is not the probability of observing a zero; see hbetabinom for the hurdle version, where it is.

The distribution function has no closed form and is computed by summing the probability mass function over \(0, \ldots, q\). It is AD-compatible in the parameters, while q and size must be numeric data. This is also what one-step-ahead (OSA) residuals via RTMB::oneStepPredict need, so these are supported, e.g. with method = "cdf" and discrete = TRUE.

Examples

set.seed(123)
x <- rzibetabinom(5, size = 10, shape1 = 2, shape2 = 3, zeroprob = 0.3)
d <- dzibetabinom(x, size = 10, shape1 = 2, shape2 = 3, zeroprob = 0.3)
p <- pzibetabinom(x, size = 10, shape1 = 2, shape2 = 3, zeroprob = 0.3)