Unequal Sizes Do Not Alter the Hierarchy
Nested data are often unbalanced: schools may contain different numbers of classes, and classes may contain different numbers of students. This variation changes how much information is observed in each group, but it does not by itself change which groups contain which observations. The key modeling task is to represent the membership structure correctly and then consider whether the observed cluster sizes are compatible with the assumptions and the intended interpretation.
Let \(a=1,\ldots,A\) index the highest-level groups, \(b=1,\ldots,B_a\) index the lower-level groups within group \(a\), and \(i=1,\ldots,n_{ab}\) index observations within lower-level group \(b\) of group \(a\). Both \(B_a\), the number of lower-level groups in group \(a\), and \(n_{ab}\), the number of observations in lower-level group \(ab\), may vary. The lower-level group is nested in the higher-level group when each lower-level group belongs to exactly one higher-level group.
A useful distinction is between the membership map and the counts. The membership map says which observation belongs to which lower-level group and which lower-level group belongs to which higher-level group. Counts summarize how many observations or subgroups appear under each parent. A data set can have highly unequal counts and still have a simple, strictly nested hierarchy.
A Nested Random-Intercept GLMM
For a response \(Y_{abi}\) from observation \(i\) in lower-level group \(ab\), consider the following random-intercept GLMM:
Here \(g\) is the link function, \(\mathbf{x}_{abi}\) is the covariate vector, \(\boldsymbol{\beta}\) is the vector of fixed-effect coefficients, \(U_a\) is the random intercept for higher-level group \(a\), and \(V_{ab}\) is the random intercept for lower-level group \(ab\). A standard specification assumes \(U_a\sim N(0,\tau_A^2)\) and \(V_{ab}\sim N(0,\tau_B^2)\), mutually independent across groups and levels. Conditional on the random effects and covariates, the responses are independent and follow the chosen response distribution, with mean related to the linear predictor through \(g\).
The index ranges allow unequal sizes directly: the model has a random effect \(U_a\) for each observed higher-level group and a random effect \(V_{ab}\) for each observed lower-level group. There is no requirement that all \(B_a\) values be the same, or that all \(n_{ab}\) values be the same. Unequal counts do not require a different nesting formula.
These assumptions are substantive. The response distribution and link must suit the outcome; the random-effects distribution and covariance structure must be reasonable; and the membership identifiers must be correct. Conditional independence means that, after conditioning on the modeled random effects and covariates, there is no additional unmodeled dependence among responses. If a cluster-size process is related to latent group characteristics in a way relevant to the response, treating the observed sizes as innocuous can also be inadequate.
Worked Example: Writing the Indices for Unequal School and Class Sizes
Suppose a hypothetical data set contains three schools. School 1 has two classes with 3 and 5 students; school 2 has one class with 4 students; and school 3 has three classes with 2, 4, and 6 students. Identify the indices and write the random-intercept structure for a student's binary outcome.
There are \(A=3\) schools, with \(B_1=2\), \(B_2=1\), and \(B_3=3\). The class sizes are \(n_{11}=3\), \(n_{12}=5\), \(n_{21}=4\), \(n_{31}=2\), \(n_{32}=4\), and \(n_{33}=6\). The total number of students is \(3+5+4+2+4+6=24\).
For a binary outcome, a logit model could be \( \operatorname{logit}\{P(Y_{abi}=1\mid U_a,V_{ab})\} =\beta_0+\beta_1x_{abi}+U_a+V_{ab} \). Each student has one school index \(a\), one class-within-school index \(ab\), and a student index \(i\) within that class. The different class counts and sizes alter the ranges of the indices, not the assignment rule. A class identifier must distinguish classes in different schools: class 1 in school 2 is not the same random-effect level as class 1 in school 3.
What Unequal Sizes Change: Information and Precision
Although unequal sizes do not change the hierarchy, they do affect how much information is observed about each group. In a random-intercept model, a group with many observations generally provides more information about its own conditional mean than a group with few observations. It does not follow that every group should receive equal influence in every summary or that the largest groups are automatically representative of the intended population.
The covariance structure makes the role of membership explicit. For illustration, take a Gaussian identity-link model with independent residuals: \(Y_{abi}=\beta_0+U_a+V_{ab}+\varepsilon_{abi}\), where \(U_a\sim N(0,\tau_A^2)\), \(V_{ab}\sim N(0,\tau_B^2)\), and \(\varepsilon_{abi}\sim N(0,\sigma^2)\), with all components independent. The variances are assumed constant across groups. For two distinct observations, covariance comes from the random effects they share.
The first case shares both random intercepts; the second shares only the higher-level intercept; the third shares neither. The group-size counts do not appear in these pairwise covariance expressions. They determine how many observations of each pair type are present, and therefore affect the amount and balance of information available for estimating model parameters.
Worked Example: Unequal Sizes and the Precision of Class Means
Use the Gaussian nested model above with \(\tau_A^2=0.25\), \(\tau_B^2=0.16\), and \(\sigma^2=0.64\). Compare the variance of the mean response in a class of 2 students with that in a class of 8 students, within the same school.
For a class with \(n\) students, its sample mean is \(\bar{Y}_{ab}=\beta_0+U_a+V_{ab}+\bar{\varepsilon}_{ab}\). The variance of the mean residual is \(\operatorname{Var}(\bar{\varepsilon}_{ab})=\sigma^2/n\), because the residuals are independent with variance \(\sigma^2\). Thus \(\operatorname{Var}(\bar{Y}_{ab})=\tau_A^2+\tau_B^2+\sigma^2/n\).
For \(n=2\), the variance is \(0.25+0.16+0.64/2=0.25+0.16+0.32=0.73\). For \(n=8\), it is \(0.25+0.16+0.64/8=0.25+0.16+0.08=0.49\). The larger class mean has lower variance because its averaged residual component is smaller. It does not eliminate uncertainty due to the shared school and class effects.
This calculation concerns the variance of a class mean under the stated Gaussian model, not a rule that larger classes should be treated as independent replications of the school effect. Eight students in one class share both group effects; they are not equivalent to eight students in eight independent schools.
Conditional Predictions and Cluster-Size Interpretation
For a nonlinear link, the cluster sizes do not enter the conditional mean formula directly. They affect which observations are available and how strongly data inform the fitted effects, while a particular conditional probability is calculated from that observation's covariates and its group's random effects. This distinction is important: changing the number of students in a class does not by itself change the probability assigned to a particular student when the covariates and random effects are held fixed.
Worked Example: A Conditional Probability in an Unequal-Size Hierarchy
In a hypothetical logistic nested model, suppose the linear predictor for a specified student is \(-1.20\), after substituting the student's covariate value and the school and class random intercepts. The class happens to contain 5 students, while other classes have different sizes. Calculate the student's conditional event probability.
For the logit link, \(P(Y=1\mid U,V)=\exp(\eta)/(1+\exp(\eta))\), where \(\eta\) is the conditional linear predictor. Therefore, \(P(Y=1\mid U,V)=\exp(-1.20)/(1+\exp(-1.20))\).
Using \(\exp(-1.20)\approx0.3012\), the probability is \(0.3012/(1+0.3012)=0.3012/1.3012\approx0.2315\). The fitted conditional probability is about \(0.231\), or 23.15%. This is conditional on the specified covariates and random effects; it is not a marginal probability averaged over the random-effects distributions. The fact that the class has 5 students does not alter this calculation.
A separate issue is whether the desired summary gives equal weight to groups or equal weight to individuals. Those are different targets when group sizes vary. For example, the unweighted average of group-specific outcome rates gives each group the same contribution, whereas pooling all individual outcomes gives more influence to groups with more observations. Neither summary is universally correct; the choice should match the scientific question and the sampling design.
Worked Example: Equal-Group and Pooled Event Rates
Two hypothetical clinics are observed. Clinic A has 0 events among 2 patients, and clinic B has 6 events among 8 patients. Compare the equal-clinic average of the observed rates with the pooled patient event rate.
The clinic-specific rates are \(0/2=0\) and \(6/8=0.75\). Giving each clinic equal weight yields \((0+0.75)/2=0.375\), or 37.5%. Pooling patients yields \((0+6)/(2+8)=6/10=0.60\), or 60.0%.
These quantities answer different descriptive questions: the first is the average of the two clinic rates, and the second is the event proportion among the 10 observed patients. They are not necessarily estimates of the same target. In a GLMM, the likelihood uses the individual response records and the specified random-effects structure; the resulting fixed effects should not automatically be described as either of these raw summaries.
Justification: Why the Membership Pattern Determines Covariance
The covariance formula follows directly from the model and shows why changing counts is not the same as changing the hierarchy. Consider two distinct responses in the same class and write each as the sum of its fixed mean, the shared school effect, the shared class effect, and its own residual. Fixed means do not contribute to covariance, and independent residuals for distinct observations have covariance zero. Independence of the random effects then gives \(\operatorname{Cov}(Y_{abi},Y_{abi'})=\operatorname{Var}(U_a)+\operatorname{Var}(V_{ab})=\tau_A^2+\tau_B^2\).
For observations in different classes of the same school, \(U_a\) is shared but the class effects and residuals are independent, so the covariance is \(\operatorname{Var}(U_a)=\tau_A^2\). For observations from different schools, no random effect is shared, so the covariance is zero under this model. The derivation depends on who shares which random effects, not on how many observations happen to be in each group. In a GLMM with a nonlinear link, these expressions describe the latent linear predictor's random-effect covariance structure; they are not generally the response-scale covariances.
Diagnostics, Alternatives, and Limitations
Unequal sizes can make estimation less balanced and can expose model weaknesses. Check the group counts and the membership identifiers before fitting: duplicate labels, groups assigned to multiple parents, or a mistaken hierarchy can create a different dependence model. Examine whether a small number of very large clusters dominate the information, whether some levels have too few observations to estimate their variability reliably, and whether model convergence or random-effect estimates are sensitive to a few groups. Residual and fitted-value checks should respect the response distribution and the conditional structure; apparent extra dependence may indicate omitted structure rather than an unequal-size problem itself.
A particularly important failure mode is informative cluster size. Cluster size is informative when it is associated with outcomes or latent group characteristics in a way relevant to the analysis. For instance, if clinics with higher underlying event risk systematically contribute more patients, a model that conditions on observed size without accounting for this relationship may not answer the intended population-level question. The assumption that size is noninformative is not guaranteed merely because the random effects are normally distributed. Consider the data-generation and sampling processes, and decide whether the target is an average group, an average individual, or another population quantity. If needed, model the size process jointly, use a design-appropriate weighting or sampling approach, or conduct sensitivity analyses.
Common alternatives have distinct consequences. Aggregating each group to one summary loses individual-level information and can obscure within-group covariate effects; it is not a neutral way to handle unequal sizes. Treating groups as fixed effects may be useful for specific within-group comparisons, but it changes the target and does not estimate a population distribution of group effects in the same way as random effects. A model with only one grouping level is simpler, but it is inappropriate when dependence genuinely occurs at multiple nested levels. The appropriate choice follows the design and estimand, not the convenience of a balanced data table.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions below.
- Each of four schools has a different number of classes, and each class has a different number of students. What fact determines whether classes are nested within schools?
- In the Gaussian random-intercept model, two distinct observations share a class and school. What is their covariance in terms of the variance components?
- Suppose a class has 10 students rather than 5. Does that change the conditional logit probability for a specified student if the covariates and random effects are held fixed? Explain.
- Two clinics have rates 0.20 and 0.80, and each clinic is given equal weight. What is their equal-clinic average rate? Why might this differ from the pooled patient rate?
Solutions. (1) Classes are nested in schools if each class belongs to exactly one school. Different numbers of classes or students do not change that membership rule. (2) The covariance is \(\tau_A^2+\tau_B^2\), because the observations share both the school and class random intercepts, while their residuals are independent. (3) No. With the linear predictor and random effects fixed, the conditional logit probability is determined by that linear predictor; the class size affects the amount of data, not the probability formula for that student. (4) The equal-clinic average is \((0.20+0.80)/2=0.50\). The pooled patient rate weights clinics according to their patient counts, so it can differ whenever clinic sizes differ and their rates are not identical.