Learn R Programming

RTMBdist (version 0.1.0)

dirmult: Dirichlet-multinomial distribution

Description

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

Usage

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

rdirmult(n, size, alpha)

Value

ddirmult gives the density and rdirmult generates random samples.

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.

Examples

Run this code
# 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)

Run the code above in your browser using DataLab