| dirichlet | R Documentation |
Density and and random generation for the Dirichlet distribution.
ddirichlet(x, alpha, log = FALSE)
rdirichlet(n, alpha)
x |
vector or matrix of quantiles. If |
alpha |
vector or matrix of positive shape parameters |
log |
logical; if |
n |
number of random values to return. |
This implementation of ddirichlet allows for automatic differentiation with RTMB.
f(\mathbf{x};\,\boldsymbol{\alpha}) = \frac{\Gamma\!\left(\sum_i \alpha_i\right)}{\prod_i \Gamma(\alpha_i)} \prod_i x_i^{\alpha_i - 1},
where \mathbf{x} lies on the unit simplex and \alpha_i > 0.
ddirichlet gives the density, rdirichlet generates random deviates.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.