Syntax Supported by the IML Procedure and the iml Action

RANDDIRICHLET Function

RANDDIRICHLET (N, Shape) ;

This function is supported by the IML procedure and the iml action.

The RANDDIRICHLET function is part of the IMLMLIB library. The RANDDIRICHLET function generates a random sample from a Dirichlet distribution, which is a multivariate generalization of the beta distribution.

The input parameters are as follows:

N

is the number of observations to sample.

Shape

is a 1 times left-parenthesis p plus 1 right-parenthesis vector of shape parameters for the distribution, Shape left-bracket i right-bracket greater-than 0.

The RANDDIRICHLET function returns an upper N times p matrix that contains N random draws from the Dirichlet distribution.

If upper X equals StartSet upper X 1 upper X 2 ellipsis upper X Subscript p Baseline EndSet with sigma-summation Underscript i equals 1 Overscript p Endscripts upper X Subscript i Baseline less-than 1 and upper X Subscript i Baseline greater-than 0 follows a Dirichlet distribution with shape parameter alpha equals StartSet alpha 1 alpha 2 ellipsis alpha Subscript p plus 1 Baseline EndSet, then

  • the probability density function for x is

    f left-parenthesis x semicolon alpha right-parenthesis equals StartFraction normal upper Gamma left-parenthesis sigma-summation Underscript i equals 1 Overscript p plus 1 Endscripts alpha Subscript i Baseline right-parenthesis Over product Underscript i equals 1 Overscript p plus 1 Endscripts normal upper Gamma left-parenthesis alpha Subscript i Baseline right-parenthesis EndFraction product Underscript i equals 1 Overscript p Endscripts x Subscript i Baseline Superscript alpha Super Subscript i Superscript minus 1 Baseline left-parenthesis 1 minus x 1 minus x 2 minus ellipsis minus x Subscript p Baseline right-parenthesis Superscript alpha Super Subscript p plus 1 Superscript minus 1
  • if p equals 1, the probability distribution is a beta distribution.

  • if alpha 0 equals normal upper Sigma Subscript i equals 1 Superscript p plus 1 Baseline alpha Subscript i, then

    • the expected value of upper X Subscript i is alpha Subscript i Baseline slash alpha 0.

    • the variance of upper X Subscript i is alpha Subscript i Baseline left-parenthesis alpha 0 minus alpha Subscript i Baseline right-parenthesis slash left-parenthesis alpha 0 squared left-parenthesis alpha 0 plus 1 right-parenthesis right-parenthesis.

    • the covariance of upper X Subscript i and upper X Subscript j is minus alpha Subscript i Baseline alpha Subscript j slash left-parenthesis alpha 0 squared left-parenthesis alpha 0 plus 1 right-parenthesis right-parenthesis.

The following example generates 1,000 samples from a two-dimensional Dirichlet distribution. Each row of the returned matrix x is a row vector sampled from the Dirichlet distribution. The following example computes the sample mean and covariance and compares them with the expected values:

call randseed(1);
n = 1000;
Shape = {2, 1, 1};
x = RandDirichlet(n,Shape);
d = nrow(Shape)-1;
s = Shape[1:d];
Shape0 = sum(Shape);
Mean = s`/Shape0;
Cov = -s*s` / (Shape0##2*(Shape0+1));
/* replace diagonal elements with variance */
Variance = s#(Shape0-s) / (Shape0##2*(Shape0+1));
do i = 1 to d;
   Cov[i,i] = Variance[i];
end;

SampleMean = mean(x);
SampleCov = cov(x);
print SampleMean Mean, SampleCov Cov;

Figure 304: Estimated Mean and Covariance Matrix

SampleMean Mean 
0.49924490.24856770.50.25

SampleCov Cov 
0.0502652-0.0260850.05-0.025
-0.0260850.0393922-0.0250.0375


For further details about sampling from the Dirichlet distribution, see Kotz, Balakrishnan, and Johnson (2000); Gentle (2003); or Devroye (1986).

Last updated: March 08, 2024