O'Reilly logo

The R Book by Michael J. Crawley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mixed-Effects Models with Temporal Pseudoreplication

A common cause of temporal pseudoreplication in growth experiments with fixed effects is when each individual is measured several times as it grows during the course of an experiment. The next example is as simple as possible: we have a single fixed effect (a two-level categorical variable: with fertilizer added or not) and six replicate plants in each treatment, with each plant measured on five occasions (after 2, 4, 6, 8 or 10 weeks of growth). The response variable is root length. The fixed-effect formula looks like this:

fixed = root~fertilizer

The random-effects formula needs to indicate that the week of measurement (a continuous random effect) represents pseudoreplication within each individual plant:

random = ~week|plant

Because we have a continuous random effect (weeks) we write ~week in the random-effects formula rather than the ~1 that we used with categorical random effects (above). Here are the data:

results<-read.table("c:\\temp\\fertilizer.txt",header=T)
attach(results)
names(results)

[1]  "root"  "week"  "plant"  "fertilizer"

We begin with data inspection. For the kind of data involved in mixed-effects models there are some excellent built-in plotting functions (variously called panel plots, trellis plots, or lattice plots).

library(nlme)
library(lattice)

To use trellis plotting, we begin by turning our dataframe called results (created by read.table) into a groupedData object (p. 668). To do this we specify ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required