1 Introduction
This guide is focused on frequentist implementations of mixed models in R, covering different scenarios common in the agricultural and life sciences.
This is not intended to be a guide to the theory of mixed models, it is focused on R syntactical issues for correct implementations of mixed models only. We do provide a short introduction to mixed models. UCLA provides a longer more comprehensive introduction.
1.1 Data
Readers of this material are welcome to test any of the code in this guide. All data used in this tutorial are from previously conducted studies and are available in the GitHub repository for this resource and explained in the chapters they are used. You can also download all data sets as a zipped file (~12 Mb).
1.2 Packages
1.2.1 Table of required packages for modelling
| Package | Purpose |
|---|---|
| lme4 (Bates et al. 2015) | main package for linear mixed models, v 2.0 or later required |
| lmerTest (Kuznetsova et al. 2017) | for computing p-values when using lme4 |
| nlme (Pinheiro et al. 2023; Pinheiro and Bates 2000) | main package for linear mixed models and part of “base R” |
| emmeans (Lenth 2022) | for conducting inference on fixed effects |
| broom.mixed (Bolker and Robinson 2024) | package for presenting the model summary output into a “tidy” workflow. |
| performance (Lüdecke et al. 2021) | For creating diagnostic plots or to compute fit measures |
1.2.2 Optional packages
This entire guide uses tje here package for loading data and easily navigating working directories. If you can load your data fine without this package, please carry on; ‘here’ plays no role in running mixed models.