EVOLUTION-MANAGER
Edit File: Multinom.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: The Multinomial Distribution</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for Multinom {stats}"><tr><td>Multinom {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>The Multinomial Distribution</h2> <h3>Description</h3> <p>Generate multinomially distributed random number vectors and compute multinomial probabilities. </p> <h3>Usage</h3> <pre> rmultinom(n, size, prob) dmultinom(x, size = NULL, prob, log = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>vector of length <i>K</i> of integers in <code>0:size</code>.</p> </td></tr> </table> <table summary="R argblock"> <tr valign="top"><td><code>n</code></td> <td> <p>number of random vectors to draw.</p> </td></tr> <tr valign="top"><td><code>size</code></td> <td> <p>integer, say <i>N</i>, specifying the total number of objects that are put into <i>K</i> boxes in the typical multinomial experiment. For <code>dmultinom</code>, it defaults to <code>sum(x)</code>.</p> </td></tr> <tr valign="top"><td><code>prob</code></td> <td> <p>numeric non-negative vector of length <i>K</i>, specifying the probability for the <i>K</i> classes; is internally normalized to sum 1. Infinite and missing values are not allowed.</p> </td></tr> <tr valign="top"><td><code>log</code></td> <td> <p>logical; if TRUE, log probabilities are computed.</p> </td></tr> </table> <h3>Details</h3> <p>If <code>x</code> is a <i>K</i>-component vector, <code>dmultinom(x, prob)</code> is the probability </p> <p style="text-align: center;"><i>P(X[1]=x[1], … , X[K]=x[k]) = C * prod(j=1 , …, K) p[j]^x[j]</i></p> <p>where <i>C</i> is the ‘multinomial coefficient’ <i>C = N! / (x[1]! * … * x[K]!)</i> and <i>N = sum(j=1, …, K) x[j]</i>. <br /> By definition, each component <i>X[j]</i> is binomially distributed as <code>Bin(size, prob[j])</code> for <i>j = 1, …, K</i>. </p> <p>The <code>rmultinom()</code> algorithm draws binomials <i>X[j]</i> from <i>Bin(n[j], P[j])</i> sequentially, where <i>n[1] = N</i> (N := <code>size</code>), <i>P[1] = p[1]</i> (<i>p</i> is <code>prob</code> scaled to sum 1), and for <i>j ≥ 2</i>, recursively, <i>n[j] = N - sum(k=1, …, j-1) X[k]</i> and <i>P[j] = p[j] / (1 - sum(p[1:(j-1)]))</i>. </p> <h3>Value</h3> <p>For <code>rmultinom()</code>, an integer <i>K x n</i> matrix where each column is a random vector generated according to the desired multinomial law, and hence summing to <code>size</code>. Whereas the <em>transposed</em> result would seem more natural at first, the returned matrix is more efficient because of columnwise storage. </p> <h3>Note</h3> <p><code>dmultinom</code> is currently <em>not vectorized</em> at all and has no C interface (API); this may be amended in the future. </p> <h3>See Also</h3> <p><a href="Distributions.html">Distributions</a> for standard distributions, including <code><a href="Binomial.html">dbinom</a></code> which is a special case conceptually. </p> <h3>Examples</h3> <pre> rmultinom(10, size = 12, prob = c(0.1,0.2,0.8)) pr <- c(1,3,6,10) # normalization not necessary for generation rmultinom(10, 20, prob = pr) ## all possible outcomes of Multinom(N = 3, K = 3) X <- t(as.matrix(expand.grid(0:3, 0:3))); X <- X[, colSums(X) <= 3] X <- rbind(X, 3:3 - colSums(X)); dimnames(X) <- list(letters[1:3], NULL) X round(apply(X, 2, function(x) dmultinom(x, prob = c(1,2,5))), 3) </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>