Tutorials › Generalized Linear Mixed Models (GLMM) › Common Mistakes in Declaring Effects Nested

Crossed and Nested Random Effects · Tutorial 524 of 698

Common Mistakes in Declaring Effects Nested

Learn to verify nesting from the design, distinguish a unit from its label, and recognize when one lower-level unit belongs to multiple parents.

Advanced 10 min read

What You'll Learn

  • Define nesting using observed unit-to-parent membership rather than factor names.
  • Distinguish reused local labels from shared units.
  • Check whether each lower-level unit has exactly one parent in the study.
  • Trace how an incorrect declaration changes implied dependence.
  • Choose between nested, crossed, and occurrence-specific interpretations.
  • Diagnose structural problems using membership tables and graphs.

Why Declaring Nesting Requires More Than a Label

A grouping variable can look nested in a data file without representing a nested structure. Class “1” may mean a different classroom in each school, while the same clinician may work at several clinics. The decisive question is not whether the labels are similar, or whether one factor is called a “level” of another. It is whether each lower-level unit belongs to exactly one upper-level unit over the scope of the study.

Declaring effects nested makes a claim about which observations share a random effect and, consequently, which observations are expected to be dependent. A mistaken claim can merge distinct units or split a genuinely shared unit. In either case, the fitted model no longer describes the intended membership structure.

Definition: In a specified study and over a specified period, a lower-level unit is nested within an upper-level unit if every lower-level unit has membership in exactly one upper-level unit. Several lower-level units may belong to the same upper-level unit. Nesting concerns the identity and membership of units, not the wording or numerical format of their labels.

The scope matters. A patient may belong to one clinic for a study of a single visit, but be seen at several clinics in a study covering a year. A clinician may have one administrative home clinic but provide care at multiple clinics. State what counts as a unit, which memberships are relevant, and the time period before deciding whether nesting applies.

A Model-Based View of the Structural Claim

For a GLMM, let \(Y_i\) denote the response for observation \(i\), let \(x_i\) be its fixed-effect predictor vector, and let \(g\) be the link function. A simple random-intercept model for observations in upper-level group \(j\) and lower-level unit \(k\) can be written as follows:

$$ g\{E(Y_{ijk}\mid b_j,u_{k(j)})\} = x_{ijk}^{\mathsf T}\beta+b_j+u_{k(j)}. $$

Here \(b_j\) is the random intercept for upper-level unit \(j\), and \(u_{k(j)}\) is the random intercept for lower-level unit \(k\) within \(j\). A standard version assumes \(b_j\sim N(0,\tau^2)\), \(u_{k(j)}\sim N(0,\omega^2)\), and independence among these random effects. The response distribution and link must also be appropriate for the outcome; conditional on the random effects and predictors, observations are assumed independent in this simple model. The notation \(k(j)\) encodes the structural claim: each lower-level unit has one parent \(j\).

That claim has a dependence consequence. In a Gaussian identity-link version with residual variance \(\sigma^2\), two distinct responses from the same lower-level unit share both random intercepts. Their covariance is \(\tau^2+\omega^2\). Two responses from different lower-level units in the same parent group share only \(b_j\), so their covariance is \(\tau^2\). Responses in different upper-level units share neither intercept. For non-Gaussian GLMMs, these variance components describe dependence on the linear-predictor scale; response-scale covariances need not equal these simple sums.

Worked Example: Reused Classroom Labels

Worked Example: Reused Classroom Labels

Hypothetical data. Two schools each have classrooms labeled 01 and 02. Students have a continuous test score, and each row records a student’s school, classroom label, and score. Is classroom nested in school, or does the reused label mean that “01” is one classroom shared by both schools?

First identify the units. Suppose classroom 01 in School A and classroom 01 in School B are physically and organizationally distinct rooms. The local label “01” is reused; it does not identify one shared classroom. Each of the four actual classrooms has exactly one school as its parent, so classrooms are nested within schools. A classroom identity must preserve both pieces of information: School A:01, School A:02, School B:01, and School B:02. The number of classroom units is \(2\times2=4\), not 2.

