dirichlet: Dirichlet Distribution

dirichletR Documentation

Dirichlet Distribution

Description

Probability density function (PDF), cumulative density function (CDF), and random generation for the Dirichlet distribution with parameters \lapha = \alpha_1, ... , \alpha_n, all positive reals, in short, Dir(\alpha). Dirichlet distribution is a family of continuous multivariate probability distributions, a multivariate generalization of the Beta distribution. The PDF is a multidimensional generalization of the beta distribution.

Usage

ddirichlet(x, alpha, log = FALSE)

pdirichlet(q, alpha, lower.tail = TRUE, log.p = FALSE, log.base = exp(1), ...)

rdirichlet(n, alpha)

Arguments

x

A numerical matrix x_ij >= 0 or vector x_i >= 0 of observed counts or relative frequencies \sum x_i = 1.

alpha

Dirichlet distribution's parameters. A numerical parameter vector, strictly positive (default 1): \lapha = \alpha_1, ... , \alpha_n.

q

numeric vector.

lower.tail

logical; if TRUE (default), probabilities are P(X<=x), otherwise, P(X > x)

log.p

logical; if TRUE, probabilities/densities p are returned as log(p).

log.base

(Optional) The logarithm's base if log.p = TRUE.

...

Additional named or unnamed arguments to be passed to function hcubature used in functions 'pdirichlet' and 'qdirichlet'.

n

number of observations.

p

vector of probabilities.

interval

The interval whether to search for the quantile (see Details).

tol

The desired accuracy (convergence tolerance) for the quantile estimation.

Details

The computation of the function 'pdirichlet' is accomplished using Monte Carlo integration of the density 'dirichlet'. The estimation are based on the fact that if a variable x = (x_1, x_2, ...x_n) follows Dirichlet Distribution with parameters \alpha = \alpha_1, ... , \alpha_n (all positive reals), in short, x ~ Dir(\alpha), then x_i ~ Beta(\alpha_i, \alpha_0 - \alpha_i), where Beta(.) stands for the Beta distribution and \alpha_0 = \sum \alpha_i.

The density is computed directly from the logarithm of Dirichlet PDF log(Dir(\alpha)).

if x = (x_1, x_2, ...x_n) are observed counts, then they are transformed estimated probability p_i of the observation x_i is estimated as: p_i = (x_i + \alpha_i)/(\sum x_i + sum \alpa_i).

Value

GG PDF values (3-parameters or 4-parameters) for ddirichlet, GG probability for pdirichlet, quantiles or GG random generated values for rdirichlet.

Author(s)

Robersy Sanchez (https://genomaths.com).

References

1. Sjolander K, Karplus K, Brown M, Hughey R, Krogh A, Saira Mian I, et al. Dirichlet mixtures: A method for improved detection of weak but significant protein sequence homology. Bioinformatics. 1996;12: 327–345. doi:10.1093/bioinformatics/12.4.327.

Examples

## A random generation of numerical vectors
x <- rdirichlet(n = 1e3, alpha = rbind(
    c(2.1, 3.1, 1.2),
    c(2.5, 1.9, 1.6)
))
head(x[[1]])
lapply(x, estimateDirichDist)

### Density computation
alpha <- cbind(1:10, 5, 10:1)
x <- rdirichlet(10, c(5, 5, 10))
ddirichlet(x = x, alpha = alpha)

### Or just one vector alpha
x <- rdirichlet(n = 10, alpha = c(2.1, 3.1, 1.2))
ddirichlet(x = x, alpha = c(2.1, 3.1, 1.2))

## Compute Dirichlet probability
set.seed(123)
q <- rdirichlet(10, alpha = c(2.1, 3.2, 3.3))
pdirichlet(q, alpha = c(2.1, 3.2, 3.3))


genomaths/usefr documentation built on April 18, 2023, 3:35 a.m.