rpbinom | R Documentation |
Generates random draws from independent multinomial distributions (= product-multinomial pmultinom
).
rpbinom(prob, n) rpmultinom(prob, n, options, drop_fixed = TRUE)
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). |
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.
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.