20: Linear and Generalised Linear Mixed Models

Task N

Published

2026/06/13

Practice Task

Work through these exercises after reading the Mixed Models chapter, using the vegan pyrifos dataset (data(pyrifos)) — aquatic invertebrate communities from 12 mesocosm ditches sampled repeatedly over 11 weeks following insecticide (chlorpyrifos) dosing. Four exercises are hands-on calculations and two are short conceptual questions.

  1. Reconstruct the design factors (ditch, week and dose; see ?pyrifos) and build a univariate response, for example total abundance (rowSums(pyrifos)) or richness (vegan::specnumber(pyrifos)). Fit a naive model that ignores ditch (an lm(), or a glm() for a count response, of the response on dose), and inspect the residuals for the repeated-measures structure.

  2. Fit a mixed model with lme4::lmer() (or glmer() for a count response) that adds (1 | ditch) to account for the repeated sampling of each ditch. Compare the fixed-effect estimates and their standard errors with those of the naive model.

  3. Compute the intraclass correlation (ICC) for ditch with performance::icc() (or by hand from the variance components). How much of the variation is between ditches?

  4. Add week to the model and test whether a dose-by-week interaction, or a random slope for week within ditch, is supported. Watch for and report any singular fits.

  5. Explain pseudoreplication in this design: why are repeated samples from the same ditch not independent, and what does the random effect fix?

  6. Explain what the ICC represents, and how adding the random-effect structure changes the standard errors and the inferences you can draw relative to the naive model.

Assessment Criteria

This Task is not formally assessed. It is built around four hands-on analyses (Exercises 1–4) and two short conceptual questions (Exercises 5–6); work through all six and bring your annotated Quarto document to class for discussion.

Reuse

Citation

BibTeX citation:
@online{smit2026,
  author = {Smit, A. J.},
  title = {20: {Linear} and {Generalised} {Linear} {Mixed} {Models}},
  date = {2026-06-13},
  url = {https://tangledbank.netlify.app/BCB743/tasks/Task_N.html},
  langid = {en}
}
For attribution, please cite this work as:
Smit AJ (2026) 20: Linear and Generalised Linear Mixed Models. https://tangledbank.netlify.app/BCB743/tasks/Task_N.html.