Tutorials › Generalized Linear Mixed Models (GLMM) › Recognizing Nesting From a Sampling Design

Crossed and Nested Random Effects · Tutorial 482 of 698

Recognizing Nesting From a Sampling Design

Use the design’s membership structure—not just the data table’s labels—to decide whether lower-level units are nested within higher-level units.

Advanced 10 min read

What You'll Learn

  • Define a lower-level unit’s parent set from the study’s membership rules.
  • Check that every unit has exactly one parent before calling a relationship nested.
  • Distinguish reused labels from distinct units using globally unique or composite identifiers.
  • Recognize when missing or multiple parent records leave nesting unresolved.
  • Use membership checks to diagnose apparent nesting in sample data.

Why the Sampling Design Determines Nesting

A data table may list pupils, classrooms, and schools in separate columns, but the column arrangement alone does not establish a hierarchy. The key question is how the study defines membership: does each pupil belong to exactly one classroom, and does each classroom belong to exactly one school? If so, those units form nested relationships for that study. If a unit has no recorded parent, or has more than one, the relationship is not established as a simple nested hierarchy.

This distinction matters when identifying the grouping structure for a generalized linear mixed model. A random effect for a grouping factor represents the grouping units defined by the design. Incorrectly treating reused labels as unique units, or assuming one-parent membership without checking it, can misrepresent which observations share a group. The introductory material on crossed and nested classifications distinguishes the general ideas; here the emphasis is on recognizing them from membership records.

A Precise Membership Rule

Definition: Let \(U\) be the set of distinct lower-level units in the study and \(H\) the set of higher-level units. For each \(u \in U\), define its parent set \(\mathcal{P}(u)\) as the set of distinct higher-level units to which the study’s design assigns \(u\). The lower-level units are nested within the higher-level units if and only if \(|\mathcal{P}(u)|=1\) for every \(u \in U\). A unit with no recorded parent has unresolved membership; a unit with more than one parent does not satisfy this simple nesting rule.

The word distinct is essential. A unit is an identifiable entity in the design, not necessarily a label as it appears in a column. If the label “Room 12” is used in several schools, the label alone does not identify one classroom across the study. The distinct units might instead be identified by the combinations \((\text{school}, \text{room label})\).

A sampling frame may include units for which no outcome was ultimately observed. Their membership can still be known from the design. Conversely, an observation row with a blank parent field does not establish that the unit has no real parent; it shows that the recorded membership is incomplete or unresolved. Do not count that row as evidence of nesting or silently assign a parent.

Why Exactly One Parent Is the Right Criterion

The membership rule can also be stated as a mapping. If every lower-level unit has exactly one parent, there is a function \(f: U \to H\) that assigns each unit \(u\) to its parent \(f(u)\). “Exactly one” requires both existence (at least one parent) and uniqueness (no more than one parent).

$$ |\mathcal{P}(u)|=1\ \text{for every }u\in U \quad\Longleftrightarrow\quad \text{each }u\text{ has one and only one assigned parent.} $$

For each higher-level unit \(h\), collect the lower-level units assigned to it: \(U_h=\{u\in U:f(u)=h\}\). These sets cover \(U\), because each lower-level unit has a parent. They do not overlap, because a unit assigned to two different higher-level units would have two parents, contradicting uniqueness. Thus the lower-level units divide into non-overlapping groups indexed by their parents. This partition is a useful consequence of nesting, but it is valid only after both existence and uniqueness have been checked.

Worked Example: Pupils, Classrooms, and Schools

Hypothetical design. A district samples pupils from three schools. The sampled pupils and their recorded classroom and school identifiers are:

PupilClassroomSchool
P1C1S1
P2C1S1
P3C2S1
P4C3S2
P5C4S3

