EVOLUTION-MANAGER
Edit File: Binomial.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 Binomial 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 Binomial {stats}"><tr><td>Binomial {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>The Binomial Distribution</h2> <h3>Description</h3> <p>Density, distribution function, quantile function and random generation for the binomial distribution with parameters <code>size</code> and <code>prob</code>. </p> <p>This is conventionally interpreted as the number of ‘successes’ in <code>size</code> trials. </p> <h3>Usage</h3> <pre> dbinom(x, size, prob, log = FALSE) pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE) qbinom(p, size, prob, lower.tail = TRUE, log.p = FALSE) rbinom(n, size, prob) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, q</code></td> <td> <p>vector of quantiles.</p> </td></tr> <tr valign="top"><td><code>p</code></td> <td> <p>vector of probabilities.</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>number of observations. If <code>length(n) > 1</code>, the length is taken to be the number required.</p> </td></tr> <tr valign="top"><td><code>size</code></td> <td> <p>number of trials (zero or more).</p> </td></tr> <tr valign="top"><td><code>prob</code></td> <td> <p>probability of success on each trial.</p> </td></tr> <tr valign="top"><td><code>log, log.p</code></td> <td> <p>logical; if TRUE, probabilities p are given as log(p).</p> </td></tr> <tr valign="top"><td><code>lower.tail</code></td> <td> <p>logical; if TRUE (default), probabilities are <i>P[X ≤ x]</i>, otherwise, <i>P[X > x]</i>.</p> </td></tr> </table> <h3>Details</h3> <p>The binomial distribution with <code>size</code> <i>= n</i> and <code>prob</code> <i>= p</i> has density </p> <p style="text-align: center;"><i> p(x) = choose(n, x) p^x (1-p)^(n-x)</i></p> <p>for <i>x = 0, …, n</i>. Note that binomial <em>coefficients</em> can be computed by <code><a href="../../base/html/Special.html">choose</a></code> in <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>. </p> <p>If an element of <code>x</code> is not integer, the result of <code>dbinom</code> is zero, with a warning. </p> <p><i>p(x)</i> is computed using Loader's algorithm, see the reference below. </p> <p>The quantile is defined as the smallest value <i>x</i> such that <i>F(x) ≥ p</i>, where <i>F</i> is the distribution function. </p> <h3>Value</h3> <p><code>dbinom</code> gives the density, <code>pbinom</code> gives the distribution function, <code>qbinom</code> gives the quantile function and <code>rbinom</code> generates random deviates. </p> <p>If <code>size</code> is not an integer, <code>NaN</code> is returned. </p> <p>The length of the result is determined by <code>n</code> for <code>rbinom</code>, and is the maximum of the lengths of the numerical arguments for the other functions. </p> <p>The numerical arguments other than <code>n</code> are recycled to the length of the result. Only the first elements of the logical arguments are used. </p> <h3>Source</h3> <p>For <code>dbinom</code> a saddle-point expansion is used: see </p> <p>Catherine Loader (2000). <em>Fast and Accurate Computation of Binomial Probabilities</em>; available from <a href="http://www.herine.net/stat/software/dbinom.html">http://www.herine.net/stat/software/dbinom.html</a>. </p> <p><code>pbinom</code> uses <code><a href="Beta.html">pbeta</a></code>. </p> <p><code>qbinom</code> uses the Cornish–Fisher Expansion to include a skewness correction to a normal approximation, followed by a search. </p> <p><code>rbinom</code> (for <code>size < .Machine$integer.max</code>) is based on </p> <p>Kachitvichyanukul, V. and Schmeiser, B. W. (1988) Binomial random variate generation. <em>Communications of the ACM</em>, <b>31</b>, 216–222. </p> <p>For larger values it uses inversion. </p> <h3>See Also</h3> <p><a href="Distributions.html">Distributions</a> for other standard distributions, including <code><a href="NegBinomial.html">dnbinom</a></code> for the negative binomial, and <code><a href="Poisson.html">dpois</a></code> for the Poisson distribution. </p> <h3>Examples</h3> <pre> require(graphics) # Compute P(45 < X < 55) for X Binomial(100,0.5) sum(dbinom(46:54, 100, 0.5)) ## Using "log = TRUE" for an extended range : n <- 2000 k <- seq(0, n, by = 20) plot (k, dbinom(k, n, pi/10, log = TRUE), type = "l", ylab = "log density", main = "dbinom(*, log=TRUE) is better than log(dbinom(*))") lines(k, log(dbinom(k, n, pi/10)), col = "red", lwd = 2) ## extreme points are omitted since dbinom gives 0. mtext("dbinom(k, log=TRUE)", adj = 0) mtext("extended range", adj = 0, line = -1, font = 4) mtext("log(dbinom(k))", col = "red", adj = 1) </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>