Understanding and Interpreting the GLM
Learn about the diagnostic plots of GLMs and understand the concept of overdispersion.
Coding with glm()
We were coding a generalized linear model, glm()
, which is almost identical to coding a linear model with lm()
. The only real difference is that we include an extra argument, family=
, to define the error distribution family we’re using. Aside from that, everything is the same. Let’s explore the differences between the four error distributions that were described previously.
First, let’s make four models using one of the error distributions for each, and let’s use Res
, Pred
, and their interaction as our predictor variables.
Notice that all the models use the following glm()
function except for the negative binomial distribution, which uses a particular version of glm()
that’s just for the negative binomial. This is glm.nb()
, which is found in the MASS package. Since the function specifies that it’s for a negative binomial, we don’t need to set a family argument, as in the glm()
function. Also, note that we could have used the lm()
function for the first two models because the Gaussian family is the same as a normal distribution.
glm.n<-glm(N.dead~Res*Pred, family="gaussian", data=RxP.byTank)
glm.ln<-glm(log(N.dead)~Res*Pred, family="gaussian", data=RxP.byTank)
glm.p<-glm(N.dead~Res*Pred, family="poisson",
...