InfluentialPoints.com
Biology, images, analysis, design...
Use/Abuse Principles How To Related
"It has long been an axiom of mine that the little things are infinitely the most important" (Sherlock Holmes)

Search this site

 

 

Negative binomial distribution functions using R

Negative binomial mass probability function

R's dnbinom function returns the probability of observing a count (f), as predicted by the negative binomial model, given a 'shape' (or 'size') parameter (k) and mean (m).

For example:

Gave:

[1] 0.0746496

    Note:
  • Although shape parameters equal to zero and infinity are theoretically possible, these functions will not accept those limiting values.
      When k is above around 10^10, use a Poisson function (with the same mean).

  • To obtain the expected proportion for each of a range of outcomes, you need to use an ordered list of counts instead of a single value, for example as dnbinom(0:10, s=k, mu=m)

  • If you wish to fit the negative binomial distribution to a set of observed frequencies, and variable y contains those frequencies, given an estimate of k, you could find their expected number of each count using dnbinom(0:max(y), s=k, mu=mean(y))*tot(y)

  • Negative binomial cumulative distribution function
      R's pnbinom function returns the probability of observing a count less than or equal to a given count.

  • Negative binomial inverse distribution function
      R's qnbinom function does the opposite of its pnbinom function - that is it returns the relevent quantile (again a count).

  • Negative binomial random function
      R's rnbinom function gives 1 (or more) counts randomly selected from the specified negative binomial distribution(s).

      For example, rnbinom(5, s=3, m=2) would provide 5 counts randomly selected from a negative binomial distribution whose mean is 2, and shape parameter (k) is 3.