dat <- yates.oats
desplot(yield ~ x*y, dat, out1=block, text=gen, col=nitro, cex=1)
# Roughly linear gradient across the field. The right-half of each
# block has lower yield. The blocking is inadequate!
require(lattice)
xyplot(yield ~ x|factor(nitro), dat, type = c('p', 'smooth'),
xlab='x', span=1, as.table = TRUE)
# Typical split-plot analysis
library(lme4)
m3 <- lmer(yield ~ nitro * gen + (1|block/gen), data=dat)
# Residuals still show structure
xyplot(resid(m3) ~ dat$x, xlab='x', type=c('p','smooth'))
# Add a linear trend for x
m4 <- lmer(yield ~ x + nitro * gen + (1|block/gen), data=dat)
xyplot(resid(m4) ~ dat$x, type=c('p','smooth'), xlab='x')
# Compare fits
AIC(m3,m4)Run the code above in your browser using DataLab