The lme and lmer Functions

Most of the examples in this chapter use the linear mixed model formula lme. This is to provide compatibility with the excellent book by Pinheiro and Bates (2000) on Mixed-Effects Models in S and S-PLUS. More recently, however, Douglas Bates has released the generalized mixed model function lmer as part of the lme4 package, and you may prefer to use this in your own work (see the Index for worked examples of lmer in this book; all of the analyses in this chapter using lme are repeated using lmer on the book's website). Here, I provide a simple comparison of the basic syntax of the two functions.

lme

Specifying the fixed and random effects in the model formula is done with two formulae. Suppose that there are no fixed effects, so that all of the categorical variables are random effects. Then the fixed effect simply estimates the intercept (parameter 1):

fixed = y~1

The fixed effect (a compulsory part of the lme structure) is just the overall mean value of the response variable y ~ 1. The fixed = part of the formula is optional. The random effects show the identities of the random variables and their relative locations in the hierarchy. The random effects are specified like this:

random = ~ 1 | a/b/c

and in this case the phrase random = is not optional. An important detail to notice is that the name of the response variable (y) is not repeated in the random-effects formula: there is a blank space to the left of the tilde ~. In most mixed-effects models ...

Get The R Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.