Diagnostic Plots
Let's learn about the diagnostic plots in R.
Q-Q plot
Because lme4 is a relatively new package, not all of the same utility functions that we can use with other simpler models exist within it. For example, if we want to make the Q-Q plot, we have to either build it ourselves or use a separate function that has been written in another package. To build it ourselves, we use the following code:
qqnorm(resid(lmm1));qqline(resid(lmm1))
Plotting the residual
Maybe now’s a good time to remind everyone what exactly a Q-Q plot is. In the previous code, we first extracted the residuals of model lmm1
, then plotted them with the qqnorm()
function. If we think of an ANOVA, the residuals are how different each of our data points is from the treatment mean. If we think about a regression, it’s how far the points are from the line of best fit. We can plot the residuals alone, along with a horizontal red line at zero, as follows:
plot(resid(lmm1))abline(h=0, col='red', lwd=2)
Above are the residuals from the lmm1
model, with a red line indicating zero. Recall that a residual with a value of zero means that the value is precisely what the model would predict—that is., it’s the mean value).
We see that R has plotted how far from the predicted mean each point in our data frame ...