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 implementations of models only.
1.1 Terms
Please read this section and refer back to if when you forget what these terms mean.
Term | Definition |
---|---|
Random effect | An independent variable where the levels being estimated compose a random sample from a population whose variance will be estimated |
Fixed effect | An independent variable with specific, predefined levels to estimate |
Experimental unit | The smallest unit being used for analysis. This could be an animal, a field plot, a person, a meat or muscle sample. The unit may be assessed multiple times or through multiple point in time. When the analysis is all said and done, the predictions occur at this level. |
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 |
lmerTest (Kuznetsova, Brockhoff, and Christensen 2017) | for computing p-values when using lme4 |
nlme (J. Pinheiro, Bates, and R Core Team 2023; J. C. Pinheiro and Bates 2000) | main package for linear mixed models and part of ‘base R’ |
emmeans (Lenth 2022) | for estimating fixed effects, their confidence intervals and conducting contrasts |
broom.mixed (Bolker and Robinson 2024) | package for presenting the model summary output into a tidy workflow. |
DHARMa (Hartig 2022) | for evaluating residuals (error terms) in generalized linear models |
performance (Lüdecke et al. 2021) | For creating diagnostic plots or to compute fit measures |
1.2.2 Optional packages
This entire guide will use the here package for loading data. If you can load your data fine without this package, please carry on. ‘here’ is certainly not required for running mixed models.