Generate random samples from the multinomial distribution.
- 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.
- p is the second parameter of the multinomial distribution. p can be a vector with the probabilities of the categories or a matrix with each row containing the probabilities of a multinomial sample. If p has more than one row and n is non-scalar, then the number of rows of p 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 p must be a vector.
- x is a matrix of random samples from the multinomial distribution with corresponding parameters n and p. Each row corresponds to one multinomial sample. The number of columns, therefore, corresponds to the number of columns of p. If s is not specified, then the number of rows of x is the maximum of the number of elements of n and the number of rows of p. If a row of p does not sum to
1, then the corresponding row of x will contain only
NaNvalues.n = 10; p = [0.2, 0.5, 0.3]; x = mnrnd (n, p); n = 10 * ones (3, 1); p = [0.2, 0.5, 0.3]; x = mnrnd (n, p); n = (1:2)'; p = [0.2, 0.5, 0.3; 0.1, 0.1, 0.8]; x = mnrnd (n, p);
- Wendy L. Martinez and Angel R. Martinez. Computational Statistics Handbook with MATLAB. Appendix E, pages 547-557, Chapman & Hall/CRC, 2001.
- Merran Evans, Nicholas Hastings and Brian Peacock. Statistical Distributions. pages 134-136, Wiley, New York, third edition, 2000.