Code covered by the BSD License

# Generation of Random Variates

### James Huntley (view profile)

generates random variates from over 870 univariate distributions

dirmultnom_cdf(n, a, b, c)
```function [cdf] = dirmultnom_cdf(n, a, b, c)

%*******************************************************************************
%
%! DIRICHLET_MULTINOMIAL_PDF evaluates a Dirichlet Multinomial PDF.
%
%
%  Formula:
%
%    PDF(X)(A,B,C) = Comb(A,B,X) * ( Gamma(C_Sum) / Gamma(C_Sum+A) )
%      Product ( 1 <= I <= B ) Gamma(C(I)+X(I)) / Gamma(C(I))
%
%    where:
%
%      Comb(A,B,X) is the multinomial coefficient C( A; X(1), X(2), ..., X(B) ),
%      C_Sum = Sum ( 1 <= I <= B ) C(I)
%
%  Reference:
%
%    Kenneth Lange,
%    Mathematical and Statistical Methods for Genetic Analysis,
%    Springer, 1997, page 45.
%
%  Modified:
%
%    17 December 1999 (pdf evaluation for single vector, x),
%    30 March 2011 (pdf evaluation for all permutation vectors of 'b' outcomes
%    in 'a' trials)
%
%  Authors:
%
%    John Burkardt (Fortran 90); Jim Huntley (Matlab)
%
%  Parameters:
%
%    Input, integer X(B); X(I) counts the number of occurrences of
%    outcome I, out of the total of A trials.
%
%    Input, integer A, the total number of trials.
%
%    Input, integer B, the number of different possible outcomes on
%    one trial.
%
%    Input, integer C(B); C(I) is the Dirichlet parameter associated
%    with outcome I.
%
%    Output, real PDF, the value of the Dirichlet multinomial PDF.
%
%   NOTE: SINCE THE ORDER OF THE PERMUTATION VECTORS IS ARBITRARY,
%         THE PDF VALUES ARE SORTED INTO DESCENDING ORDER TO PRODUCE
%         THE SMOOTHEST PDF AND CDF!!!
%

sum1 = 0;
for jn = 1:n
sum1 = sum1 + dirmultnom_pdf(jn, a, b, c);
end
cdf = sum1;

return
```