| Line 30... |
Line 30... |
| 30 |
}
|
30 |
}
|
| 31 |
\note{\code{dmultinom} is currently \emph{not vectorized} at all and has
|
31 |
\note{\code{dmultinom} is currently \emph{not vectorized} at all and has
|
| 32 |
no C interface (API); this may be amended in the future.% yes, DO THIS!
|
32 |
no C interface (API); this may be amended in the future.% yes, DO THIS!
|
| 33 |
}
|
33 |
}
|
| 34 |
\details{
|
34 |
\details{
|
| 35 |
If \code{x} is a $K$-component vector, \code{dmultinom(x, prob)} is
|
35 |
If \code{x} is a \eqn{K}-component vector, \code{dmultinom(x, prob)}
|
| 36 |
the probability
|
36 |
is the probability
|
| 37 |
\deqn{P(X_1=x_1,\ldots,X_K=x_k) = C \times \prod_{j=1}^K
|
37 |
\deqn{P(X_1=x_1,\ldots,X_K=x_k) = C \times \prod_{j=1}^K
|
| 38 |
\pi_j^{x_j}}{P(X[1]=x[1], \dots , X[K]=x[k]) = C * prod(j=1 , \dots, K) p[j]^x[j]}
|
38 |
\pi_j^{x_j}}{P(X[1]=x[1], \dots , X[K]=x[k]) = C * prod(j=1 , \dots, K) p[j]^x[j]}
|
| 39 |
where \eqn{C} is the \sQuote{multinomial coefficient}
|
39 |
where \eqn{C} is the \sQuote{multinomial coefficient}
|
| 40 |
\eqn{C = N! / (x_1! \cdots x_K!)}{C = N! / (x[1]! * \dots * x[K]!)}
|
40 |
\eqn{C = N! / (x_1! \cdots x_K!)}{C = N! / (x[1]! * \dots * x[K]!)}
|
| 41 |
and \eqn{N = \sum_{j=1}^K x_j}{N = sum(j=1, \dots, K) x[j]}.
|
41 |
and \eqn{N = \sum_{j=1}^K x_j}{N = sum(j=1, \dots, K) x[j]}.
|
| Line 52... |
Line 52... |
| 52 |
and
|
52 |
and
|
| 53 |
\eqn{P_j = \pi_j / (1 - \sum_{k=1}^{j-1} \pi_k)}{P[j] = p[j] / (1 - sum(p[1:(j-1)]))}.
|
53 |
\eqn{P_j = \pi_j / (1 - \sum_{k=1}^{j-1} \pi_k)}{P[j] = p[j] / (1 - sum(p[1:(j-1)]))}.
|
| 54 |
}
|
54 |
}
|
| 55 |
\value{
|
55 |
\value{
|
| 56 |
For \code{rmultinom()},
|
56 |
For \code{rmultinom()},
|
| 57 |
an integer \code{K x n} matrix where each column is a random vector
|
57 |
an integer \eqn{K \times n}{K x n} matrix where each column is a
|
| 58 |
generated according to the desired multinomial law, and hence summing
|
58 |
random vector generated according to the desired multinomial law, and
|
| 59 |
to \code{size}. Whereas the \emph{transposed} result would seem more
|
59 |
hence summing to \code{size}. Whereas the \emph{transposed} result
|
| 60 |
natural at first, the returned matrix is more efficient because of
|
60 |
would seem more natural at first, the returned matrix is more
|
| 61 |
columnwise storage.
|
61 |
efficient because of columnwise storage.
|
| 62 |
}
|
62 |
}
|
| 63 |
\seealso{
|
63 |
\seealso{
|
| 64 |
\link{Distributions} for standard distributions, including
|
64 |
\link{Distributions} for standard distributions, including
|
| 65 |
\code{\link{dbinom}} which is a special case conceptually.
|
65 |
\code{\link{dbinom}} which is a special case conceptually.
|
| 66 |
%% but does not return 2-vectors
|
66 |
%% but does not return 2-vectors
|