Skip to contents

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

Usage

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.12510187 0.26050824 0.1617189 0.4526710
#>  [2,] 0.06637497 0.07129742 0.3539131 0.5084145
#>  [3,] 0.19693719 0.12057621 0.2123177 0.4701689
#>  [4,] 0.18130563 0.23975465 0.1465875 0.4323522
#>  [5,] 0.20416900 0.13513562 0.2563768 0.4043186
#>  [6,] 0.05797084 0.17074264 0.3460810 0.4252055
#>  [7,] 0.05097357 0.15506002 0.3387322 0.4552342
#>  [8,] 0.12550172 0.31443703 0.1302074 0.4298538
#>  [9,] 0.07404925 0.21557485 0.1755355 0.5348404
#> [10,] 0.02222693 0.26630898 0.3923619 0.3191022