Posnegbin {VGAM}R Documentation

Positive-Negative Binomial Distribution

Description

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

Usage

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

Arguments

x, q vector of quantiles.
p vector of probabilities.
n number of random values to return. If length(n) > 1 then the length is taken to be the number required.
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.

Details

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

munb / (1-p(0))

where munb the mean of an ordinary negative binomial distribution. The arguments of rposnegbin() are fed into rnbinom until n positive values are obtained.

Value

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

Note

The running time of rposnegbin() is slow when munb is very close to zero.

Author(s)

T. W. Yee

References

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

posnegbinomial, rnbinom, zanegbinomial.

Examples

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=size, lower.tail=FALSE) # same as before

x <- (-1):17
(ii = dposnegbin(x, munb=munb, size=size))
max(abs(cumsum(ii) - pposnegbin(x, munb=munb, size=size)))  # Should be 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=paste("dposnegbin(munb=", munb, ", size=", size, ") (blue) vs",
                        " dnbinom(mu=", munb, ", size=", size, ") (green)", sep=""),
        names.arg = as.character(x))
## End(Not run)

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

[Package VGAM version 0.7-9 Index]