Multinomial
The Multinomial Distribution

Description

Generates a random sample from the multinomial distribution and calculates a multinomial density function.

Usage

rmultinom(n, size, prob)  # random sample
dmultinom(x, size = NULL, prob, log = FALSE) # density

Arguments

n a nonnegative integer that specifies the number of random samples requested.
x a numeric vector of nonnegative integral values the length of prob giving the number of items of each type in the sample.
size a nonnegative integer indicating the number of items in each sample.
prob a numeric vector specifying the relative probability of each type of item being selected on each draw. These are divided by their sum to form probabilities. They must all be nonnegative and at least one must be positive.
log a logical value. If TRUE, returns the logarithm of the density. If FALSE (the default), returns the density.
Value
returns the density (dmultinom) or a random sample (rmultinom) for the Multinomial distribution with the parameters size and prob. The random sample is a matrix with length(prob) rows and n columns.
See Also
Binomial, NegBinomial, lgamma.
Examples
rmultinom(5, size = 10, prob=c(0.1,0.2,0.8))
dmultinom(c(1, 2, 0), prob = c(1/8, 2/8, 5/8))
dmultinom(c(1, 2, 0), prob = c(1,2,5))
dmultinom(c(1, 2, 0), prob = c(1,2,5), log = TRUE)
# impossible to have x>0 when corresponding prob==0:
dmultinom(c(1, 2, 3), prob = c(1,2,0))

Package stats version 6.1.1-7
Package Index