EVOLUTION-MANAGER
Edit File: NegBinomial.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 Negative 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 NegBinomial {stats}"><tr><td>NegBinomial {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>The Negative Binomial Distribution</h2> <h3>Description</h3> <p>Density, distribution function, quantile function and random generation for the negative binomial distribution with parameters <code>size</code> and <code>prob</code>. </p> <h3>Usage</h3> <pre> dnbinom(x, size, prob, mu, log = FALSE) pnbinom(q, size, prob, mu, lower.tail = TRUE, log.p = FALSE) qnbinom(p, size, prob, mu, lower.tail = TRUE, log.p = FALSE) rnbinom(n, size, prob, mu) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>vector of (non-negative integer) quantiles.</p> </td></tr> <tr valign="top"><td><code>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>target for number of successful trials, or dispersion parameter (the shape parameter of the gamma mixing distribution). Must be strictly positive, need not be integer.</p> </td></tr> <tr valign="top"><td><code>prob</code></td> <td> <p>probability of success in each trial. <code>0 < prob <= 1</code>.</p> </td></tr> <tr valign="top"><td><code>mu</code></td> <td> <p>alternative parametrization via mean: see ‘Details’.</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 negative 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> Γ(x+n)/(Γ(n) x!) p^n (1-p)^x</i></p> <p>for <i>x = 0, 1, 2, …</i>, <i>n > 0</i> and <i>0 < p ≤ 1</i>. </p> <p>This represents the number of failures which occur in a sequence of Bernoulli trials before a target number of successes is reached. The mean is <i>μ = n(1-p)/p</i> and variance <i>n(1-p)/p^2</i>. </p> <p>A negative binomial distribution can also arise as a mixture of Poisson distributions with mean distributed as a gamma distribution (see <code><a href="GammaDist.html">pgamma</a></code>) with scale parameter <code>(1 - prob)/prob</code> and shape parameter <code>size</code>. (This definition allows non-integer values of <code>size</code>.) </p> <p>An alternative parametrization (often used in ecology) is by the <em>mean</em> <code>mu</code> (see above), and <code>size</code>, the <em>dispersion parameter</em>, where <code>prob</code> = <code>size/(size+mu)</code>. The variance is <code>mu + mu^2/size</code> in this parametrization. </p> <p>If an element of <code>x</code> is not integer, the result of <code>dnbinom</code> is zero, with a warning. </p> <p>The case <code>size == 0</code> is the distribution concentrated at zero. This is the limiting distribution for <code>size</code> approaching zero, even if <code>mu</code> rather than <code>prob</code> is held constant. Notice though, that the mean of the limit distribution is 0, whatever the value of <code>mu</code>. </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>dnbinom</code> gives the density, <code>pnbinom</code> gives the distribution function, <code>qnbinom</code> gives the quantile function, and <code>rnbinom</code> generates random deviates. </p> <p>Invalid <code>size</code> or <code>prob</code> will result in return value <code>NaN</code>, with a warning. </p> <p>The length of the result is determined by <code>n</code> for <code>rnbinom</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><code>dnbinom</code> computes via binomial probabilities, using code contributed by Catherine Loader (see <code><a href="Binomial.html">dbinom</a></code>). </p> <p><code>pnbinom</code> uses <code><a href="Beta.html">pbeta</a></code>. </p> <p><code>qnbinom</code> uses the Cornish–Fisher Expansion to include a skewness correction to a normal approximation, followed by a search. </p> <p><code>rnbinom</code> uses the derivation as a gamma mixture of Poissons, see </p> <p>Devroye, L. (1986) <em>Non-Uniform Random Variate Generation.</em> Springer-Verlag, New York. Page 480. </p> <h3>See Also</h3> <p><a href="Distributions.html">Distributions</a> for standard distributions, including <code><a href="Binomial.html">dbinom</a></code> for the binomial, <code><a href="Poisson.html">dpois</a></code> for the Poisson and <code><a href="Geometric.html">dgeom</a></code> for the geometric distribution, which is a special case of the negative binomial. </p> <h3>Examples</h3> <pre> require(graphics) x <- 0:11 dnbinom(x, size = 1, prob = 1/2) * 2^(1 + x) # == 1 126 / dnbinom(0:8, size = 2, prob = 1/2) #- theoretically integer ## Cumulative ('p') = Sum of discrete prob.s ('d'); Relative error : summary(1 - cumsum(dnbinom(x, size = 2, prob = 1/2)) / pnbinom(x, size = 2, prob = 1/2)) x <- 0:15 size <- (1:20)/4 persp(x, size, dnb <- outer(x, size, function(x,s) dnbinom(x, s, prob = 0.4)), xlab = "x", ylab = "s", zlab = "density", theta = 150) title(tit <- "negative binomial density(x,s, pr = 0.4) vs. x & s") image (x, size, log10(dnb), main = paste("log [", tit, "]")) contour(x, size, log10(dnb), add = TRUE) ## Alternative parametrization x1 <- rnbinom(500, mu = 4, size = 1) x2 <- rnbinom(500, mu = 4, size = 10) x3 <- rnbinom(500, mu = 4, size = 100) h1 <- hist(x1, breaks = 20, plot = FALSE) h2 <- hist(x2, breaks = h1$breaks, plot = FALSE) h3 <- hist(x3, breaks = h1$breaks, plot = FALSE) barplot(rbind(h1$counts, h2$counts, h3$counts), beside = TRUE, col = c("red","blue","cyan"), names.arg = round(h1$breaks[-length(h1$breaks)])) </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>