Tutorials › Generalized Linear Mixed Models (GLMM) › Indexing Units in Nested and Crossed Models

Crossed and Nested Random Effects · Tutorial 481 of 698

Indexing Units in Nested and Crossed Models

You will learn to encode observations, nested units, and crossed classifications with indices that preserve each unit’s identity and make the observed data structure explicit.

Advanced 10 min read

What You'll Learn

  • Distinguish an observation index from indices identifying the units associated with that observation.
  • Write nested-unit indices that preserve each unit’s parent identity.
  • Represent crossed classifications with separate indices and an explicit set of observed combinations.
  • Translate hypothetical sample records into indexed responses and verify observation counts.
  • Diagnose common indexing errors, including reused local labels and confused index ranges.

Why Indexing Matters

A model’s indices say which response belongs to which observation and which units. A label such as “class 1” is ambiguous unless it is clear whether it means class 1 in a particular school or one globally identified class. Likewise, a crossed design cannot be described accurately by a single index for the observed rows if the analysis needs to distinguish the classifications attached to each response.

This tutorial focuses on writing those labels precisely. It builds on the distinction between nested and crossed classifications: in a nested structure, a lower-level unit belongs to one particular higher-level unit; in a crossed structure, the classifications are represented separately and units from one classification can occur with units from the other. Indices identify units and records; by themselves, they do not specify a probability model.

Definition: An observation index identifies a response record. A unit index identifies a member of a classification, such as a school, student, clinician, or test item. A response index may need several unit indices when a record is associated with several classifications. Indices are labels, not quantitative measurements.

For clarity, this tutorial uses \(y\) for a response and lower-case letters such as \(h,i,j,r\) for indices. The index ranges and their dependence are stated alongside each notation. For example, \(i=1,\ldots,C_h\) means that the range of \(i\) can depend on the value of \(h\). A GLMM may use these indexed responses with a chosen response distribution, link, and fixed- and random-effect terms; the indexing alone does not choose any of those components.

A Reliable Indexing Convention

Start with the observational record, then name every classification that identifies the units associated with it. For nested units, use indices in order from the highest level to the lowest, with a lower-level index understood within its parent. If the same lower-level labels are reused under different parents, the complete tuple—not the lower-level label alone—identifies the unit.

Convention: If observations are recorded at a lowest-level unit, write the response with the indices identifying its path through the hierarchy. If a unit is identified by a parent \(h\) and a local label \(i\), identify it by the pair \((h,i)\), not by \(i\) alone. For crossed classifications, give each classification its own index and specify which index combinations actually have observed responses.

An observation index is still needed when a unit contributes more than one record with the same classification labels. For example, if the same student answers multiple items, an item index distinguishes those responses. If the same student-item pair is observed on more than one occasion, an additional occasion index distinguishes the records. Whether occasion is a measured covariate, another classification, or merely a record label depends on the study and model; the notation should not silently collapse distinct responses.

The basic checks are practical: each response should have an unambiguous index tuple; each index should have a stated range; local indices should be understood within their parent; and the notation should include exactly the observed records, rather than implying unobserved combinations are present. These checks concern data structure. They do not assert that responses are independent, nor do they establish any GLMM assumptions about their conditional distributions.

Worked Example: Students Nested Within Classes and Schools

Consider a hypothetical data set with two schools. School 1 has two sampled classes, containing two and three sampled students. School 2 has one sampled class containing two sampled students. One response is recorded per student. Use \(h\) for school, \(i\) for class within school \(h\), and \(j\) for student within class \((h,i)\).

The index ranges are \(h=1,2\), \(i=1,\ldots,C_h\), and \(j=1,\ldots,n_{hi}\), where \(C_1=2\), \(C_2=1\), and the student counts are \(n_{11}=2\), \(n_{12}=3\), and \(n_{21}=2\). Thus the responses are written \(y_{hij}\). The tuples are \((1,1,1)\), \((1,1,2)\), \((1,2,1)\), \((1,2,2)\), \((1,2,3)\), \((2,1,1)\), and \((2,1,2)\).

