Mixed effect models

Eamonn Mallon

2026-03-23

Module survey

Recap

  • Yor data has structure (Batch, nested, repeated)
  • Would you want know the mean (fixed) or don’t you care (random)
  • \[ Y_{ij} = \alpha_j + \beta_j \,\text{bodylengths}_{ij} + \epsilon_{ij}, \quad \epsilon_{ij} \sim \mathcal{N}(0, \sigma^2) \]
  • \[ Y_{ij} = \alpha + a_j + \beta \,\text{bodylengths}_{ij} + b_j \,\text{bodylengths}_{ij} + \epsilon_{ij}, \quad a_j \sim \mathcal{N}(0, \sigma_a^2), \quad b_j \sim \mathcal{N}(0, \sigma_b^2), \quad \epsilon_{ij} \sim \mathcal{N}(0, \sigma^2) \]

Identify Fixed vs Random Effects

  • Drug treatment (A vs B) on insect lifespan. Insects come from 10 colonies.
  • Activity is measured daily for 10 days under two diets.
  • Exam performance before and aftee one of two different prep courses. Students are nested within classes, which are nested within schools.
  • Plant growth is measured under three fertilisers across 20 fields.
  • Gene expression is compared across three specific mutant strains and a wildtype.
  • Behaviour is studied in five named wasp populations collected from different locations.

Answers

  • Drug treatment (A vs B) on insect lifespan. Insects come from 10 colonies.
  • Activity is measured daily for 10 days under two diets.
  • Exam performance before and after one of two different prep courses. Students are nested within classes, which are nested within schools.
  • Plant growth is measured under three fertilisers across 20 fields.
  • Gene expression is compared across three specific mutant strains and a wildtype.
  • Behaviour is studied in five named wasp populations collected from different locations.

Build the Models

A researcher studies the effect of temperature on metabolic rate in insects.

  • Metabolic rate is measured for multiple individuals
  • Each individual belongs to one of several colonies
  • Body size is also recorded for each individual

Task

  1. Write a linear model where the relationship between body size and metabolic rate can differ between colonies

  2. Write a mixed effects model where colonies are treated as random effects, allowing both intercepts and slopes to vary

Linear model

  • \[ Y_{ij} = \alpha_j + \beta_j \,\text{bodysize}_{ij} + \epsilon_{ij}, \quad \epsilon_{ij} \sim \mathcal{N}(0, \sigma^2) \]

Mixed effect model

  • \[ Y_{ij} = \alpha + a_j + \beta \,\text{bodysize}_{ij} + b_j \,\text{bodysize}_{ij} + \epsilon_{ij} \]

\[ a_j \sim \mathcal{N}(0, \sigma_a^2), \quad b_j \sim \mathcal{N}(0, \sigma_b^2), \quad \epsilon_{ij} \sim \mathcal{N}(0, \sigma^2) \]