posnegbinUC: Positive-Negative Binomial Distribution

PosnegbinR Documentation

Positive-Negative Binomial Distribution


Density, distribution function, quantile function and random generation for the positive-negative binomial distribution.


dposnegbin(x, size, prob = NULL, munb = NULL, log = FALSE)
pposnegbin(q, size, prob = NULL, munb = NULL,
           lower.tail = TRUE, log.p = FALSE)
qposnegbin(p, size, prob = NULL, munb = NULL)
rposnegbin(n, size, prob = NULL, munb = NULL)


x, q

vector of quantiles.


vector of probabilities.


number of observations. Fed into runif.

size, prob, munb, log

Same arguments as that of an ordinary negative binomial distribution (see dnbinom). Some arguments have been renamed slightly.

Short vectors are recycled. The parameter 1/size is known as a dispersion parameter; as size approaches infinity, the negative binomial distribution approaches a Poisson distribution.

Note that prob must lie in (0,1), otherwise a NaN is returned.

log.p, lower.tail

Same arguments as that of an ordinary negative binomial distribution (see pnbinom).


The positive-negative binomial distribution is a negative binomial distribution but with the probability of a zero being zero. The other probabilities are scaled to add to unity. The mean therefore is

\mu / (1-p(0))

where \mu the mean of an ordinary negative binomial distribution.


dposnegbin gives the density, pposnegbin gives the distribution function, qposnegbin gives the quantile function, and rposnegbin generates n random deviates.


These functions are or are likely to be deprecated. Use Gaitdnbinom instead.


T. W. Yee


Welsh, A. H., Cunningham, R. B., Donnelly, C. F. and Lindenmayer, D. B. (1996). Modelling the abundances of rare species: statistical models for counts with extra zeros. Ecological Modelling, 88, 297–308.

See Also

Gaitdnbinom, posnegbinomial, zanegbinomial, zinegbinomial, rnbinom.


munb <- 5; size <- 4; n <- 1000
table(y <- rposnegbin(n, munb = munb, size = size))
mean(y)  # Sample mean
munb / (1 - (size / (size + munb))^size)  # Population mean
munb / pnbinom(0, mu = munb, size, lower.tail = FALSE)  # Same

x <- (-1):17
(ii <- dposnegbin(x, munb = munb, size = size))
max(abs(cumsum(ii) - pposnegbin(x, munb = munb, size)))  # 0?

## Not run:  x <- 0:10
barplot(rbind(dposnegbin(x, munb = munb, size = size),
                 dnbinom(x, mu   = munb, size = size)),
   beside = TRUE, col = c("blue","green"),
   main = paste0("dposnegbin(munb = ", munb, ", size = ", size,
                 ") (blue) vs dnbinom(mu = ", munb,
                 ", size = ", size, ") (green)"),
   names.arg = as.character(x)) 
## End(Not run)

# Another test for pposnegbin()
nn <- 5000
mytab <- cumsum(table(rposnegbin(nn, munb = munb, size))) / nn
myans <- pposnegbin(sort(as.numeric(names(mytab))), munb = munb, size)
max(abs(mytab - myans))  # Should be 0

VGAMdata documentation built on Sept. 18, 2023, 9:08 a.m.