Hierarchical Linear Models: From Statistical Principles to Modeling Practice
Hierarchical linear models, also called multilevel linear models, analyze nested or grouped data by separating overall patterns from group-level variation. This guide explains why complete pooling and separate group regressions can fail, how random intercepts, random slopes, cross-level interactions, and centering work, and how to estimate, diagnose, validate, and report these models.
1. What hierarchical linear models address
Hierarchical linear models are statistical models for hierarchical, grouped, or nested data. They are also commonly called multilevel linear models. In ordinary linear modeling, they belong to the class of linear mixed-effects models: fixed effects describe overall patterns, while random effects describe how groups deviate from those patterns.
Students belong to different schools, employees belong to different departments, and the same device can produce repeated measurements. Data like these often violate the ordinary linear regression assumption that errors are mutually independent. Students in the same school may share a teaching environment, and measurements from the same device may be affected by a common device state, so observations within a group are typically correlated.
Ignoring this structure does not necessarily bias the regression coefficients, but it can distort standard errors, confidence intervals, and significance tests. It also fails to describe group differences adequately. The value of a hierarchical linear model is that it separates individual-level variation from group-level variation.
In terminology, random-coefficient regression emphasizes that some regression coefficients vary across groups, while covariance-component models emphasize describing dependence among observations through variances and covariances from different sources. These names are closely related to multilevel linear modeling, but they do not mean that every mixed-effects model can handle only strictly nested hierarchies.
2. Why simply pooling or fitting each group separately is not enough
Two common approaches to grouped data are complete pooling and no pooling.
Complete pooling places all observations together and fits one shared regression relationship. It is structurally simple, but without additional handling of group dependence it may ignore within-group correlation and mix between-group differences into the individual-level relationship.
No pooling fits a separate model for each group. It preserves group differences, but coefficients for small groups can be strongly affected by a few unusual observations, and groups cannot share information.
Hierarchical linear models use partial pooling. Each group has its own parameters, but those parameters are treated as draws from a shared population distribution. Estimates for groups with little information are generally pulled closer to the overall mean, while groups with more information retain more of the differences supported by their own data.
This mechanism is usually called shrinkage. Shrinkage does not forcibly erase group differences. It is a model-determined tradeoff between information from the group itself and information shared by the population. The amount of shrinkage depends not only on group sample size, but also on between-group variation, within-group noise, and the distribution of the explanatory variables.
3. Understanding within-group correlation through the empty model
Start with a two-level model that has only a random intercept and no explanatory variables:
[
y{ij}=\beta_0+u{0j}+\varepsilon_{ij}
]
Here, (i) indexes individuals within a group, and (j) indexes groups.
- (y_{ij}): the response for individual (i) in group (j).
- (\beta_0): the overall mean level.
- (u_{0j}): the deviation of group (j) from the overall mean.
- (\varepsilon_{ij}): the individual-level residual.
The usual baseline assumptions are:
[
u{0j}\sim N(0,\tau{00}),\qquad
\varepsilon_{ij}\sim N(0,\sigma^2)
]
The random intercepts are assumed to be independent of the individual residuals, and random effects from different groups are also assumed to be independent.
The marginal variance of the response is then:
[
\operatorname{Var}(y{ij})=\tau{00}+\sigma^2
]
The covariance between two different individuals in the same group is (\tau_{00}), so the intraclass correlation is:
[
\rho=\frac{\tau{00}}{\tau{00}+\sigma^2}
]
The intraclass correlation describes the correlation among observations in the same group. Under this model, it can also be interpreted as the share of total variation explained by group-level differences.
Whether to use a multilevel model should not depend only on the size of the intraclass correlation. When groups are large, the study has a clear hierarchical structure, or group effects need to be estimated, grouping dependence may still need to be modeled explicitly even if the correlation is modest.
4. Random-intercept models: allowing groups to start at different levels
After adding an individual-level explanatory variable, the model can be written as:
[
y{ij}=\beta_0+\beta_1x{ij}+u{0j}+\varepsilon{ij}
]
Here, (\beta1) is a fixed slope representing a linear relationship shared by all groups, while (\beta_0+u{0j}) is the intercept for group (j).
In an employee-performance analysis, (x_{ij}) might represent training duration. The model allows departments to have different baseline performance levels, while temporarily assuming that the slope relating training duration to performance is the same across departments.
If there is also a department-level explanatory variable (z_j), such as departmental workload, the model can be written as:
[
y{ij}=\beta_0+\beta_1x{ij}+\gamma1z_j+u{0j}+\varepsilon_{ij}
]
Group-level variables explain differences in group means. The random intercept represents the remaining group differences that those variables have not explained.
Adding a random intercept does not automatically remove omitted-variable bias. Classical models usually require random effects and explanatory variables to satisfy the corresponding independence or conditional-mean assumptions. If unobserved group characteristics are correlated with the explanatory variables, consider adding group means, adjusting the model structure, or using an estimation method better aligned with the research goal.
5. Random-slope models: allowing the strength of an effect to differ
When the relationship between an explanatory variable and the response may differ by group, a random slope can be added:
[
y{ij}=\beta_0+\beta_1x{ij}+u{0j}+u{1j}x{ij}+\varepsilon{ij}
]
The slope for group (j) is (\beta1+u{1j}). A common model jointly describes the random intercept and random slope:
[
\begin{pmatrix}
u{0j}\
u{1j}
\end{pmatrix}
\sim N\left[
\begin{pmatrix}
0\
0
\end{pmatrix},
\begin{pmatrix}
\tau{00}&\tau{01}\
\tau{01}&\tau{11}
\end{pmatrix}
\right]
]
Here, (\tau{11}) is the variation of the slope across groups, and (\tau{01}) is the covariance between the intercept and the slope.
Once a random slope is included, within-group correlation is generally no longer fully described by one fixed number. The covariance between two observations in the same group changes with the values of their explanatory variables, so the empty-model intraclass-correlation formula should not be applied directly to the entire correlation structure.
Random slopes also require sufficient data. If an explanatory variable barely varies within groups, or if there are too few groups, the model may have difficulty distinguishing slope differences from random noise.
6. Cross-level interactions and variable centering
6.1 Cross-level interaction
If departmental workload changes the relationship between training duration and performance, the individual-level slope can depend on the group variable:
[
y{ij}=\beta_0+\beta_1x{ij}+\gamma1z_j+
\gamma_2x{ij}zj+u{0j}+u{1j}x{ij}+\varepsilon_{ij}
]
Here, (\gamma_2) is the cross-level interaction coefficient. It describes how the individual-level slope changes when the group variable changes by one unit.
When interpreting an interaction, show the predicted relationship at different levels of the group variable rather than judging only whether the interaction coefficient is significant.
6.2 Separating within-group and between-group effects
The same explanatory variable can contain two different kinds of information:
- Within-group differences: among employees in the same department, do those with more training have higher performance?
- Between-group differences: do departments with higher average training have higher average performance?
These relationships are not necessarily the same. The variable can be decomposed as:
[
x{ij}=(x{ij}-\bar{x}_j)+\bar{x}_j
]
The within-group deviation (x_{ij}-\bar{x}_j) and the group mean (\bar{x}_j) can then be included separately. This helps avoid interpreting an association between groups as an association between individuals.
Grand-mean centering is mainly used to adjust the reference point of a variable and improve interpretation of the intercept. Group-mean centering is used to isolate within-group relationships. Centering does not replace control for confounding, and it does not automatically give the model a causal interpretation.
7. Parameter estimation and model comparison
Linear mixed-effects models are usually estimated by maximum likelihood or restricted maximum likelihood. Bayesian methods can also be used.
Maximum likelihood estimates fixed effects and variance parameters together. Restricted maximum likelihood accounts for the information used by estimating the fixed effects when estimating variance components, so it is often used for variance-component estimation.
When comparing models, keep these principles in mind:
- When comparing different fixed-effect structures, usually fit the models by maximum likelihood and ensure that they use the same response variable and the same observations. Restricted maximum likelihood values under different fixed-effect designs generally cannot be compared directly.
- When comparing random-effect structures, combine theoretical justification, estimation stability, and model diagnostics. A variance parameter of zero lies on the boundary of the parameter space, so the reference distribution of a conventional likelihood-ratio test may not apply.
- When using information criteria, confirm that the fitting method and comparison conditions are compatible. Do not choose a model mechanically based only on the size of a number.
- When using Bayesian estimation, state the prior distributions, check sampling diagnostics, and assess how sensitive the conclusions are to the prior specification.
A more complex model is not necessarily better. Adding a random slope or covariance parameter requires a clear research motivation and enough groups and within-group information to support it.
8. Data preparation and model diagnostics
8.1 Checking the data structure
First confirm that group identifiers are accurate. If an employee moves across departments during the study, a simple “employees nested within departments” structure may no longer hold. Cross-classification or time-varying group membership may need to be considered.
Also check group sample sizes, within-group variation in the explanatory variables, the distribution of missing values, and repeated records. Highly unbalanced group sizes do not necessarily invalidate the model, but they affect estimation precision and interpretation.
8.2 Checking residuals and correlation structure
Examine the relationships between conditional residuals and both fitted values and explanatory variables to identify nonlinearity, heteroscedasticity, and unusual observations.
For longitudinal data, a random intercept or random slope may not fully explain temporal correlation. If conditional residuals remain correlated over time, the residual correlation structure should be modeled further.
Predicted random effects can be used to explore group differences, but they have been shrunk. They should not be treated as independent samples of the true random effects when simply checking distributional assumptions.
8.3 Checking convergence and singular fits
Watch whether optimization converges, whether variance estimates are close to zero, and whether random-effect correlations are close to positive or negative one. These signs may indicate that the random-effect structure is too complex, or they may result from an unsuitable variable scale or insufficient data support.
Reasonable responses include rechecking the data, rescaling variables, simplifying random-effect terms that lack justification, and comparing whether results remain stable under different fitting settings—not merely hiding warning messages.
9. Predictive validation must match the use case
Hierarchical linear models have two distinct prediction targets.
Predicting a new individual in an existing group can use that group’s estimated random effect. This is conditional prediction. Training and validation splits must still avoid using future information to estimate group effects.
Predicting an individual in an entirely new group usually cannot use a realized random effect for that group. Under the common assumption of zero-mean random effects, the population fixed effects can provide a marginal mean prediction. Prediction intervals should include uncertainty from the new group’s random effect.
Therefore, if the goal is to generalize to a new department, school, or device, use a validation design that holds out entire groups. Randomly splitting records from the same group into training and validation sets produces performance closer to “prediction within known groups,” which does not represent generalization to new groups.
If the goal is to predict future time points, use a split that respects time order. Variable processing, missing-data handling, and calculation of group statistics must use only data available before the prediction time.
10. Implementation and communicating results
In implementation, the model can be written uniformly as:
[
\mathbf{y}=\mathbf{X}\boldsymbol{\beta}
+\mathbf{Z}\mathbf{u}+\boldsymbol{\varepsilon}
]
Here, (\mathbf{X}) is the fixed-effects design matrix and (\mathbf{Z}) is the random-effects design matrix. Grouping usually makes the random-effects design matrix sparse, and a sparse representation can reduce storage and computation.
A complete workflow includes data validation, hierarchy identification, model specification, estimation diagnostics, scenario-specific validation, and archiving results. Save variable definitions, centering choices, group encodings, the training-sample range, the estimation method, and the model version so that training and prediction use consistent data-processing rules.
A results report should not list only fixed-effect coefficients. It should also include variance components, key interaction terms, the prediction target, and a statement of uncertainty. If group-effect rankings are shown, emphasize their estimation error and shrinkage. Do not treat estimates for small groups as definitive quality assessments.
Finally, a hierarchical linear model is first a method for describing and analyzing hierarchical associations. It can handle correlated observations and group heterogeneity more appropriately, but the model form alone cannot establish causality. For noncontinuous responses such as binary or count outcomes, consider a generalized linear mixed model based on the response distribution. For complex temporal dependence or crossed membership, the structure needs to be extended further. The core principle is always to match the statistical assumptions and the data-generating process to the actual analytical goal.