The total number of response records is \(2+3+2=7\). For example, \(y_{121}\) is the response for student 1 in class 2 of school 1, whereas \(y_{211}\) is the response for student 1 in class 1 of school 2. Both records have \(j=1\); that is not a conflict because their full index tuples differ.

A common error would be to write \(y_{ij}\) and treat \(i=1\) as one class across the whole data set. That discards the school index and merges class 1 in school 1 with class 1 in school 2. Writing \(y_{hij}\), and specifying that \(i\) is local to \(h\), preserves the identity of each class and student.

Crossed Classifications and Observed Combinations

For two crossed classifications, use a separate index for each classification. If the response is measured for subject \(i\) and item \(q\), one can write \(y_{iq}\). The index \(i\) identifies the subject, \(q\) identifies the item, and the response exists only for combinations that were actually observed. A notation such as \(i=1,\ldots,N\), \(q=1,\ldots,Q\) gives the possible index ranges, but does not alone establish that all \(NQ\) pairs have observations.

Worked Example: Patients Rated by Crossed Assessors

Suppose, hypothetically, three patients are rated by two assessors. Ratings are recorded for patient 1 by both assessors, patient 2 by both assessors, and patient 3 by assessor 1 only. Let \(i=1,2,3\) identify patients and \(j=1,2\) identify assessors. Suppose the recorded binary outcome is whether a rating meets a stated threshold, with values shown below.

Patient \(i\)Assessor \(j\)Recorded response \(y_{ij}\)
111
120
211
221
310

The observed index set is \( \mathcal{O}=\{(1,1),(1,2),(2,1),(2,2),(3,1)\} \). The data therefore contain five responses, not six: the pair \((3,2)\) is not in \(\mathcal{O}\). The response notation is \(y_{ij}\) for \((i,j)\in\mathcal{O}\), rather than for every possible pair in the Cartesian product of the two index ranges.

For example, substituting \(i=2\) and \(j=1\) gives \(y_{21}=1\); substituting \(i=3\) and \(j=1\) gives \(y_{31}=0\). The number of records is \(|\mathcal{O}|=5\). It would be incorrect to assign a response value to \(y_{32}\) from this table: that observation was not recorded. The absent pair is missing from the observed index set, not a response of zero.

When every combination is observed, \(\mathcal{O}\) is the full set of pairs and contains \(NQ\) elements. When it is not, writing the observed set prevents the notation from suggesting a complete grid. This is a bookkeeping statement, not a claim about why some combinations are absent or what assumptions a model should make about that absence.

Combining Nested and Crossed Indices

Some records involve units nested within one classification and crossed with units from another. The index tuple should retain both facts: use the parent path to identify nested units, and a separate index for each crossed classification. Do not replace those distinct identities with a single row number if the analysis needs to refer to the units themselves.

Worked Example: Students Nested Within Classes and Crossed With Test Items

Imagine a hypothetical assessment in one school. Class 1 contains two students and class 2 contains one student. Each student answers items 1 and 2, and item numbers refer to the same two items for students in both classes. Write \(i\) for class, \(j\) for student within class \(i\), and \(q\) for item. Let \(y_{ijq}\) denote the response for that student-item combination.

The ranges are \(i=1,2\), \(j=1,\ldots,n_i\), with \(n_1=2\) and \(n_2=1\), and \(q=1,2\). If every student answers both items, the total number of responses is \(n_1(2)+n_2(2)=2(2)+1(2)=6\). The six tuples are \((1,1,1)\), \((1,1,2)\), \((1,2,1)\), \((1,2,2)\), \((2,1,1)\), and \((2,1,2)\).

Here \(y_{121}\) refers to student 2 in class 1 answering item 1, while \(y_{211}\) refers to student 1 in class 2 answering item 1. The item index \(q\) is shared across classes; the student index \(j\) is local to its class. Thus the tuple distinguishes a nested student identity while retaining the separate item classification.

