Learn R Programming

MultiRNG (version 1.2.4)

draw.multinomial: Pseudo-Random Number Generation under Multivariate Multinomial Distribution

Description

This function implements pseudo-random number generation for a multivariate multinomial distribution with pdf

$$f(x|\theta_{1},...,\theta_{d})=\frac{N!}{\prod x_{j}!}\prod_{j=1}^{d}\theta_{j}^{x_{j}}$$

for \(0<\theta_{j}<1\), \(x_{j}\geq 0\), and \(\sum_{j=1}^{d}x_{j}=N\), where \(\theta_{1},...,\theta_{d}\) are cell probabilities and \(N\) is the size.

Usage

draw.multinomial(no.row,d,theta,N)

Arguments

no.row

Number of rows to generate.

d

Number of variables to generate.

theta

Vector of cell probabilities.

N

Sample Size. Must be at least 2.

Value

A \(no.row \times d\) matrix of generated data.

Examples

Run this code
# NOT RUN {
theta.vec=c(0.3,0.3,0.25,0.15) ; N=4
mydata=draw.multinomial(no.row=1e5,d=4,theta=c(0.3,0.3,0.25,0.15),N=4)
apply(mydata,2,mean)-N*theta.vec
# }

Run the code above in your browser using DataLab