dmultinomial: The Vectorized Multinomial Distribution

dmultinomialR Documentation

The Vectorized Multinomial Distribution

Description

Generate multinomially distributed random number vectors and compute multinomial probabilities. These functions are the vectorized versions of rmultinom and dmultinom. Recycling is permitted.

Usage

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

rmultinomial(n, size, prob)

Arguments

x

vector or matrix of length (or ncol) K of integers in ‘⁠0:size⁠’.

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 ‘⁠dmultinomial⁠’, it defaults to ‘⁠sum(x)⁠’. The first element corresponds to the vector ‘⁠prob⁠’ or the first row of ‘⁠prob⁠’, ...

prob

numeric non-negative vector of length K, or matrix of size ‘⁠(n x K)⁠’ specifying the probability for the K classes; is internally normalized to sum 1.

log

logical; if ‘⁠TRUE⁠’, log probabilities are computed.

n

number of random vectors to draw.

Examples

x <- c(100, 200, 700)
x1 <- matrix(c(100,200,700, 200,100,700, 700,200,100), byrow=TRUE, ncol=3)
p <- c(1, 2, 7)
p1 <- matrix(c(1,2,7, 2,1,7, 7,2,1), byrow=TRUE, ncol=3)
dmultinomial(x1, prob=p)
## is equivalent to
c(dmultinom(x1[1,], prob=p),
  dmultinom(x1[2,], prob=p),
  dmultinom(x1[3,], prob=p))

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

mc2d documentation built on Oct. 23, 2026, 1:06 a.m.