glim(x, y, n, error = "gaussian", link = "identity", wt = <<see below>>, resid = "none", init = <<see below>>, intercept = T, scale = <<see below>>, offset = 0, sequence = c(0, ncol(x)), eps = 0.0001, iter.max = 10)
Two different types of residuals may be returned, Pearson residuals and deviance residuals. Pearson residuals are the difference between the observation and the fit divided by the square root of the estimated variance for the observation. For Poisson errors the sum of the squared Pearson residuals is the Pearson Chi-squared goodness-of-fit statistic. The deviance residual is defined as the square root of the deviance for each observation with the sign determined by the sign of the observation minus the fit. (The sum of the squares of the deviance residuals will equal the deviance for the final model in unweighted cases.)
Denote the predicted value f(xb+offset) by mu. The deviance for each point is computed as: (y-mu)^2 for the Gaussian, 2*(y*log(ifelse(y==0,1,y/mu)) - (y-mu)) for the Poisson, 2*n*(y*log(ifelse(y==0,1,y/mu)) + (1-y)*log(ifelse(y==1,1,(1-y)/(1-mu)))) for the Binomial, -2*(log(y/mu) - (y-mu)/mu ) for the Gamma, and (y-mu)^2 / (y*mu^2) for the Inverse Gaussian. The deviance component of the output is the sum of wt times the deviance vector.
An iterated reweighted least squares algorithm is used to estimate the coefficients. Observations that have missing values in x, y, n or wt are deleted from the computations; residuals for such observations will be NA.
liver.x <- cbind(injection=liver.cells, A.exper=ifelse(levels(liver.exper)[liver.exper]=="A", 1, 0), B.exper=ifelse(levels(liver.exper)[liver.exper]=="B", 1, 0), C.exper=ifelse(levels(liver.exper)[liver.exper]=="C", 1, 0)) glim(liver.x, liver.gt[,1], error="poisson", link="log", intercept=F, seq=c(0,1,4)) liver.pl <- glim(liver.cells, liver.gt[,1], error="poisson", link="log", resid="dev") liver.fit <- exp(cbind(1,liver.cells) %*% liver.pl$coef) plot(liver.fit, liver.pl$resid, log="x", type="n") text(liver.fit, liver.pl$resid, levels(liver.exper)[liver.exper])
barley.cultar <- barley.disease barley.cultar[] <- 1:8 barley.cult <- NULL for (i in 1:8) barley.cult <- cbind(barley.cult, ifelse(barley.cultar==i, 1, 0)) dimnames(barley.cult) <- list(NULL, dimnames(barley.disease)[[1]])
# change 0 to NA in binomial denominator barley.exp <- as.vector(ifelse(barley.exposed==0, NA, barley.exposed)) glim(barley.cult, as.vector(barley.disease), n=barley.exp, error="binom", link="logit", intercept=F)