Tutorials › Generalized Linear Mixed Models (GLMM) › Level-Specific Predictors in Hierarchical Models

Crossed and Nested Random Effects · Tutorial 504 of 698

Level-Specific Predictors in Hierarchical Models

Classify predictors by the units on which they vary, then place them correctly in nested and crossed generalized linear mixed models.

Advanced 12 min read

What You'll Learn

  • Distinguish a predictor’s measurement level from the level of the outcome.
  • Classify variables by the units on which their values can vary.
  • Write nested and crossed GLMM linear predictors with level-appropriate terms.
  • Calculate a conditional fitted probability from predictors and random effects.
  • Diagnose coding and design problems that can obscure a predictor’s level.
  • Compare random-effects modeling with pooled models and group indicators.

Why Predictor Level Matters

In a hierarchical data set, a row may describe a person, while that person belongs to a class, school, and district. A predictor can describe the person, one of those groups, or a unit that is crossed with another grouping factor. Its level is determined by which units can have different values, not by whether it is numerical or categorical. Getting this right determines what a coefficient compares and where its information comes from.

For example, a patient’s age can vary from patient to patient within a clinic, while a clinic’s staffing policy is shared by all patients in that clinic. Both may appear as columns on every patient row, but repeating a clinic-level value on those rows does not make it a patient-level predictor. Likewise, the same grouping unit can be a higher level in one model and simply a group in another: level is relative to the hierarchy being modeled.

Definition: An observation-level predictor may vary among observations within a grouping unit. A group-level predictor is defined for a group and is constant for observations belonging to that group. A higher-level predictor is defined for a unit above the immediate group in a nested hierarchy and is shared by the lower-level units it contains. In crossed designs, classify a predictor by the membership unit it describes, rather than forcing it into a single nested chain.

These labels describe the predictor’s source and variation, not the response’s measurement scale. A binary response can have predictors at several levels; so can a count or continuous response. Also distinguish a predictor’s level from the random-effects level: a clinic policy is a fixed predictor that varies between clinics, whereas a clinic random intercept represents residual clinic-to-clinic differences after accounting for modeled predictors.

Modeling Predictors in a Nested Hierarchy

Suppose observations \(i\) are nested in classes \(j\), and classes are nested in schools \(k\). Let \(Y_{ijk}\) be a binary response, \(x_{ijk}\) an observation-level predictor, \(z_{jk}\) a class-level predictor, and \(w_k\) a school-level predictor. One possible logistic mixed model is

$$ Y_{ijk}\mid u_k,v_{jk} \sim \operatorname{Bernoulli}(p_{ijk}),\qquad \operatorname{logit}(p_{ijk}) = \beta_0+\beta_x x_{ijk}+\beta_z z_{jk}+\beta_w w_k+u_k+v_{jk}. $$

Here \(u_k\) is a school random intercept and \(v_{jk}\) is a class-within-school random intercept. The model assumes the specified conditional Bernoulli response distribution and, conditional on the random effects and predictors, independent responses. A usual random-intercept specification treats the random effects as mean-zero with a stated distribution, often jointly normal, and uses a link function appropriate to the response. The fixed coefficients describe conditional associations on the log-odds scale: for example, \(\beta_z\) is the modeled change in log odds for a one-unit difference in the class-level predictor, holding the other fixed predictors and random effects constant.

The subscripts expose the assignment: \(x_{ijk}\) can differ between observations in the same class; \(z_{jk}\) can differ between classes but not among observations within one class; and \(w_k\) can differ between schools but not among classes in a school. In an actual data file, the latter two values are commonly repeated down the rows for convenience. Their level does not change just because they are copied onto each row.

Worked Example: Patient, Clinic, and Region Predictors

Consider a hypothetical data set of patients nested in clinics, with clinics nested in regions. The response \(Y_{ijk}\) indicates whether patient \(i\) in clinic \(j\), region \(k\), is readmitted within 30 days. The predictors are patient age in years \(x_{ijk}\), number of patient comorbidities \(c_{ijk}\), clinic staffing index \(s_{jk}\), and a region indicator \(r_k\) (1 for urban, 0 otherwise). Suppose the fitted model is

$$ \operatorname{logit}(p_{ijk}) = -1.20+0.03x_{ijk}+0.50c_{ijk}-0.15s_{jk}+0.25r_k+a_k+b_{jk}. $$

