posnegbinomial {VGAM} | R Documentation |
Maximum likelihood estimation of the two parameters of a positive negative binomial distribution.
posnegbinomial(lmunb = "loge", lsize = "loge", isize = NULL, zero = -2, nsimEIM = 250, ishrinkage = 0.95, imethod = 1)
lmunb |
Link function applied to the |
lsize |
Parameter link function applied to the dispersion parameter,
called |
isize |
Optional initial value for |
nsimEIM, zero |
|
ishrinkage, imethod |
See |
The positive negative binomial distribution is an ordinary negative binomial distribution but with the probability of a zero response being zero. The other probabilities are scaled to sum to unity.
This family function is based on negbinomial
and most
details can be found there. To avoid confusion, the parameter
munb
here corresponds to the mean of an ordinary negative
binomial distribution negbinomial
. The mean of
posnegbinomial
is
munb / (1-p(0))
where p(0) = (k/(k + munb))^k is the probability an ordinary negative binomial distribution has a zero value.
The parameters munb
and k
are not independent in the
positive negative binomial distribution, whereas they are in the
ordinary negative binomial distribution.
This function handles multivariate responses, so that a matrix
can be used as the response. The number of columns is the number
of species, say, and setting zero = -2
means that all
species have a k
equalling a (different) intercept only.
An object of class "vglmff"
(see vglmff-class
).
The object is used by modelling functions such as vglm
,
rrvglm
and vgam
.
The Poisson model corresponds to k
equalling infinity.
If the data is Poisson or close to Poisson, numerical problems may
occur. Possibly a loglog link could be added in the future to try help
handle this problem.
This VGAM family function is computationally expensive
and usually runs slowly;
setting trace = TRUE
is useful for monitoring convergence.
This family function handles multiple responses.
Thomas W. Yee
Barry, S. C. and Welsh, A. H. (2002) Generalized additive modelling and zero inflated count data. Ecological Modelling, 157, 179–188.
Williamson, E. and Bretherton, M. H. (1964) Tables of the logarithmic series distribution. Annals of Mathematical Statistics, 35, 284–297.
rposnegbin
,
pospoisson
,
negbinomial
,
zanegbinomial
,
rnbinom
,
CommonVGAMffArguments
,
corbet
,
logff
,
simulate.vlm
.
## Not run: pdata <- data.frame(x2 = runif(nn <- 1000)) pdata <- transform(pdata, y1 = rposnegbin(nn, munb = exp(0+2*x2), size = exp(1)), y2 = rposnegbin(nn, munb = exp(1+2*x2), size = exp(3))) fit <- vglm(cbind(y1, y2) ~ x2, posnegbinomial, data = pdata, trace = TRUE) coef(fit, matrix = TRUE) dim(depvar(fit)) # dim(fit@y) is not as good # Another artificial data example pdata2 <- data.frame(munb = exp(2), size = exp(3)); nn <- 1000 pdata2 <- transform(pdata2, y3 = rposnegbin(nn, munb = munb, size = size)) with(pdata2, table(y3)) fit <- vglm(y3 ~ 1, posnegbinomial, pdata2, trace = TRUE) coef(fit, matrix = TRUE) with(pdata2, mean(y3)) # Sample mean head(with(pdata2, munb/(1-(size/(size+munb))^size)), 1) # Population mean head(fitted(fit), 3) head(predict(fit), 3) # Example: Corbet (1943) butterfly Malaya data fit <- vglm(ofreq ~ 1, posnegbinomial, weights = species, data = corbet) coef(fit, matrix = TRUE) Coef(fit) (khat <- Coef(fit)["size"]) pdf2 <- dposnegbin(x = with(corbet, ofreq), mu = fitted(fit), size = khat) print( with(corbet, cbind(ofreq, species, fitted = pdf2*sum(species))), digits = 1) with(corbet, matplot(ofreq, cbind(species, fitted = pdf2*sum(species)), las = 1, xlab = "Observed frequency (of individual butterflies)", type = "b", ylab = "Number of species", col = c("blue", "orange"), main = "blue 1s = observe; orange 2s = fitted")) ## End(Not run)