Stack Exchange
open access
CC BY-SA
Crossed vs nested random effects: how do they differ and how are they specified correctly in lme4?
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
- A Large-Scale Longitudinal Study of School Factors as Mediators from Depression and Parental Monitoring to Peer Victimization in Mainland Chinese Middle Schools#228389
- Cracking the Conundrum#942132
- Beneath the Floor: Censored DSEM Models for Analyzing ESM Data with Floor Effects#372313
- Subalpine and Alpine Plant Community Turnover in Yosemite National Park Following 30 Years of Climate Warming#1128437
- Failure of LMC statistical complexity in identifying structural order in the XY model#1116169
Record · ID 787300
Retrieved via Conceptio: every document is proof-bundled with source, license, and retrieval metadata.
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
Read the Docs → · View CLI source on GitHub · Conceptio Open Knowledge Archive