Statistics: mnrnd

### Function Reference: `mnrnd`

statistics: r = mnrnd (n, pk)
statistics: r = mnrnd (n, pk, s)

Random arrays from the multinomial distribution.

### Arguments

- n is the first parameter of the multinomial distribution. n can be scalar or a vector containing the number of trials of each multinomial sample. The elements of n must be non-negative integers.
- pk is the second parameter of the multinomial distribution. pk can be a vector with the probabilities of the categories or a matrix with each row containing the probabilities of a multinomial sample. If pk has more than one row and n is non-scalar, then the number of rows of pk must match the number of elements of n.
- s is the number of multinomial samples to be generated. s must be a non-negative integer. If s is specified, then n must be scalar and pk must be a vector.

### Return values

- r is a matrix of random samples from the multinomial distribution with corresponding parameters n and pk. Each row corresponds to one multinomial sample. The number of columns, therefore, corresponds to the number of columns of pk. If s is not specified, then the number of rows of r is the maximum of the number of elements of n and the number of rows of pk. If a row of pk does not sum to `1`, then the corresponding row of r will contain only `NaN` values.

### Examples

     n = 10;
     pk = [0.2, 0.5, 0.3];
     r = mnrnd (n, pk);
     n = 10 * ones (3, 1);
     pk = [0.2, 0.5, 0.3];
     r = mnrnd (n, pk);
     n = (1:2)';
     pk = [0.2, 0.5, 0.3; 0.1, 0.1, 0.8];
     r = mnrnd (n, pk);

### References

1. Wendy L. Martinez and Angel R. Martinez. Computational Statistics Handbook with MATLAB. Appendix E, pages 547-557, Chapman & Hall/CRC, 2001.
2. Merran Evans, Nicholas Hastings and Brian Peacock. Statistical Distributions. pages 134-136, Wiley, New York, third edition, 2000.

See also: mnpdf

Source Code: mnrnd