Skip to main content

A primer on mixed-effects Models: theory and practice

Slides from a tutorial on mixed-effects models I presented to my research group.
r
statistics
multilevel
mixed models
animations
Author
Published

Tuesday, March 31, 2020

When I started my PhD I had to get familiar with Linear Mixed Models very well very quickly. Then I was asked to present what I learnt and prepare this informal tutorial for my colleagues, which I presented on March 10th, 2020 (yes, early pandemic :confounded:). This post shares the result.

This is not supposed to be taken as a formal guide to linear mixed-effects models, but rather as a semi-coherent compilation of notes and self-suggestions that I considered worth sharing with my lab mates during my early stages of in the PhD. Here are the slides:

What I should be taken more seriously are (1) the references I suggest in the first slides (which I consider some of the best resources available to learn linear mixed-effects models), and (2) the memes, which I personally curated and even created to sweeten up the dreadful incoherence of the content of some of the slides (sorry about that).

Before the presentation I tweeted one of the animations I generated for it.

This tweet got some attention (for my usual numbers) and many kind folks have asked for the R code or the GIF file of the specific animation included in the tweet, so here they are (you’ll also find them in the GitHub repository) in a perhaps more comfortable format, ready to be cloned or downloaded):

Linear mixed models animated

Session info

R version 4.6.1 (2026-06-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 26.04.1 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libmkl_rt.so;  LAPACK version 3.8.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Madrid
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] xaringanExtra_0.8.0

loaded via a namespace (and not attached):
 [1] htmlwidgets_1.6.4 compiler_4.6.1    fastmap_1.2.0     cli_3.6.6        
 [5] htmltools_0.5.9   tools_4.6.1       otel_0.3.0        yaml_2.3.12      
 [9] rmarkdown_2.32    knitr_1.52        jsonlite_2.0.0    xfun_0.62        
[13] digest_0.6.39     rlang_1.3.0       renv_1.3.1        evaluate_1.0.5   

Reuse

Citation

BibTeX citation:
@online{garcia-castro2020,
  author = {Garcia-Castro, Gonzalo},
  title = {A Primer on Mixed-Effects {Models:} Theory and Practice},
  date = {2020-03-31},
  url = {https://gongcastro.github.io/blog/posts/primer-linear-mixed-models/primer-linear-mixed-models.html},
  langid = {en}
}
For attribution, please cite this work as:
Garcia-Castro, G. (2020, March 31). A primer on mixed-effects Models: theory and practice. https://gongcastro.github.io/blog/posts/primer-linear-mixed-models/primer-linear-mixed-models.html