Age and comorbidity count are observation-level: patients in the same clinic can have different values. The staffing index is clinic-level because it is shared by patients in a clinic. The urban indicator is region-level because it is shared by clinics in a region. The clinic and region intercepts \(b_{jk}\) and \(a_k\) represent modeled group deviations, not additional observed predictors.

For a hypothetical patient aged 60 with two comorbidities, in a clinic with staffing index 4, in an urban region, suppose the estimated region and clinic random intercepts are \(-0.10\) and \(0.20\). Then

$$ \eta = -1.20+0.03(60)+0.50(2)-0.15(4)+0.25(1)-0.10+0.20 = 1.35. $$

The corresponding conditional fitted probability is

$$ \hat p = \frac{\exp(1.35)}{1+\exp(1.35)} \approx 0.7941. $$

Thus the model gives about a 0.794 conditional fitted probability for this specified patient and these estimated group effects. This is a model-based prediction, not a causal claim about changing the staffing index or moving a patient to an urban region.

How to Determine a Predictor’s Level

Start from the observational unit represented by one outcome record, then ask where each predictor is actually defined and which units can have distinct values. A reliable audit uses identifiers as well as variable names. For each candidate predictor, compare values among observations sharing a class, school, subject, item, or other relevant grouping unit. If the value is constant within every clinic but differs across clinics, that is evidence of a clinic-level predictor. If it changes among patients in the same clinic, it is not clinic-level merely because the clinic identifier is also on the row.

The design determines whether the grouping is nested or crossed. In a nested hierarchy, every class belongs to one school. In a crossed design, an observation can belong to one subject and one item, with subjects appearing with multiple items and items appearing with multiple subjects. A subject attribute is subject-level, and an item attribute is item-level, even though neither sits above the other in a single hierarchy.

Worked Example: A Crossed Subject-and-Item Experiment

In a hypothetical binary-response experiment, each record is one response by subject \(s\) to item \(q\). Let \(t_{sq}\) be the trial number for that particular response, \(A_s\) the subject’s age in years, and \(D_q\) the item’s difficulty score. The data include repeated observations from subjects across items and repeated items across subjects. A possible model is

$$ \operatorname{logit}(p_{sq}) = -0.50-0.10t_{sq}+0.04A_s+0.20D_q+u_s+v_q. $$

Trial number is observation-level because it can change from one response record to another for the same subject and item. Age is subject-level, and difficulty is item-level. The crossed random intercepts \(u_s\) and \(v_q\) account for residual subject and item differences; the predictors remain assigned to their respective units.

For a response on trial 2 from a 30-year-old subject to an item with difficulty score 3, suppose \(u_s=0.30\) and \(v_q=-0.20\). Substitution gives

$$ \eta = -0.50-0.10(2)+0.04(30)+0.20(3)+0.30-0.20 = 1.20, \qquad \hat p=\frac{\exp(1.20)}{1+\exp(1.20)}\approx0.7685. $$

The fitted probability is conditional on the stated subject and item effects. The fact that age is repeated on many response rows does not create more independent subjects with distinct ages; the age information comes from differences among subjects.

Why Group-Level Predictors Need Between-Group Information

A short algebraic argument clarifies why a group-level predictor must be supported by variation across groups. For two observations \(i\) and \(i'\) in the same group \(j\), consider a random-intercept model with observation-level \(x_{ij}\) and group-level \(z_j\):

$$ \eta_{ij}=\beta_0+\beta_x x_{ij}+\beta_z z_j+u_j,\qquad \eta_{ij}-\eta_{i'j}=\beta_x(x_{ij}-x_{i'j}). $$

The \(\beta_z z_j\) term and the group intercept cancel in the within-group contrast because both are shared by the two observations. Therefore, within-group contrasts can inform the observation-level association but do not, by themselves, distinguish the coefficient of \(z_j\). That coefficient is learned from differences between groups with different \(z_j\) values, under the model’s assumptions. Repeating \(z_j\) on every row does not turn those rows into independent group-level units.

Worked Example: Class and School Predictors

Suppose a hypothetical school dataset has one row per student. The response records whether the student passed an assessment. Predictors are each student’s weekly study hours \(h_{ijk}\), the class’s average class size \(m_{jk}\), and the school’s tutoring-program indicator \(q_k\). Each class belongs to exactly one school. A model might include

$$ \operatorname{logit}(p_{ijk}) = -0.80+0.12h_{ijk}-0.04m_{jk}+0.35q_k+u_k+v_{jk}. $$

