[Rd] rmultinom() -- how \\ via own C code?

Kurt Hornik Kurt.Hornik@wu-wien.ac.at
Mon Jan 27 23:31:03 2003

>>>>> Ben Bolker writes:

>   I use multivariate random values frequently -- multinomial (using
> code contributed to the R-list by Ian Wilson), Dirichlet (using ratios
> of gamma/sum(gamma)), multivariate normal (using mvrnorm() from MASS,
> which I wish were called rmvnorm instead!)  I have functions for them
> in some of my home-brewed packages.  I would vote for adding some of
> them to the recommended packages.

>   Many multinomial distributions have matrices or vectors of
> arguments: if one wants to generate multiple variates with different
> parameters, how should these arguments be stacked?  e.g. for
> multinomial deviates, should one be able to specify an m by p matrix
> for "prob" where m is a divisor of n?

I have recently added code to r-devel to generate random two-way tables
with given row and column totals.  This works as

	r2dtable(n, r, c)

where r and c are the row and column totals, and returns a *list* of
length n.  If each draw gives a random 'vector' one can stack the
results into a matrix as does e.g. mvrnorm in MASS, or one could return
a list; in the general case, I think we always want a list of random

>   The other minor point is that I usually give d- and r-functions for
> these distributions but not p- and q- (since I don't really want to
> think about defining, much less computing, multidimensional cumulative
> distributions ...)

[Although e.g. simulating the distribution of random tables with given
marginals and doing computations on that would be rather nice ...]