powered by
Density and and random generation for the Dirichlet distribution.
ddirichlet(x, alpha, log = FALSE)rdirichlet(n, alpha)
rdirichlet(n, alpha)
ddirichlet gives the density, rdirichlet generates random deviates.
ddirichlet
rdirichlet
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.
x
vector or matrix of positive shape parameters
logical; if TRUE, densities \(p\) are returned as \(\log(p)\).
TRUE
number of random values to return.
This implementation of ddirichlet allows for automatic differentiation with RTMB.
RTMB
# 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)
Run the code above in your browser using DataLab