The Dirichlet distribution is an absolute continuous probability, specifically a multivariate generalization of the beta distribution, parameterized by a vector \(\boldsymbol{\alpha} = (\alpha_1, \alpha_2, ..., \alpha_k)\) with \(\alpha_i > 0\).
Usage
Dir(alpha = c(1, 1))
ddir(x, alpha, log = FALSE)
rdir(n, alpha)
# S4 method for class 'Dir,numeric'
d(distr, x, log = FALSE)
# S4 method for class 'Dir,matrix'
d(distr, x)
# S4 method for class 'Dir,numeric'
r(distr, n)
# S4 method for class 'Dir'
mean(x)
# S4 method for class 'Dir'
mode(x)
# S4 method for class 'Dir'
var(x)
# S4 method for class 'Dir'
entro(x)
# S4 method for class 'Dir'
finf(x)
lldir(x, alpha)
# S4 method for class 'Dir,matrix'
ll(distr, x)
edir(x, type = "mle", ...)
# S4 method for class 'Dir,matrix'
mle(
distr,
x,
par0 = "same",
method = "L-BFGS-B",
lower = 1e-05,
upper = Inf,
na.rm = FALSE
)
# S4 method for class 'Dir,matrix'
me(distr, x, na.rm = FALSE)
# S4 method for class 'Dir,matrix'
same(distr, x, na.rm = FALSE)
vdir(alpha, type = "mle")
# S4 method for class 'Dir'
avar_mle(distr)
# S4 method for class 'Dir'
avar_me(distr)
# S4 method for class 'Dir'
avar_same(distr)
Arguments
- alpha
numeric. The non-negative distribution parameter vector.
- x
For the density function,
x
is a numeric vector of quantiles. For the moments functions,x
is an object of classDir
. For the log-likelihood and the estimation functions,x
is the sample of observations.- log
logical. Should the logarithm of the probability be returned?
- n
number of observations. If
length(n) > 1
, the length is taken to be the number required.- distr
an object of class
Dir
.- type
character, case ignored. The estimator type (mle, me, or same).
- ...
extra arguments.
- par0, method, lower, upper
arguments passed to optim for the mle optimization.
- na.rm
logical. Should the
NA
values be removed?
Value
Each type of function returns a different type of object:
Distribution Functions: When supplied with one argument (
distr
), thed()
,p()
,q()
,r()
,ll()
functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr
andx
), they evaluate the aforementioned functions directly.Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The
moments()
function returns a list with all the available methods.Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.
Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.
Details
The probability density function (PDF) of the Dirichlet distribution is given by: $$ f(x_1, ..., x_k; \alpha_1, ..., \alpha_k) = \frac{1}{B(\boldsymbol{\alpha})} \prod_{i=1}^k x_i^{\alpha_i - 1}, $$ where \(B(\boldsymbol{\alpha})\) is the multivariate Beta function: $$ B(\boldsymbol{\alpha}) = \frac{\prod_{i=1}^k \Gamma(\alpha_i)}{\Gamma\left(\sum_{i=1}^k \alpha_i\right)} $$ and \(\sum_{i=1}^k x_i = 1\), \(x_i > 0\).
References
Oikonomidis, I. & Trevezas, S. (2025), Moment-Type Estimators for the Dirichlet and the Multivariate Gamma Distributions, arXiv, https://arxiv.org/abs/2311.15025
Examples
# -----------------------------------------------------
# Dir Distribution Example
# -----------------------------------------------------
# Create the distribution
a <- c(0.5, 2, 5)
D <- Dir(a)
# ------------------
# dpqr Functions
# ------------------
d(D, c(0.3, 0.2, 0.5)) # density function
#> [1] 1.003913
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#> [1] 24.77300121 7.30983973 0.82018079 3.09639840 9.01982497
#> [6] 39.84500725 330.11542526 9.42548756 4.61888811 2.27497931
#> [11] 64.27091137 18.62530960 2.10211248 1.63802351 1.19686120
#> [16] 8.25251246 17.90121464 0.74870277 8.72460022 0.55837485
#> [21] 8.21813142 1.88378114 18.25077604 36.30299265 193.49162463
#> [26] 16.48802269 7.72075754 1.92680717 1.59190279 2.49922116
#> [31] 7.30498152 125.93965445 0.54948163 2.53622638 56.48520822
#> [36] 0.43959178 6.73568100 56.29973185 19.69573566 2.82021054
#> [41] 17.76917321 2.44265070 136.52489485 6.02799115 9.74419696
#> [46] 103.22800743 62.45528918 59.23861402 16.72800114 12.04350492
#> [51] 0.21314095 15.49143498 20.53195188 8.40650362 15.71665753
#> [56] 3.40624205 7.31707158 16.34273035 9.23467406 66.67870933
#> [61] 103.58033370 0.05178777 2.78600739 44.65538491 16.32873325
#> [66] 6.18668122 7.92540146 16.90022450 7.97774674 132.13019415
#> [71] 13.78471007 9.94941804 3.18909544 3.71704118 1.92530182
#> [76] 6.59831401 16.47057195 0.92414964 129.28524193 1.24635003
#> [81] 80.27388019 476.34209004 3.11768072 13.39764640 29.41641117
#> [86] 1.99204330 9.86443108 28.78544730 0.55269678 26.26901025
#> [91] 20.60548672 5.84967397 12.47014567 50.39362983 1.54175468
#> [96] 9.07270050 6.03121668 12.81735187 5.22700358 2.67761296
# ------------------
# Moments
# ------------------
mean(D) # Expectation
#> [1] 0.06666667 0.26666667 0.66666667
mode(D) # Mode
#> [1] -0.1111111 0.2222222 0.8888889
var(D) # Variance
#> [,1] [,2] [,3]
#> [1,] 0.007320261 -0.002091503 -0.005228758
#> [2,] -0.002091503 0.023006536 -0.020915032
#> [3,] -0.005228758 -0.020915032 0.026143791
entro(D) # Entropy
#> [1] -2.452547
finf(D) # Fisher Information Matrix
#> alpha1 alpha2 alpha3
#> alpha1 4.7921863 -0.1426159 -0.14261590
#> alpha2 -0.1426159 0.5023182 -0.14261590
#> alpha3 -0.1426159 -0.1426159 0.07870706
# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 0.06666667 0.26666667 0.66666667
# ------------------
# Point Estimation
# ------------------
ll(D, x)
#> [1] 219.6185
lldir(x, a)
#> [1] 219.6185
edir(x, type = "mle")
#> $alpha
#> [1] 0.5942496 1.9223128 5.0267809
#>
edir(x, type = "me")
#> $alpha
#> [1] 0.8187913 2.2631115 5.9893682
#>
mle(D, x)
#> $alpha
#> [1] 0.5942496 1.9223128 5.0267809
#>
me(D, x)
#> $alpha
#> [1] 0.8187913 2.2631115 5.9893682
#>
e(D, x, type = "mle")
#> $alpha
#> [1] 0.5942496 1.9223128 5.0267809
#>
mle("dir", x) # the distr argument can be a character
#> $alpha
#> [1] 0.5942496 1.9223128 5.0267809
#>
# ------------------
# Estimator Variance
# ------------------
vdir(a, type = "mle")
#> alpha1 alpha2 alpha3
#> alpha1 0.2581065 0.4243918 1.236676
#> alpha2 0.4243918 4.7978389 9.462596
#> alpha3 1.2366759 9.4625963 32.092246
vdir(a, type = "me")
#> alpha1 alpha2 alpha3
#> alpha1 0.6967287 1.109928 3.213417
#> alpha2 1.1099281 6.555295 13.730859
#> alpha3 3.2134166 13.730859 43.124878
avar_mle(D)
#> alpha1 alpha2 alpha3
#> alpha1 0.2581065 0.4243918 1.236676
#> alpha2 0.4243918 4.7978389 9.462596
#> alpha3 1.2366759 9.4625963 32.092246
avar_me(D)
#> alpha1 alpha2 alpha3
#> alpha1 0.6967287 1.109928 3.213417
#> alpha2 1.1099281 6.555295 13.730859
#> alpha3 3.2134166 13.730859 43.124878
v(D, type = "mle")
#> alpha1 alpha2 alpha3
#> alpha1 0.2581065 0.4243918 1.236676
#> alpha2 0.4243918 4.7978389 9.462596
#> alpha3 1.2366759 9.4625963 32.092246