Conceptio › Archive › Stack Exchange
Stack Exchange open access CC BY-SA

Crossed vs nested random effects: how do they differ and how are they specified correctly in lme4?

Joe King · 2016
Stack Exchange · Datasets · License: CC BY-SA · 2016
Open Source ↗
mixed-model
Here is how I have understood nested vs. crossed random effects: Nested random effects occur when a lower level factor appears only within a particular level of an upper level factor. For example, pupils within classes at a fixed point in time. In lme4 I thought that we represent the random effects for nested data in either of two equivalent ways: (1|class/pupil) # or (1|class) + (1|class:pupil) Crossed random effects means that a given factor appears in more than one level of the upper level factor. For example, there are pupils within classes measured over several years. In lme4, we would write: (1|class) + (1|pupil) However, when I was looking at a particular nested dataset, I noticed that both model formulas gave identical results (code and output below). However I have seen other datasets where the two formulas produced different results. So what is going on here? mydata <- read.csv("https://web.archive.org/web/20160624172041if_/http://www-personal.umich.edu/~bwest/classroom.csv") # (the data is no longer at `http://www-personal.umich.edu/~bwest/classroom.csv` # hence the link to web.archive.org) # Crossed version: Linear mixed model fit by REML ['lmerMod'] Formula: mathgain ~ (1 | schoolid) + (1 | classid) Data: mydata REML criterion at convergence: 11768.8 Scaled residuals: Min 1Q Median 3Q Max -4.6441 -0.5984 -0.0336 0.5334 5.6335 Random effects: Groups Name Variance Std.Dev. classid (Intercept) 99.23 9.961 schoolid (Intercept) 77.49 8.803 Residual 1028.23 32.066 Number of obs: 1190, groups: classid, 312; schoolid, 107 # Nested version: Formula: mathgain ~ (1 | schoolid/classid) REML criterion at convergence: 11768.8 Scaled residuals: Min 1Q Median 3Q Max -4.6441 -0.5984 -0.0336 0.5334 5.6335 Random effects: Groups Name Variance Std.Dev. classid:schoolid (Intercept) 99.23 9.961 schoolid (Intercept) 77.49 8.803 Residual 1028.23 32.066 Number of obs: 1190, groups: classid:schoolid, 312; schoolid, 107
Conceptio Open Archive

Analyze & explore related research in Conceptio

Connect this record directly into your research workflow or AI agent. Explore citations across open repositories, query full text, and export structured proof bundles.

This document is indexed with metadata only: full text is not available in the archive for this record. Open the official source ↗

Related documents

Record · ID 787300
Retrieved via Conceptio: every document is proof-bundled with source, license, and retrieval metadata.
Bring this data into your agent: Connect via MCP or API · 20 free credits to start · no card required
Read the Docs → · View CLI source on GitHub · Conceptio Open Knowledge Archive