Dirichlet-multinomial distribution
dirmult.RdDensity and and random generation for the Dirichlet-multinomial distribution.
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.
Details
This implementation of ddirmult allows for automatic differentiation with RTMB.
$$P(\mathbf{x};\,\boldsymbol{\alpha}, n) = \frac{\Gamma(\alpha_0)\,\Gamma(n+1)}{\Gamma(n+\alpha_0)} \prod_i \frac{\Gamma(x_i + \alpha_i)}{\Gamma(\alpha_i)\,\Gamma(x_i+1)},$$ where \(\alpha_0 = \sum_i \alpha_i\) and \(n = \sum_i x_i\).