dirichlet: Dirichlet distribution

dirichletR Documentation

Dirichlet distribution

Description

Density and and random generation for the Dirichlet distribution.

Usage

ddirichlet(x, alpha, log = FALSE)

rdirichlet(n, alpha)

Arguments

x

vector or matrix of quantiles. If x is a vector, it needs to sum to one. If x is a matrix, each row should sum to one.

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 ddirichlet allows for automatic differentiation with RTMB.

Value

ddirichlet gives the density, rdirichlet generates random deviates.

Examples

# single alpha
alpha <- c(1,2,3)
x <- rdirichlet(1, alpha)
d <- ddirichlet(x, alpha)
# vectorised over alpha
alpha <- rbind(alpha, 2*alpha)
x <- rdirichlet(2, alpha)

RTMBdist documentation built on April 1, 2026, 5:07 p.m.