Assume the identifiers are unique within the district and the design assigns each pupil to one classroom and each classroom to one school. For each pupil \(u\), count the distinct recorded classroom parents: \(|\mathcal{P}_{\text{class}}(P1)|=1\), and likewise the counts for P2 through P5 are \(1\). Therefore pupils are nested within classrooms in this design.

For the classroom-to-school relationship, the parent sets are \(\mathcal{P}(C1)=\{S1\}\), \(\mathcal{P}(C2)=\{S1\}\), \(\mathcal{P}(C3)=\{S2\}\), and \(\mathcal{P}(C4)=\{S3\}\). Each has size \(1\), so classrooms are nested within schools. The conclusion follows from the design’s one-classroom, one-school assignments, not merely from seeing classroom and school columns in the table.

Reused Labels and the Identity of a Unit

A membership check is meaningful only when the units have been identified correctly. Suppose two schools each use the classroom label “01.” If the study’s records identify the classrooms as \((S1,01)\) and \((S2,01)\), these are two distinct classrooms. Each has one school parent. Treating “01” alone as the identity of a classroom would incorrectly merge them and make the same supposed classroom appear to have two school parents.

Worked Example: Classroom Labels Reused Across Schools

Hypothetical records. Pupils A and B attend classroom 01 at school S1; pupils C and D attend classroom 01 at school S2. The design confirms that classroom numbers restart at 01 in each school.

Define distinct classroom units using a composite identifier. Then the classroom units are \((S1,01)\) and \((S2,01)\), with parent sets \(\mathcal{P}((S1,01))=\{S1\}\) and \(\mathcal{P}((S2,01))=\{S2\}\). Each parent-set size is \(1\), so classrooms are nested within schools.

If instead the analysis treats the label “01” as one district-wide classroom, the assembled parent set becomes \(\{S1,S2\}\), with size \(2\). That result describes a mistaken unit definition, not the design. The correction is to use a unique classroom identifier, such as school plus classroom number, before assessing nesting.

When Records Do Not Establish a Hierarchy

A simple nested relationship fails in two different ways. A lower-level unit can have multiple parents, violating uniqueness, or have no recorded parent, violating existence. These situations should not be collapsed into a single “not nested” data-cleaning category: multiple recorded parents may indicate a genuinely non-hierarchical assignment, while a missing parent may be a recording problem or an unclear design definition.

Worked Example: Multiple and Missing Parent Records

Hypothetical design records. A program records the classroom membership of three pupils as follows: Q1 is assigned to classroom A; Q2 is assigned to classrooms A and B during the defined study period; Q3 has a blank classroom field, and no other source identifies a classroom.

For Q1, \(\mathcal{P}(Q1)=\{A\}\), so \(|\mathcal{P}(Q1)|=1\). Q1 meets the one-parent condition. For Q2, \(\mathcal{P}(Q2)=\{A,B\}\), so \(|\mathcal{P}(Q2)|=2\). Q2 does not meet the simple nesting condition. For Q3, \(\mathcal{P}(Q3)=\varnothing\), so \(|\mathcal{P}(Q3)|=0\). Its membership is unresolved, not proof that it has no true classroom or that the remaining units form a complete nested structure.

The design must clarify whether Q2’s two assignments are valid memberships under the study definition, or whether one record is erroneous. Q3’s missing membership must be resolved or explicitly left unresolved. Until then, it would be unjustified to state that every pupil is nested within exactly one classroom.

A Practical Design-Based Check

1
Define the units.
Specify what counts as one lower-level unit and one higher-level unit for this study. Use design identifiers, not labels assumed to be unique.
2
Define membership.
State which parent assignment counts. If membership can change, specify the relevant study period or unit definition before forming parent sets.
3
Count distinct parents for every lower-level unit.
For each \(u\), calculate \(|\mathcal{P}(u)|\). A count of \(1\) satisfies the rule; a count of \(0\) is unresolved, and a count greater than \(1\) violates the simple one-parent rule.
4
Check the interpretation against the design.
Investigate unexpected counts, reused labels, and conflicting records. Only after the identifiers and assignments are clarified should the relationship be described as nested.

