Fit a generalized linear model with secure convergence.

glmgam.fit(X, y, coef.start = NULL, tol = 1e-6, maxit = 50, 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.

coef.start

numeric vector of starting values for the regression coefficients

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.

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.

Details

This function implements a modified Fisher scoring algorithm for generalized linear models, similar 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.

glmgam.fit is in principle equivalent to glm.fit(X,y,family=Gamma(link="identity")) but with much more secure convergence.

Author

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

glmgam.fit is called by mixedModel2Fit.

glm is the standard glm fitting function in the stats package.

Examples

y <- rgamma(10, shape=5)
X <- cbind(1, 1:10)
fit <- glmgam.fit(X, y, trace=TRUE)
#> Iter = 0 , Dev = 1.768659  Beta 7.635646 -0.3225118 
#> Iter = 1 , Dev = 1.756053  Beta 7.640667 -0.344654 
#> Iter = 2 , Dev = 1.749128  Beta 7.717942 -0.3629515 
#> Iter = 3 , Dev = 1.729458  Beta 8.085104 -0.4127735 
#> Iter = 4 , Dev = 1.719556  Beta 8.444979 -0.4630993 
#> Iter = 5 , Dev = 1.717867  Beta 8.583008 -0.4845948 
#> Iter = 6 , Dev = 1.717603  Beta 8.635069 -0.4929636 
#> Iter = 7 , Dev = 1.717562  Beta 8.655524 -0.4962541 
#> Iter = 8 , Dev = 1.717555  Beta 8.663593 -0.4975509 
#> Iter = 9 , Dev = 1.717554  Beta 8.666778 -0.4980623