Simulates from a Dirichlet distribution with concentration parameter vector \(\alpha\) = (\(\alpha_1\), ..., \(\alpha_K\)).

rDir(n = 1, alpha = c(1, 1))

Arguments

n

A numeric scalar. The size of sample required.

alpha

A numeric vector. Dirichlet concentration parameter.

Value

An n by length(alpha) numeric matrix.

Details

The simulation is based on the property that if \(Y_1, \ldots, Y_K\) are independent, \(Y_i\) has a gamma(\(\alpha_i\), 1) distribution and \(S = Y_1 + \cdots + Y_k\) then \((Y_1, \ldots, Y_K) / S\) has a Dirichlet(\(\alpha_1\), ..., \(\alpha_K\)) distribution.

See https://en.wikipedia.org/wiki/Dirichlet_distribution#Gamma_distribution

References

Kotz, S., Balakrishnan, N. and Johnson, N. L. (2000) Continuous Multivariate Distributions, vol. 1, Models and Applications, 2nd edn, ch. 49. New York: Wiley. doi:10.1002/0471722065

See also

rprior_prob for prior simulation of GEV parameters - prior on probability scale.

Examples

rDir(n = 10, alpha = 1:4)
#>             [,1]       [,2]       [,3]      [,4]
#>  [1,] 0.02033082 0.25857950 0.50908752 0.2120022
#>  [2,] 0.01516279 0.21516422 0.03571335 0.7339596
#>  [3,] 0.22395186 0.03806343 0.34757184 0.3904129
#>  [4,] 0.11381426 0.05391379 0.34029701 0.4919749
#>  [5,] 0.16456654 0.14984515 0.11893918 0.5666491
#>  [6,] 0.12383678 0.15374676 0.15762498 0.5647915
#>  [7,] 0.01438139 0.13353260 0.37545388 0.4766321
#>  [8,] 0.19956898 0.01125842 0.37236384 0.4168088
#>  [9,] 0.07170164 0.10631943 0.09119960 0.7307793
#> [10,] 0.06436264 0.13251928 0.17289609 0.6302220