spaMM (version 4.4.16)

negbin: Family function for negative binomial “2” response (including truncated variant).

Description

Returns a GLM family object for negative-binomial model with variance quadratically related to the mean \(\mu\): variance=\(\mu+\mu^2\)/shape, where the shape parameter need or need not be specified, depending on usage. The zero-truncated variant can be specified as negbin2(., trunc = 0L). See negbin1 for the alternative negative-binomial model with variance “linearly” related to the mean.

A fixed-effect residual-dispersion model can be fitted, using the resid.model argument, which is used to specify the form of the logarithm of the shape parameter. Thus the variance of the response become \(\mu+\mu^2\)/exp(<specified linear expression>).

negbin(.) is an alias for negbin2(.) (truncated or not), and Tnegbin(.) is an alias for negbin2(., trunc = 0L).

Usage

# (the shape parameter is actually not requested unless this is used in a glm() call)
#
negbin2(shape = stop("negbin2's 'shape' must be specified"), link = "log", trunc = -1L, 
        LLgeneric = TRUE)

# For use with glm(), both negbin2's 'shape' and glm's method="llm.fit" are needed.

# alias with distinct arguments: Tnegbin(shape = stop("Tnegbin's 'shape' must be specified"), link = "log")

Value

A family object with structure similar to stats:: family object but with additional member functions for usage with spaMM fitting functions.

Arguments

shape

Shape parameter of the underlying Gamma distribution: the present negative binomial distribution can be represented as a Poisson-Gamma mixture, where the conditional Poisson mean is \(\mu\) times a Gamma random variable with mean 1 and variance 1/shape (as produced by rgamma(., shape=shape,scale=1/shape)).

link

log, sqrt or identity link, specified by any of the available ways for GLM links (name, character string, one-element character vector, or object of class link-glm as returned by make.link).

trunc

Either 0L for zero-truncated distribution, or -1L for default untruncated distribution.

LLgeneric

For development purposes, not documented.

Details

shape is the \(k\) parameter of McCullagh and Nelder (1989, p.373) and the theta parameter of Venables and Ripley (2002, section 7.4). The latent Gamma variable has mean 1 and variance 1/shape.

The name NB_shape should be used to set values of shape in optimization control arguments of the fitting functions (e.g., fitme(.,init=list(NB_shape=1))); but fixed values are set by the shape argument.

The returned family object is formally suitable for usage with glm if the shape argument is specified, but such usage is not recommended as it will lead to incorrect results for the zero-truncated case.

References

McCullagh, P. and Nelder, J.A. (1989) Generalized Linear Models, 2nd edition. London: Chapman & Hall.

Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S-PLUS. Fourth Edition. Springer.

Examples

Run this code
## Fitting negative binomial model with estimated scale parameter:
data("scotlip")
fitme(cases~I(prop.ag/10)+offset(log(expec)),family=negbin(), data=scotlip)
negfit <- fitme(I(1+cases)~I(prop.ag/10)+offset(log(expec)),family=Tnegbin(), data=scotlip)
simulate(negfit,nsim=3)

Run the code above in your browser using DataLab