Mixed-Effects Models in R
The very basics of how to run models with random effects in R
This page assumes that you already understand the basics of how to run a linear model and how to interpret linear model output.
Mixed-effects models can be built in R using the lme4 package. Other packages to work with mixed-effects models are GLMMadaptive, glmmML, glmmTMB, and MCMCglmm.
Linear and generalized linear mixed-effects models have the following structure: outcome variable ~ fixed effects + random effects.
Outcome variable = the variable that is hypothesized to be modified by the predictors. For example in a looking while listening study looking time would be a likely outcome variable.
Fixed effects are predictors that affect the outcome consistently across all observations. For example, in a looking while listening task where children heard some mixed language phrases, language mixing is a fixed predictor of looking time because mixing was always the same in each experiment for each participant.
Random effects are grouping variables where we expect individual differences. For example, in a looking while listening task we expect each child to perform differently based on their individual traits, so participant is a random predictor of looking time.
To learn more about mixed-effects modelling:
“A brief introduction to mixed effects modelling and multi-model inference in ecology”. The title mentions ecology, but the concepts translate really well across fields.
For hands-on practice, the Coding Club modelling tutorials are very helpful, as is this tutorial on model diagnostics with DHARMa (simulation-based approach).
For troubleshooting, the stats community in StackExchange is great for addressing specific technical questions that standard tutorials might not cover.
Books:
Statistics for linguistics: An introduction using R. Bodo Winter (2019). Find it in the lab's library.
Last updated