Dirichlet | R Documentation |
Density function and random generation for Dirichlet distribution with
parameter vector alpha
.
ddirichlet(x, alpha, log = FALSE, tol = 1e-10) rdirichlet(n, alpha)
x |
vector (or matrix) of points in sample space. |
alpha |
vector of Dirichlet hyper parameters. |
log |
logical; if TRUE, natural logarithm of density is returned. |
tol |
tolerance of vectors not summing to 1 and negative values. |
n |
number of random variables to be generated. |
If x
is a matrix, each row is taken to be a different point whose
density is to be evaluated. If the number of columns in (or length of, in
the
alpha
, the
vector sum to 1.
The k-dimensional Dirichlet distribution has density
Gamma (alpha_1 + ... + alpha_k)*(Gamma(alpha_1)*...*Gamma(alpha_k))^{-1}*x_1^{alpha_1-1}*...*x_k^{alpha_k-1}
assuming that x_i > 0 and x_1 + ... + x_k = 1, and zero otherwise.
If the sum of row entries in x
differs from 1 by more than
tol
,
is assumed to be
rdirichlet
returns a matrix, each row of which is an
independent draw
alpha
.
ddirichlet
returns a vector, each entry being the density of the
corresponding row of x
. If x
is a vector, then the output
will have length 1.
Robin Evans
https://en.wikipedia.org/wiki/Dirichlet_distribution
x = rdirichlet(10, c(1,2,3)) x # Find densities at random points. ddirichlet(x, c(1,2,3)) # Last column to be inferred. ddirichlet(x[,c(1,2)], c(1,2,3)) ddirichlet(x, matrix(c(1,2,3), 10, 3, byrow=TRUE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.