How Nesting Differs From Other Membership Patterns

Observed membership patternWhat the check showsDesign-based conclusion
Every lower-level unit has exactly one parentAll parent-set sizes equal 1The lower-level units are nested within the higher-level units.
A lower-level unit has two distinct parentsAt least one parent-set size exceeds 1The one-parent nesting rule fails; investigate the design and assignment.
A lower-level unit has no recorded parentAt least one parent-set size is 0Membership is missing or unresolved; nesting has not been established for all units.
A label appears under different parents, but identifiers are local to each parentThe apparent multiple parents may result from merging distinct unitsReconstruct globally unique unit identities, then repeat the check.

A crossed classification is different from a hierarchy: units of one factor are not each confined to a single level of the other factor. That contrast is useful when describing a design, but the immediate task here is more basic: establish the actual units and their parent sets before assigning a classification. A mixed or incomplete membership pattern should not be forced into a nested label simply because most units have one parent.

Diagnostics, Common Mistakes, and Limits

Useful diagnostics start with the design documentation and then check the records. Tabulate distinct parent counts for every lower-level unit; list units with counts of zero or greater than one; and inspect whether supposedly unique identifiers repeat across parents. Compare the flagged records with the sampling frame or assignment rules. A clean table is not enough if its identifiers are local labels, and a table with missing values does not by itself reveal the intended membership.

  • Mistake: “No unit has two parents, so the units are nested.” A unit with no parent also has no two parents. The correction is to require exactly one parent for every distinct lower-level unit: \(|\mathcal{P}(u)|=1\), not merely \(|\mathcal{P}(u)|\leq 1\).
  • Mistake: treating a zero count as evidence for nesting. A zero recorded parent leaves membership unresolved. Confirm the assignment or report that the hierarchy could not be verified for that unit.
  • Mistake: treating a repeated label as one unit. If labels are reused within different parents, form unique identifiers from the design before counting parents.
  • Mistake: inferring nesting from the observed sample alone. The sample may omit units or contain incomplete records. Use the defined units and assignment rules for the study, then use records to check whether they are represented consistently.

This check classifies a membership relationship; it does not determine whether a particular random-effects model is appropriate, whether its parameters can be estimated, or how observations’ covariance should be calculated. Those questions require additional assumptions and information. The nesting conclusion is also specific to the unit definition and membership rule: changing the study period or redefining units can change the parent sets.

Key takeaway: A lower-level unit is nested within a higher-level unit only when every distinct lower-level unit has exactly one parent under the study’s defined membership relationship. Zero recorded parents means unresolved membership; more than one means the simple nesting condition fails.

Check Your Understanding

For each question, apply the parent-set rule. Brief solutions follow the questions.

  1. A study identifies each laboratory specimen as belonging to one patient. Three specimen records have patient IDs 14, 14, and 27. What must be checked before concluding specimens are nested within patients?
  2. Each school numbers its classes from 1. Two records show class 1 at schools A and B. Why should these not automatically be treated as one classroom with two parents?
  3. For one lower-level unit, the records show \(\mathcal{P}(u)=\{H_2,H_5\}\). Does the one-parent nesting condition hold for \(u\)?
  4. A unit has no higher-level ID in the data, and no design document resolves the omission. Is it nested, or is its membership unresolved?

Solutions. (1) Confirm that each specimen is a distinct unit and that the design assigns every specimen to exactly one patient; the repeated ID 14 is not itself a problem, since several specimens may share one parent. (2) Class 1 may be a local label; identify the classrooms as (A, 1) and (B, 1). Each then has one school parent. (3) No. Its parent-set size is \(2\), so uniqueness fails. (4) Its parent-set size is \(0\) in the available records, so membership is unresolved; the data do not establish nesting for that unit.

Clinical Biostats