dBetaBinom: A beta binomial distribution and beta function for use in...

dBetaBinomR Documentation

A beta binomial distribution and beta function for use in nimble models

Description

dBetaBinom_v and dBetaBinom_s provide a beta binomial distribution that can be used directly from R or in nimble models. These are also used by beta binomial variations of dNmixture distributions. nimBetaFun is the beta function.

Usage

nimBetaFun(a, b, log)

dBetaBinom_v(x, N, shape1, shape2, len, log = 0)

dBetaBinom_s(x, N, shape1, shape2, len, log = 0)

rBetaBinom_v(n, N, shape1, shape2, len)

rBetaBinom_s(n, N, shape1, shape2, len)

Arguments

a

shape1 argument of the beta function.

b

shape2 argument of the beta function.

log

TRUE or 1 to return log probability. FALSE or 0 to return probability.

x

vector of integer counts.

N

number of trials, sometimes called "size".

shape1

shape1 parameter of the beta distribution.

shape2

shape2 parameter of the beta distribution.

len

length of x.

n

number of random draws, each returning a vector of length len. Currently only n = 1 is supported, but the argument exists for standardization of "r" functions.

Details

These nimbleFunctions provide distributions that can be used directly in R or in nimble hierarchical models (via nimbleCode and nimbleModel). They are used by the beta-binomial variants of the N-mixture distributions (dNmixture).

The beta binomial is the marginal distribution of a binomial distribution whose probability follows a beta distribution.

The probability mass function of the beta binomial is choose(N, x) * B(x + shape1, N - x + shape2) / B(shape1, shape2), where B(shape1, shape2) is the beta function.

nimBetaFun(shape1, shape2) calculates B(shape1, shape2).

The beta binomial distribution is provided in two forms. dBetaBinom_v and is when shape1 and shape2 are vectors. dBetaBinom_s is used when shape1 and shape2 are scalars. In both cases, x is a vector.

Author(s)

Ben Goldstein and Perry de Valpine

See Also

For beta binomial N-mixture models, see dNmixture. For documentation on the beta function, use ?stats::dbeta

Examples

# Calculate a beta binomial probability with different shape1 and shape2 for each x[i]
dBetaBinom_v(x = c(4, 0, 0, 3), N = 10,
  shape1 = c(0.5, 0.5, 0.3, 0.5), shape2 = c(0.2, 0.4, 1, 1.2))
# or with constant shape1 and shape2
dBetaBinom_s(x = c(4, 0, 0, 3), N = 10, shape1 = 0.5, shape2 = 0.5, log = TRUE)

nimbleEcology documentation built on June 27, 2024, 5:09 p.m.