For illustration, suppose the Gaussian random-intercept model has school variance \(\tau^2=0.25\), classroom variance \(\omega^2=0.64\), and residual variance \(\sigma^2=1.00\). The marginal variance of a student score is \(0.25+0.64+1.00=1.89\). For two different students in the same classroom, the covariance is \(0.25+0.64=0.89\), and their model-implied correlation is \(0.89/1.89=0.4709\). For students in different classrooms of the same school, it is \(0.25/1.89=0.1323\). These calculations rely on the assumed independent random intercepts and residuals, not on estimates from real data.

If the classroom effect were keyed only by the label 01 or 02, the model would treat the two distinct classrooms labeled 01 as sharing one classroom random effect. It would then assign them an unintended shared component of covariance. The error is not that labels are reused; it is that a local label has been mistaken for a globally unique unit.

Worked Example: Names Do Not Establish Membership

Worked Example: Names Do Not Establish Membership

Hypothetical data. Two hospitals each record outcomes in units called “A” and “B.” In the study’s organizational records, each hospital has its own Unit A and Unit B. Decide whether units are nested in hospitals, even though the unit names repeat.

The relevant membership pairs are (Hospital 1, Unit A), (Hospital 1, Unit B), (Hospital 2, Unit A), and (Hospital 2, Unit B). Each distinct unit appears under exactly one hospital, so there are four units nested in two hospitals. For example, Hospital 1:Unit A and Hospital 2:Unit A are separate units; the shared word “A” does not make them the same entity.

A suitable structural expression for a unit-level random intercept is \(u_{r(j)}\), where \(r\) identifies a unit within hospital \(j\). The unit key must distinguish the four combinations. Counting by hospital gives \(2\) units per hospital, hence \(2\times2=4\) unit effects. If the records instead showed that one centrally managed unit served both hospitals and remained the same unit for the study, its membership would not be one-to-one with hospitals. Names alone cannot distinguish these situations; the operational definition and membership records do.

The reverse naming pattern is also possible: unit IDs might be globally unique, such as U101, U102, U203, and U204, while every unit still belongs to exactly one hospital. Global uniqueness does not make the factor crossed. It is membership, not a numbering convention, that determines the relationship.

Worked Example: A Lower-Level Unit With Multiple Parents

Worked Example: A Lower-Level Unit With Multiple Parents

Hypothetical data. A study records patient outcomes at two clinics. Clinician P1 sees patients at both clinics; P2 works only at Clinic 1, and P3 works only at Clinic 2. The same clinician ID refers to the same person at each clinic. Is clinician nested within clinic?

The membership sets are P1: {Clinic 1, Clinic 2}, P2: {Clinic 1}, and P3: {Clinic 2}. There are three clinician units, and P1 has two clinic memberships. Therefore, clinician is not nested within clinic for this study. A clinician-by-clinic occurrence is not automatically a new clinician: splitting P1 into two IDs would discard the fact that the same person contributes observations at both locations.

To see why the distinction matters, consider a logistic GLMM with clinic and clinician random intercepts. Suppose their variances on the log-odds scale are \(0.16\) and \(0.36\), respectively. Two observations from P1, one at each clinic, share the clinician effect but not the clinic effect. Their shared random-intercept covariance contribution on the linear-predictor scale is \(0.36\). Two observations from P1 at the same clinic share both contributions, \(0.16+0.36=0.52\). These are latent-scale contributions, not response-scale covariances or correlations. Declaring clinician nested in clinic would fail to represent P1 as one clinician across both locations.

There are situations in which separate clinic-specific clinician roles are the intended units—for example, if the study defines the target as a clinician’s separate service role at each clinic. That is a different scientific definition, not a coding fix. Make the unit definition explicit and use it consistently.

A Short Justification: Why Shared Membership Changes Dependence

The covariance implication in the Gaussian example follows from the law of total covariance. Write two distinct responses as \(Y_i=\mu_i+b_{j(i)}+u_{k(i)}+\epsilon_i\), with independent, mean-zero random intercepts and residuals. Conditional on the random effects, the responses are independent, so their conditional covariance is zero. Their marginal covariance is therefore the covariance of their conditional means. If they share a parent intercept, that contribution is \(\operatorname{Var}(b_j)=\tau^2\); if they also share a lower-level intercept, add \(\operatorname{Var}(u_k)=\omega^2\). Thus:

