The function ddirichlet()
computes the density of a Dirichlet distribution.
The function rdirichlet()
samples from a Dirichlet distribution.
The functions with suffix _cpp
perform no input checks, hence are faster.
Usage
ddirichlet_cpp(x, concentration, log = FALSE)
rdirichlet_cpp(concentration)
ddirichlet(x, concentration, log = FALSE)
rdirichlet(n = 1, concentration)
Value
For ddirichlet()
: The density value.
For rdirichlet()
: If n = 1
a vector
of length p
, else
a matrix
of dimension n
times p
with samples as rows.
See also
Other simulation helpers:
Simulator
,
correlated_regressors()
,
dmvnorm_cpp()
,
dtnorm_cpp()
,
dwishart_cpp()
,
simulate_markov_chain()
Examples
x <- c(0.5, 0.3, 0.2)
concentration <- 1:3
# compute density
ddirichlet(x = x, concentration = concentration)
#> [1] 0.72
ddirichlet(x = x, concentration = concentration, log = TRUE)
#> [1] -0.3285041
# sample
rdirichlet(concentration = 1:3)
#> [1] 0.08113735 0.43284491 0.48601774
rdirichlet(n = 4, concentration = 1:2)
#> [,1] [,2]
#> [1,] 0.15721799 0.8427820
#> [2,] 0.14692809 0.8530719
#> [3,] 0.68125471 0.3187453
#> [4,] 0.09856497 0.9014350