Skip to contents

Density and and random generation for the Dirichlet-multinomial distribution.

Usage

ddirmult(x, size, alpha, log = FALSE)

rdirmult(n, size, alpha)

Arguments

x

vector or matrix of non-negative counts, where rows are observations and columns are categories.

size

vector of total counts for each observation. Needs to match the row sums of x.

alpha

vector or matrix of positive shape parameters

log

logical; if TRUE, densities \(p\) are returned as \(\log(p)\).

n

number of random values to return.

Value

ddirmult gives the density and rdirmult generates random samples.

Details

This implementation of ddirmult allows for automatic differentiation with RTMB.

Examples

# single alpha
alpha <- c(1,2,3)
size <- 10
x <- rdirmult(1, size, alpha)
d <- ddirmult(x, size, alpha)
# vectorised over alpha and size
alpha <- rbind(alpha, 2*alpha)
size <- c(size, 3*size)
x <- rdirmult(2, size, alpha)