| multinom {multicool} | R Documentation |
This function calculates the number of permutations of a multiset, this being the multinomial coefficient. If a set X contains k unique elements x_1, x_2, \ldots, x_k with associate counts (or multiplicities) of n_1, n_2, \ldots, n_k, then this function returns
\frac{n!}{n_1!n_2!\ldots n_k!}
where n = \sum_{i=1}{k}n_i.
multinom(x, counts = FALSE)
x |
Either a multiset (with one or more potentially non-unique elements), or if |
counts |
if |
multinom depends on C++ code written by Dave Barber which can be found at http://home.comcast.net/~tamivox/dave/multinomial/index.html. The code may require the STL algorithm library to be included in order to compile it.
A single integer representing the multinomial coefficient for the given multiset, or given set of multiplicities.
James M. Curran, Dave Barber
http://home.comcast.net/~tamivox/dave/multinomial/index.html
## an example with a multiset X = (a,a,a,b,b,c)
## There are 3 a s, 2 b s and 1 c, so the answer should be
## (3+2+1)!/(3!2!1!) = 6!/3!2!1! = 60
x = rep(letters[1:3],3:1)
multinom(x)
## in this example x is a vector of counts
## the answer should be the same as above as x = c(3,2,1)
x = rep(letters[1:3],3:1)
x = as.vector(table(x)) #coerce x into a vector of counts
multinom(x, counts = TRUE)