# Diagnostics for the final model fitted in Chapter 7, using R

library(lattice)
trellis.device(color=F)

# Generate Figure 7.4 (standardized residuals)

plot(model7.3.fit, resid(., type="p") ~ fitted(.), xlab="Predicted value", ylab="Residual", abline=0)

# Generate Figure 7.5
 
qqnorm(model7.3.fit, ~resid(.)) #layout=c(2,1), aspect = 2, id = 0.05) 

# Generate Figure 7.6

qqnorm(model7.3.fit, ~ranef(.,level=1), layout=c(2,1), aspect = 2, id = 0.05)