rDirichlet: Simulate Mixing Proportions from a Dirichlet Distribution
Description
Generates samples from the Dirichlet distrubution with parameter alpha efficiently by simulating Gamma(alpha, 1) random variables and normalising them.
Usage
rDirichlet(G, alpha, nn = 0)
Arguments
G
The number of groups for which weights need to be sampled.
alpha
The Dirichlet hyperparameter, either of length 1 or G. When the length of alpha is 1, this amounts to assuming an exchangeable prior. Be warned that this will be recycled if necessary.
nn
A vector giving the number of observations in each of G groups so that Dirichlet posteriors rather than priors can be sampled from. This defaults to 0, i.e. simulation from the prior. Be warned that this will be recycled if necessary.
Value
A Dirichlet vector of G weights which sum to 1.
References
Devroye, L. (1986) Non-Uniform Random Variate Generation, Springer-Verlag, New York, p. 594.