Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rMultinom

Generate Multinomial Random Variables with Varying Probabilities


Description

Given a matrix of multinomial probabilities where rows correspond to observations and columns to categories (and each row sums to 1), generates a matrix with the same number of rows as has probs and with m columns. The columns represent multinomial cell numbers, and within a row the columns are all samples from the same multinomial distribution. The code is a modification of that in the impute.polyreg function in the MICE package.

Usage

rMultinom(probs, m)

Arguments

probs

matrix of probabilities

m

number of samples for each row of probs

Value

an integer matrix having m columns

See Also

Examples

set.seed(1)
w <- rMultinom(rbind(c(.1,.2,.3,.4),c(.4,.3,.2,.1)),200)
t(apply(w, 1, table)/200)

Hmisc

Harrell Miscellaneous

v4.5-0
GPL (>= 2)
Authors
Frank E Harrell Jr <fh@fharrell.com>, with contributions from Charles Dupont and many others.
Initial release
2021-02-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.