Why a Category’s Role Is Not Determined by Its Name
A data set may contain categorical variables called “site,” “treatment,” “classroom,” or “region.” Those names do not decide how a variable enters a generalized linear mixed model (GLMM). A site can be a sampled grouping level, a specific site of direct interest, or simply part of a label used to identify lower-level units. The decisive questions are what units the study samples and whether observations reuse those units.
This distinction matters because a grouping effect represents modeled variation among units and induces dependence among observations that share a unit. A fixed categorical predictor instead represents differences among specified categories. A label identifies membership; it need not have a coefficient of its own. The earlier material on nested and cross-classified structures establishes how membership patterns describe those relationships. Here the focus is deciding what a categorical variable represents before choosing its model role.
Three Roles for Categorical Variables
For a grouping factor, the modeled units are the groups, not the category names as such. For example, if patients are observed at sampled clinics, clinic membership can define a level: patients from the same clinic share a clinic effect. A random intercept for clinic represents a distribution of clinic deviations, commonly modeled as independent normal effects with mean zero and variance \(\tau^2\).
A fixed categorical predictor has a different purpose. Suppose the study compares three specified treatment arms. The arms are categories of substantive interest, so the model can assign coefficients to contrasts among them. The treatment factor is not a grouping level merely because its values are categories. In particular, patients in the same treatment arm do not become a cluster just because they share the treatment label.
A nested label can look like a categorical factor in a data file but primarily serves as an identifier. If classrooms are numbered 1, 2, and 3 separately within each school, “classroom 1” at one school is not automatically the same unit as “classroom 1” at another. The school and classroom membership together identify the classroom. Whether classrooms define a sampling level depends on the study structure and the model’s intended representation of variation among classrooms, not on the classroom numbers.
A Model-Based Reason for Tracking Membership
Consider a binary response \(Y_{ij}\) from observation \(i\) in sampled group \(j\). One possible random-intercept GLMM is
This formulation assumes the response distribution and link are appropriate, the fixed-effects part is correctly specified, and the group effects follow the stated distribution and are independent across groups. Conditional on the random effects and predictors, observations are assumed independent. The random intercept accounts for a shared group deviation; it does not make all observations unconditionally independent.
The membership structure implies a precise covariance pattern on the linear predictor. For two observations \(r\) and \(s\) in groups \(j(r)\) and \(j(s)\), let \(\eta_r=\beta_0+\beta_1x_r+b_{j(r)}\). Conditional on the fixed predictors, independence and common variance of the group effects give
The justification is direct: fixed terms have no random covariance, while two observations in the same group contain the same random variable \(b_j\), whose variance is \(\tau^2\). Different groups have independent random effects. This is covariance of the linear predictors, not a claim that the binary responses have covariance exactly equal to \(\tau^2\). The response dependence is induced through the shared random effect and the link.
The model is defensible only if the group definition matches the design and the groups provide information about between-group variation. If every observation has a unique group label, there is no repeated membership to distinguish a group-level variance from observation-level variation in this basic random-intercept structure. If observations share groups but those groups were not sampled or reasonably treated as exchangeable units, the random-effects interpretation may also be inappropriate.
Worked Example: Clinics as Sampled Grouping Levels
Suppose a hypothetical study records a binary outcome for six patients at each of eight clinics selected from a larger set of clinics. A fitted logistic random-intercept model reports a clinic-intercept variance estimate of \(\hat{\tau}^2=0.36\). Is clinic a sampling level, and what does that estimated variance imply for the linear predictors?
Classification. Clinics are sampled units, and multiple patients are observed within each clinic. Clinic membership is therefore a plausible grouping level. The model treats clinic deviations as draws from a population distribution, rather than estimating a separate clinic coefficient as the sole target for each of these eight named clinics.
For two patients at the same clinic, the random-intercept contribution to the covariance of their linear predictors is the estimated variance:
The estimated standard deviation of clinic intercepts is \(\sqrt{0.36}=0.60\) log-odds units. A one-standard-deviation increase in the clinic intercept multiplies conditional odds by \(\exp(0.60)\approx1.822\), with other predictors held fixed. This is a description of the fitted model’s clinic-level variation, not evidence that clinics cause outcome differences.
The design supports the proposed grouping structure because each clinic contributes repeated observations, and clinics are sampled from a broader set. The distributional and link assumptions still require substantive and diagnostic assessment; the membership pattern alone does not prove them.
When the Categories Are Predictors, Not Groups
The contrast with a fixed predictor is easiest to see by asking what would count as the scientific comparison. If the question concerns differences among a specified set of arms, regions, or device types, the categories themselves may be the objects of comparison. A model can represent those differences with fixed coefficients. The fact that many observations share a category does not create a random intercept for that category automatically.
A fixed categorical predictor generally requires a reference category or another explicit contrast scheme. Its coefficients describe modeled differences relative to the chosen reference or contrast, subject to the link and other predictors. A random grouping effect instead represents a distribution of group deviations and is usually intended to capture dependence and between-group heterogeneity. Which role is appropriate depends on the estimand, design, and set of units to which conclusions are intended to extend—not simply on whether the factor has “few” or “many” values.
Worked Example: Treatment Arm as a Fixed Predictor
In a hypothetical trial, participants are assigned to one of two specified arms, A or B, and each participant contributes one binary outcome. Participants are also recruited at multiple clinics, with several participants per clinic. Suppose the fitted model is
where \(b_s\) is a clinic random intercept and \(I(\text{arm}_i=B)\) equals 1 for arm B and 0 for arm A. The treatment arms are the specified categories of interest, so arm is a fixed predictor. Clinic can separately be a grouping level because multiple participants share clinics.
At \(b_s=0\), the fitted probability for arm A is
For arm B, the linear predictor at \(b_s=0\) is \(-1.20+0.70=-0.50\), giving
The fitted conditional odds ratio for B versus A is \(\exp(0.70)\approx2.014\). It compares the arms at the same clinic random intercept; it is not a marginal probability contrast averaged over clinics. The classification follows the design: the arms are specific treatment categories to compare, while clinic membership accounts for shared outcomes among participants treated at the same clinic. This interpretation describes the model; causal conclusions additionally depend on the trial design and its assumptions.
Labels Within Another Factor
A label can be locally meaningful without naming the same unit throughout the data set. Suppose school S1 has classrooms numbered 1 and 2, and school S2 also has classrooms numbered 1 and 2. The value “1” alone is not a globally unique classroom identifier. The pair (school, classroom number) identifies a classroom. If several outcomes are observed within each classroom, those memberships can support a classroom-level component nested within school.
For example, a model with independent school and classroom-within-school random intercepts has the form
where \(j\) indexes schools, \(k\) indexes classrooms within school \(j\), and \(i\) indexes observations within classroom \(k\) of school \(j\). Under the stated independent, mean-zero random-effects assumptions, two linear predictors in the same classroom share both \(u_j\) and \(v_{jk}\); observations in different classrooms of the same school share only \(u_j\); observations in different schools share neither. This explains why membership—not the classroom number printed in the file—determines the structure.
Worked Example: Reused Classroom Numbers Within Schools
Suppose a hypothetical data set contains four sampled schools. Each school has classrooms labeled 1 and 2, with three binary outcomes recorded per classroom. A fitted model reports school-intercept variance \(\hat{\sigma}^2_{\text{school}}=0.25\) and classroom-within-school variance \(\hat{\sigma}^2_{\text{class}}=0.49\). Treat the classroom labels as locally nested identifiers. Find the random-effect covariance of the linear predictors for three pairs of observations.
Two observations in the same classroom share the school and classroom random effects. Their covariance is
Two observations in different classrooms of the same school share only the school effect, so their covariance is \(0.25\). Two observations from different schools share neither effect, so their covariance is \(0\) under the model’s independence assumptions.
Thus “classroom 1” in school 1 and “classroom 1” in school 2 are not the same group. Treating the label 1 as a single globally shared category would assert a shared random effect across those schools, contrary to the sampling structure described. The values identify classrooms only in combination with school membership.
A Practical Classification Check
Before assigning a model role to a categorical variable, reconstruct the study’s sampling and membership structure. A useful check is to list the observational units and trace whether each value is reused for multiple observations, whether the same units recur across other factors, and what category differences the analysis is intended to estimate.
State what one response represents and identify the larger units from which observations, sites, or groups were sampled.
Check whether multiple observations share a unit. Record whether a label is globally unique or meaningful only within another factor.
Ask whether the analysis compares specified categories, estimates variation among sampled units, or only needs the labels to define membership.
Confirm that the proposed random effects induce dependence for precisely the observations that share the modeled units.
This classification is a design-based decision, not a mechanical rule based on the number of categories. A factor with only a few levels may be fixed if those particular levels are the comparison of interest. A factor with many levels may still be fixed when each level is specifically important. Conversely, many observed groups do not justify random effects if their membership and sampling do not support that interpretation.
Diagnostics, Alternatives, and Limits
Structural choices should be checked against the data and design. A membership table or cross-tabulation can reveal labels that are reused unexpectedly, categories with only one observation, or apparent groups that are actually one-to-one with individual records. Compare the proposed group assignments with the sampling records. Then examine model convergence, estimated variance components, and residual patterns for signs that the fitted dependence structure is inadequate. A variance estimate near zero can indicate little evidence for that component in the fitted model, but it does not by itself prove that the study design had no grouping.
Several warning signs deserve particular attention:
- Every identifier is declared random. A row ID that occurs once per observation does not create repeated within-group information for a random intercept.
- Every repeated category is called a cluster. Sharing a treatment arm does not make observations a sampled group; the role depends on the sampling design and target of inference.
- Local labels are treated as global IDs. Classroom 1 within each of several schools may denote different classrooms.
- Only the category count is used to choose fixed versus random. The inferential target and sampling scheme matter at least as much as the number of observed levels.
- A zero or unstable variance is ignored. Sparse replication, too few groups, or confounding among factors can leave a variance component weakly identified or make the assumed structure difficult to assess.
A fixed categorical predictor is a reasonable alternative when the scientific target is a set of explicit category contrasts. A random grouping effect is a reasonable alternative when groups represent sampled or exchangeable units and shared membership should induce dependence. A nested label is not a competing scientific predictor unless the label itself carries substantive meaning; it may simply define which observations share a lower-level unit. These approaches answer different questions, so they should not be chosen solely because one is computationally convenient.
No classification resolves poor design or unsupported assumptions. A small number of sampled groups can provide limited information about between-group variation; highly unbalanced membership can leave some comparisons weakly supported; and a grouping factor may be confounded with a predictor. A factor’s category labels alone cannot establish exchangeability, normality of random effects, or an appropriate link. Those assumptions need to be justified and assessed for the particular application.
Check Your Understanding
Answer each question by referring to the sampling scheme and the intended comparison. Solutions follow the questions.
- A study samples 15 hospitals from a wider network and observes several patients per hospital. What role can hospital play, and what feature of the design supports it?
- A trial compares two named diets, with each participant contributing one response. Should diet automatically be a random grouping effect because many participants share each diet? Explain.
- Three schools each have rooms labeled A and B. What identifies a room, and why might the room letters alone be inadequate group identifiers?
- A data set has a unique patient code for every row and only one response per patient. Does the code alone support a patient random intercept in that data set?
- State one reason why the number of observed categories alone cannot decide whether a factor is fixed or random.
Solutions. (1) Hospital can be a grouping level because hospitals are sampled units and multiple patients share each hospital, allowing shared hospital variation to represent dependence. (2) No. Diet is a fixed predictor if the specified diets are the categories being compared; sharing a diet label does not itself make participants a sampled group. (3) The school-room pair identifies a room. The letter alone is reused at different schools and therefore does not uniquely identify one room. (4) No. A unique code with one response per patient gives no repeated within-patient observations for that random intercept; the code is an identifier, not evidence of a grouping structure. (5) Fixed versus random role depends on the sampling scheme and inferential target: a few specified categories can be fixed, while sampled units can be modeled as random when the assumptions and target support it.