Skip to contents

Draws random vectors from the Dirichlet distribution by normalizing independent Gamma variables, using the random number generator of R.

Usage

rdirichlet(n, alpha)

Arguments

n

Number of draws (a whole number of at least 1).

alpha

Numeric vector of at least two positive concentration parameters.

Value

A numeric matrix with n rows and length(alpha) columns whose rows sum to 1 (a matrix is returned even when n = 1). Column names are taken from names(alpha).

Examples

set.seed(1)
rdirichlet(3, c(1.5, 0.5, 2, 1))
#>           [,1]        [,2]      [,3]       [,4]
#> [1,] 0.2217315 0.002515614 0.7018506 0.07390225
#> [2,] 0.6482919 0.010219327 0.2687974 0.07269139
#> [3,] 0.6636989 0.051268044 0.1688307 0.11620239