pdf and random deviates of the Dirichlet distribution.

ddirichlet(x, alpha)

rdirichlet(n, alpha, allowZero = FALSE)

Arguments

x

vector of quantiles. For x < 0 || x > 1 or if the sum of x is not equal to 1, zero will be returned for the density

alpha

The Dirichlet parameters. alpha > 0 unless allowZero=TRUE

n

number of observations

allowZero

Indicator that zeros are allowed in the alpha vector and should be handled appropriately

Value

ddirichlet gives the density and rdirichlet generates random deviates.

Examples

rdirichlet(10, c(4,3,2))
#> [,1] [,2] [,3] #> [1,] 0.3404537 0.28869411 0.37085222 #> [2,] 0.6725347 0.16560242 0.16186283 #> [3,] 0.3446954 0.47724988 0.17805474 #> [4,] 0.2153887 0.64554928 0.13906205 #> [5,] 0.3457184 0.58370664 0.07057496 #> [6,] 0.3884493 0.07957157 0.53197912 #> [7,] 0.4386653 0.18161309 0.37972163 #> [8,] 0.5581667 0.23415027 0.20768304 #> [9,] 0.3502420 0.50506911 0.14468885 #> [10,] 0.4812373 0.35005756 0.16870513
ddirichlet(c(.2, .7, .1), c(4, 3, 2))
#> [1] 1.31712
rdirichlet(5, c(4,3,0,2), allowZero=TRUE)
#> [,1] [,2] [,3] [,4] #> [1,] 0.4760291 0.41208717 0 0.1118837358 #> [2,] 0.3240160 0.47084014 0 0.2051438482 #> [3,] 0.6104010 0.24798143 0 0.1416175572 #> [4,] 0.4511503 0.08128398 0 0.4675657254 #> [5,] 0.7192682 0.28020778 0 0.0005240707
(ddirichlet(c(-0.2, 1.2), c(2,2)) == 0)
#> [1] TRUE