Learn R Programming

joker (version 0.14.2)

Dir: Dirichlet Distribution

Description

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 Dir,numeric d(distr, x, log = FALSE)

# S4 method for Dir,matrix d(distr, x)

# S4 method for Dir,numeric r(distr, n)

# S4 method for Dir mean(x)

# S4 method for Dir mode(x)

# S4 method for Dir var(x)

# S4 method for Dir entro(x)

# S4 method for Dir finf(x)

lldir(x, alpha)

# S4 method for Dir,matrix ll(distr, x)

edir(x, type = "mle", ...)

# S4 method for Dir,matrix mle( distr, x, par0 = "same", method = "L-BFGS-B", lower = 1e-05, upper = Inf, na.rm = FALSE )

# S4 method for Dir,matrix me(distr, x, na.rm = FALSE)

# S4 method for Dir,matrix same(distr, x, na.rm = FALSE)

vdir(alpha, type = "mle")

# S4 method for Dir avar_mle(distr)

# S4 method for Dir avar_me(distr)

# S4 method for Dir avar_same(distr)

Value

Each type of function returns a different type of object:

  • Distribution Functions: When supplied with one argument (distr), the d(), 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 and x), 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.

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 class Dir. 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?

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

Run this code
# -----------------------------------------------------
# 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
x <- r(D, 100) # random generator function

# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself

# ------------------
# Moments
# ------------------

mean(D) # Expectation
mode(D) # Mode
var(D) # Variance
entro(D) # Entropy
finf(D) # Fisher Information Matrix

# List of all available moments
mom <- moments(D)
mom$mean # expectation

# ------------------
# Point Estimation
# ------------------

ll(D, x)
lldir(x, a)

edir(x, type = "mle")
edir(x, type = "me")

mle(D, x)
me(D, x)
e(D, x, type = "mle")

mle("dir", x) # the distr argument can be a character

# ------------------
# Estimator Variance
# ------------------

vdir(a, type = "mle")
vdir(a, type = "me")

avar_mle(D)
avar_me(D)

v(D, type = "mle")

Run the code above in your browser using DataLab