Introduction: *Linear mixed-effects models* (LMMs), also
known as hierarchical models, are another extension of simple linear
models used when there is clustering (i.e., nested data structures) or
non-independence (i.e., repeated measurements) among observations. These
models are called “mixed-effects” because they incorporate both fixed
and random effects. Fixed effects are variables with a *constant
effect* on the response variable, while random effects are variables
whose values or levels are assumed to be drawn randomly from a larger
population of levels. Given the natural clustering in biological data
(e.g., genetic groups, geographic locations), as well as the
longitudinal monitoring of the same individuals over time, LMMs
represent another essential tool in modern population biology.

In this module, you will expand your skills on linear models
(**Modules M.4**) to LMMs while testing associations
between Cayo Santiago rhesus macaque social cognition and age.

**Upon completion of this module, you will be able
to:**

- Fit linear mixed-effects models in
**R**;
- Interpret model output;
- Plot model predictions;
- Visualize random effects.

**References:**

**Extra training:**

**Associated literature:**

##
**Expand for R Notation and functions index**

**Notation:**

**[]** for subsets by columns.

**Functions:**

Base R:

**class()** and **str()** for data
structure;
**predict()** for extracting model predictions;
**summary()** for model output.

ggeffects:

**ggpredict()** for plotting model predictions.

lmerTest:

**lmer()** for fitting linear mixed-effects
models.

### Testing associations between social cognition and age

Rhesus macaques represent an excellent comparative system to study the
evolutionary origins of cognitive development in primates. However,
comparative developmental research on cognition is often challenging to
implement due to low sample sizes or no access to populations of
individuals that vary with age. Cayo Santiago rhesus macaques provide
the rare opportunity to address questions on the evolution of cognition,
given that experimental tasks can be performed in many individuals in
the field. Cayo Santiago monkeys are habituated to human observers, and
thus researchers can generate relatively large amounts of data of
socioemotional cognitive traits of individuals with known age (Fig 1).