18 Mixed Effects Models
Overview
In this chapter, we’ll make a quick non-technical overview of fitting mixed effects models, focusing on the use of the function lme()
.
Objectives
Upon completion of this lesson, you should be able to:
- Recognize when a mixed effects model might be appropriate
- Be able to fit simple repeated measures models with
lme()
- Be able to fit simple split-plot models with
lme()
Data and R Code Files
The R code file and data files for this lesson can be found on the Essential R - Notes on learning R page.
18.1 What is a Mixed Effects Model?
Here we’ll introduce the idea behind the mixed-effects model.
18.2 Repeated Measures Done the Wrong Way
Now we’ll begin a demonstration of the wrong way to analyze data that includes repeated measures, using the “machines” data included in the package nlme
.
18.3 Repeated Measures Using Mixed Effects I
Here we’ll demonstrate the use of lme()
to fit a mixed effects model - in this case a separate intercept for each worker.
18.4 Repeated Measures Using Mixed Effects II
Now we’ll try a different model, with the machine * worker interaction as a random effect. The substantial reducion in AIC and the more reduced patterning in the residuals suggests that this ia a superior model.
18.5 Split-plot Using Mixed Effects
Here we’ll revisit the split-plot experiment we analyzed using aov()
in Lesson 13, this time with lme()
.
18.6 Using anova()
to Compare Models
Here we’ll demonstrate the use of anova()
to compare two models fit by lme()
- note that the models must be nested and both must be fit by ML rather than REML.