...

/

Generalized Linear Mixed Model (GLMM)

Generalized Linear Mixed Model (GLMM)

Learn about the generalized linear mixed model in R.

Generalized linear mixed model (GLMM)

Now, let’s explore how mixed-effects models can be used in a generalized linear model framework.

Even though we were using tank-level values, those tanks come from spatially segregated blocks, and as we’ve already seen, the effects of those blocks may be important. As a first step, we may plot the number of animals that died by block to see what sorts of patterns there are.

Note that since Block is a numerical variable (1–8), it’s helpful to convert it to a factor when plotting so that the boxplot comes out correctly. We can do that easily by placing the variable inside the factor() function, which changes it into a factor, but we only do so for this plot.

R
qplot (data=RxP.byTank,
x=factor(Block),
y=N.dead,
geom='boxplot')

Once the above code is run, the figure generated should make it clear that there’s definitely some variation in survival across our blocks. There’s substantial variation within each block, as noted by the distance between the top and bottom of each bar, which are the 25% and 75% percentage values. This is also seen in the horizontal black lines, which are the medians in each block. The median mortality in Blocks 7 and 8 is about 10 tadpoles, whereas it’s over 20 in Blocks 3 and 4.

Let’s rerun our negative binomial model but as a mixed-effects model including Block as a random effect. The coding is identical to what we’ve done already, but now we’re using the glmer.nb() ...