glmnbfit: Fit Negative Binomial Generalized Linear Model with Log-Link

glmnb.fitR Documentation

Fit Negative Binomial Generalized Linear Model with Log-Link

Description

Fit a generalized linear model with secure convergence.

Usage

glmnb.fit(X, y, dispersion, weights = NULL, offset = 0, coef.start = NULL,
          start.method = "mean", tol = 1e-6, maxit = 50L, trace = FALSE)

Arguments

X

design matrix, assumed to be of full column rank. Missing values not allowed.

y

numeric vector of responses. Negative or missing values not allowed.

dispersion

numeric vector of dispersion parameters for the negative binomial distribution. If of length 1, then the same dispersion is assumed for all observations.

weights

numeric vector of positive weights, defaults to all one.

offset

offset vector for linear model

coef.start

numeric vector of starting values for the regression coefficients

start.method

method used to find starting values, possible values are "mean" or "log(y)"

tol

small positive numeric value giving convergence tolerance

maxit

maximum number of iterations allowed

trace

logical value. If TRUE then output diagnostic information at each iteration.

Details

This function implements a modified Fisher scoring algorithm for generalized linear models, analogous to the Levenberg-Marquardt algorithm for nonlinear least squares. The Levenberg-Marquardt modification checks for a reduction in the deviance at each step, and avoids the possibility of divergence. The result is a very secure algorithm that converges for almost all datasets.

glmnb.fit is in principle equivalent to glm.fit(X,y,family=negative.binomial(link="log",theta=1/dispersion)) but with more secure convergence. Here negative.binomial is a function in the MASS package.

The dispersion parameter is the same as 1/theta for the MASS::negative.binomial function or 1/size for the stats::rnbinom function. dispersion=0 corresponds to the Poisson distribution.

Value

List with the following components:

coefficients

numeric vector of regression coefficients

fitted

numeric vector of fitted values

deviance

residual deviance

iter

number of iterations used to convergence. If convergence was not achieved then iter is set to maxit+1.

Author(s)

Gordon Smyth and Yunshun Chen

References

Dunn, PK, and Smyth, GK (2018). Generalized linear models with examples in R. Springer, New York, NY. doi: 10.1007/978-1-4419-0118-7

See Also

The glmFit function in the edgeR package on Bioconductor is a high-performance version of glmnb.fit for many y vectors at once.

glm is the standard glm fitting function in the stats package. negative.binomial in the MASS package defines a negative binomial family for use with glm.

Examples

y <- rnbinom(10, mu=1:10, size=5)
X <- cbind(1, 1:10)
fit <- glmnb.fit(X, y, dispersion=0.2, trace=TRUE)

statmod documentation built on Jan. 6, 2023, 5:14 p.m.

Related to glmnbfit in statmod...