If one item response were not recorded, the appropriate notation would restrict \((i,j,q)\) to an observed set \(\mathcal{O}\) and count only its elements. The ranges describe which labels are possible; the set \(\mathcal{O}\) describes which records are present.

Justification, Diagnostics, and Alternatives

The reason for using a full tuple for nested units can be shown directly. Suppose classes are labeled \(i=1,\ldots,C_h\) separately within each school \(h\). A class’s identity is the pair \((h,i)\). If school 1 and school 2 both have a class labeled 1, then the local label \(i=1\) maps to two different classes. It is therefore not a one-to-one identifier. The pair \((h,i)\), however, distinguishes them because its first coordinate identifies the school and its second identifies the class within that school. The same argument applies down a hierarchy: append each local index to its parent path.

A global identifier is a valid alternative. One could assign every class a unique label, such as class IDs 1, 2, and 3, and separately record each class’s school. This can be convenient in data files, but it is a different encoding: the parent relationship must still be represented explicitly. A local-index notation such as \((h,i)\) makes that relationship visible in the tuple; a global ID does not automatically communicate it.

A single row index, such as \(r=1,\ldots,n\), is also useful for referring to records in a data table. It is not a substitute for unit indices when the goal is to express which units contribute to a response. A robust data representation can keep both: \(r\) identifies the record, while other columns or indices identify the school, class, student, item, assessor, or occasion.

Check an indexing scheme against the records before using it:

  • Repeated local labels: If “student 1” occurs in several classes, verify that the class path is included wherever student identity matters.
  • Unclear ranges: State whether an index range is fixed or depends on a parent, such as \(j=1,\ldots,n_{hi}\).
  • Missing combinations: List or define the observed index set rather than implying every combination exists.
  • Collapsed repeated records: If the same unit combination has multiple observations, add an index that distinguishes those records.
  • Index interpreted as a measurement: The numbers 1, 2, and 3 label units; their numerical ordering or spacing has no inherent statistical meaning.

These checks help catch data-structure errors, but correct indexing does not guarantee that the eventual GLMM is appropriate. The model’s likelihood, link, random-effects structure, and assumptions must be justified separately. In particular, an index tuple does not establish conditional independence, identify which effects should be included, or resolve whether all parameters can be estimated.

Key takeaway: Give every response an index tuple that identifies its observation and the relevant units. Use a parent path for nested identities, separate indices for crossed classifications, and an explicit observed set when combinations are incomplete.

Check Your Understanding

Answer each question by writing the index structure and explaining what its indices identify. Solutions follow the questions.

  1. Four clinics each have a different number of sampled patients, and one response is recorded per patient. Suggest notation that identifies each patient without requiring globally unique patient labels.
  2. Two assessors rate each of five cases, except that case 4 is rated only by assessor 1. How many response records are observed, and how should the observed set be represented?
  3. In a nested design, student labels run from 1 within each class. Explain why \(j=1\) alone may not identify a student and give an appropriate identifier.
  4. Each of three students answers four common items, but one student-item response is not recorded. Does the index range alone give the number of observed responses? Explain.

Solutions. (1) Let \(h=1,\ldots,4\) index clinics and \(i=1,\ldots,n_h\) index patients within clinic \(h\). Write \(y_{hi}\); the patient is identified by \((h,i)\). The record count is \(\sum_{h=1}^{4}n_h\). (2) Let \(i=1,\ldots,5\) index cases and \(j=1,2\) index assessors. There are \(5(2)-1=9\) records. Define \(\mathcal{O}=\{(i,j):i=1,\ldots,5,\ j=1,2\}\setminus\{(4,2)\}\), and write \(y_{ij}\) only for \((i,j)\in\mathcal{O}\). (3) The label \(j=1\) can occur in multiple classes, so it is ambiguous by itself. If \(h\) indexes class and \(j\) is local within class, use \((h,j)\), or write the response as \(y_{hj}\). (4) The ranges describe \(3(4)=12\) possible student-item pairs, but only 11 responses are observed. Specify the observed set as the full set of pairs with the missing pair removed; do not assign a response to that absent pair.

Clinical Biostats