dmultinomial {mc2d}R Documentation

The Vectorized Multinomial Distribution

Description

Generate multinomially distributed random number vectors and compute multinomial probabilities.

Usage

dmultinomial(x, size=NULL, prob, log=FALSE)
rmultinomial(n, size, prob)

Arguments

x Vector of length K of integers in 0:size.
n Number of random vectors to draw.
size A vector of integers, say N, specifying the total number of objects that are put into K boxes in the typical multinomial experiment. For dmultinom, it defaults to sum(x). The first element correspond to the vector prob or the first row of prob, ...
prob Numeric non-negative vector of length K, or matrix of size (x x K) specifying the probability for the K classes; is internally normalized to sum 1.
log Logical; if TRUE, log probabilities are computed.

Details

This function is the vectorized version of rmultinom and dmultinom. Recycling is permitted.

Examples

prob <- c(1, 2, 7)
rmultinomial(4, 1000, prob)
rmultinomial(4, c(10, 100, 1000, 10000), prob)

## rmultinomial used with mcstoc
## (uncertain size and prob)
s <- mcstoc(rpois, "U", lambda=50)
p <- mcstoc(rdirichlet, "U", nvariates=3, alpha=c(4, 10, 20))
mcstoc(rmultinomial, "VU", nvariates=3, size=s, prob=p)


[Package mc2d version 0.1-6 Index]