Study hours are observation-level, class size is class-level, and the tutoring indicator is school-level. For a student studying 5 hours per week in a class of 24, at a school with the program (\(q_k=1\)), suppose the school effect is \(0.10\) and the class effect is \(-0.20\). Then

$$ \eta = -0.80+0.12(5)-0.04(24)+0.35(1)+0.10-0.20 = -0.91, \qquad \hat p=\frac{\exp(-0.91)}{1+\exp(-0.91)}\approx0.2870. $$

This is the conditional fitted probability for the specified covariates and random effects. Notice that the school program indicator is not a student characteristic merely because it appears on the student’s row. If the program is identical in every school, however, there is no observed between-school contrast in this data with which to estimate its association separately from the intercept; the correct level classification cannot remedy a lack of predictor variation.

Diagnostics, Alternatives, and Limitations

Before fitting the model, verify the level assignment against the data structure. A compact diagnostic table can list each predictor, its unit of definition, the number of distinct values within a typical grouping unit, and the number of groups across which it varies. Check the group identifiers for data-entry inconsistencies: a supposedly fixed school policy that changes across rows within the same school may indicate a merge or coding error, a time-varying policy, or a misidentified unit. Decide which explanation matches the design before modeling.

  • Inspect variation within and between groups. A predictor labeled group-level should be constant within its defined group at the relevant time. A predictor with no variation across groups cannot estimate a between-group coefficient.
  • Check membership structure. Confirm whether an observation has one parent group at each nested level or multiple crossed memberships. A wrongly assigned hierarchy can put predictors and random effects on the wrong units.
  • Check the number of independent units. A group-level coefficient is supported by the number and range of distinct groups, not simply the total number of rows. Very few groups or little between-group variation can produce unstable estimates and wide uncertainty.
  • Check the scientific definition and timing. An aggregate computed from the same observations may have a different interpretation from a separately measured group characteristic. Time-varying group conditions may require an explicitly time-indexed predictor rather than a constant group-level column.

A pooled GLM can be simpler, but it does not represent within-group dependence through random effects. A mixed model separates fixed predictor terms from group-specific deviations while retaining the chosen hierarchy. Another approach is to include group indicators as fixed effects. Those indicators can control for group differences, but if each group has its own unrestricted indicator, any predictor constant within group is perfectly represented by those indicators and its separate coefficient cannot be estimated. Thus fixed group indicators are not an automatic substitute when the aim is to estimate an association for a group-level predictor.

Level-specific coefficients are also not automatically causal effects. A school-level policy may be associated with unmeasured school characteristics, and a subject attribute may be associated with how subjects entered the experiment. The model’s conditional association depends on the chosen specification and assumptions. Finally, observed values may vary at more than one meaningful level, such as a person’s current stress and their long-term average stress. Distinguishing these components requires a deliberate predictor construction; simply labeling the raw column “individual-level” does not resolve its interpretation.

Common pitfall: “This clinic’s staffing index is recorded on every patient row, so it is an observation-level predictor.” That reasoning confuses data storage with variation and measurement. If all patients in a clinic share the same index, it is clinic-level. Its coefficient is informed by differences between clinics, not by treating repeated copies as independent clinic measurements.
Key takeaway: Assign each predictor by asking which unit it describes and which units can differ in its value. Then make the fixed-effect term and the grouping structure match that answer; do not infer a predictor’s level from the layout of the data table.

Check Your Understanding

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

  1. In a model of patients within hospitals, each patient has a blood-pressure measurement and each hospital has a region label. Classify both predictors.
  2. In a crossed subject-and-item study, what level is an item’s word frequency if it is the same every time that item is shown?
  3. A school-level indicator is copied onto 600 student rows from six schools. How many distinct school-level units provide variation for estimating its association?
  4. In a nested class-within-school model, a predictor is constant within each class but differs among classes within schools. What is its level?
  5. Why can an unrestricted set of hospital fixed indicators prevent estimation of a hospital-level policy coefficient?

Solutions. (1) Blood pressure is observation-level; region is hospital-level if each hospital belongs to one region and the label is shared by its patients. (2) Item-level, because it is defined for an item and shared across subjects’ responses to that item. (3) Six distinct schools, not 600 independent school-level values. (4) Class-level, because it is shared within a class but can differ across classes. (5) The policy is constant within each hospital and is therefore represented by the hospital indicators; its separate coefficient is not distinguishable from unrestricted hospital-specific intercepts.

Clinical Biostats