$$ \operatorname{Cov}(Y_i,Y_{i'}) = \begin{cases} \tau^2+\omega^2, & \text{same lower-level unit},\\ \tau^2, & \text{different lower-level units, same parent},\\ 0, & \text{different parents}. \end{cases} $$

This calculation assumes the stated Gaussian identity-link model, distinct observations, and independent random effects and residuals. It shows why structural declarations are not merely notational: they specify which pairs of observations share latent terms. For a non-Gaussian GLMM, the same membership logic applies, although the marginal dependence on the response scale is generally more complicated.

Checks, Alternatives, and Failure Modes

Before specifying nesting, make a membership table or graph using real unit identities rather than display labels. For each proposed lower-level unit, list every parent it has during the study period. Then ask whether each row has exactly one parent. If the answer depends on the time window, define that window explicitly.

  • Warning sign: a local label is used as a global ID. Check whether “Room 1,” “Ward A,” or “Group 2” is unique across parents. If not, construct or verify a unit key that preserves the actual identity.
  • Warning sign: factor names seem to settle the question. “Students within schools” is not enough if the same student is measured across schools. Names describe roles; the incidence data establish membership.
  • Warning sign: a lower-level unit has multiple parents. Confirm that repeated IDs genuinely refer to the same unit. If so, the one-parent condition fails. If they refer to separate units that happen to share a label, distinguish those identities instead.
  • Warning sign: implied dependence is implausible. Ask which observations the proposed random effects make share a latent contribution. If the model joins distinct units or separates observations from one unit, revisit the structure rather than treating the symptom as a numerical fitting problem.

The main structural alternatives are different, substantive descriptions of the design. A nested structure applies when each lower-level unit has one parent. A crossed or cross-classified structure is relevant when units from two classifications can recur in combinations rather than one classification being contained within the other. If the target unit is an occurrence-specific role, define occurrences as the units only when that definition matches the research question. Some factors may instead be modeled as fixed effects when the inferential target concerns the particular observed categories; that choice does not, by itself, repair an incorrect unit definition.

A membership graph can help: draw one node for each distinct unit and an edge for each observed membership. A proposed nesting should give each lower-level node exactly one parent node. Multiple edges from one lower-level node indicate either a non-nested structure or an unresolved identity definition. Empty combinations do not automatically establish nesting or crossing; what matters is the intended membership relationship and the design’s scope.

Common Mistakes

  • “The labels repeat, so the units are shared.” Repeated labels can identify distinct local units. Verify identity before joining records.
  • “The labels are unique, so the factor is not nested.” Unique codes can still represent units each belonging to one parent. Nesting is about membership, not code reuse.
  • “The variables are named ‘parent’ and ‘child,’ so the child is nested.” A name or organizational chart does not establish the study’s actual observation structure. Check all memberships over the chosen scope.
  • “A unit appearing in two parents can be made nested by duplicating its ID.” Duplication changes the modeled unit from one shared entity to separate parent-specific occurrences. It is justified only if those occurrences are the intended units.
  • “An unusual fit proves the nesting declaration is wrong.” Fit problems can have many causes. Use unit definitions, membership records, and implied dependence to diagnose structure; do not infer it from a single warning or variance estimate.
Key takeaway: Declare a lower-level effect nested only after confirming that each identified lower-level unit has exactly one parent over the study’s stated scope. Reused names do not merge units, and multiple genuine parent memberships cannot be removed by relabeling.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. Three hospitals each have a distinct ward labeled “East.” Does the repeated label mean ward is one shared unit?
  2. Technician T7 works at two laboratories during the study, and the same technician ID is confirmed at both. Is technician nested within laboratory?
  3. Every globally unique classroom ID belongs to one school. Does global uniqueness rule out nesting?
  4. In the Gaussian nested random-intercept model, what covariance is implied for two distinct observations from different classrooms in the same school?

Solutions. (1) No. If the wards are distinct, there are three ward units; each has one hospital parent, so ward is nested in hospital. (2) No. T7 has two laboratory memberships, so the one-parent condition fails; the study may have a cross-classified structure or need a different, explicitly justified unit definition. (3) No. Each classroom still has exactly one parent school, so classroom can be nested despite globally unique IDs. (4) The observations share the school random intercept but not the classroom intercept, so the covariance is \(\tau^2\), under the independent Gaussian identity-link assumptions stated above.

Clinical Biostats