rpbinom {multinomineq} | R Documentation |
Random Generation for Independent Multinomial Distributions
Description
Generates random draws from independent multinomial distributions (= product-multinomial pmultinom
).
Usage
rpbinom(prob, n)
rpmultinom(prob, n, options, drop_fixed = TRUE)
Arguments
prob |
vector with probabilities or a matrix with one probability vector per row.
For |
n |
integer vector, specifying the number of trials for each binomial/multinomial distribution
Note that this is the |
options |
number of observable categories/probabilities for each item
type/multinomial distribution, e.g., |
drop_fixed |
whether the output matrix includes the last probability for each category (which is not a free parameter since probabilities must sum to one). |
Value
a matrix with one vector of frequencies per row. For rpbinom
, only
the frequencies of 'successes' are returned, whereas for rpmultinom
, the
complete frequency vectors (which sum to n
within each option) are returned.
Examples
# 3 binomials
rpbinom(prob = c(.2, .7, .9), n = c(10, 50, 30))
# 2 and 3 options: [a1,a2, b1,b2,b3]
rpmultinom(
prob = c(a1 = .5, b1 = .3, b2 = .6),
n = c(10, 20), options = c(2, 3)
)
# or:
rpmultinom(
prob = c(a1 = .5, a2 = .5, b1 = .3, b2 = .6, b3 = .1),
n = c(10, 20), options = c(2, 3),
drop_fixed = FALSE
)
# matrix with one probability vector per row:
p <- rpdirichlet(
n = 6, alpha = c(1, 1, 1, 1, 1),
options = c(2, 3)
)
rpmultinom(prob = p, n = c(20, 50), options = c(2, 3))