Hierarchical Linear Models: Principles and Practice for Nested Data
This article explains hierarchical linear models (HLM), also known as mixed-effects or multilevel models, and why they are the right tool when observations are nested inside higher-level units. It covers the assumptions of ordinary regression that nested data violate, the two-level model structure with random intercepts and random slopes, variance components and the intraclass correlation, model comparison, estimation by maximum likelihood and restricted maximum likelihood, data preparation including centering and missing data, a step-by-step analysis workflow, diagnostic checks, common misuses, and the boundaries with fixed-effects panel models, GLMMs, and clustered robust regression. Readers will learn how to specify, estimate, report, and validate a multilevel model without confusing individual-level and group-level effects.
Hierarchical linear models (HLM), also called mixed-effects models or multilevel linear models, appear in the econometrics literature as random coefficient regression and in the statistics literature as covariance components models. The approach grew out of Bayesian linear model ideas in the 1970s and was designed for data where observations sit inside higher-level units: students within classes and schools, employees within teams and organizations, repeated measurements within individuals over time. Ignoring that nesting produces two kinds of inferential error at once: treating a group-level correlation as an individual regularity (the ecological fallacy), or extrapolating an individual-level effect to the group without qualification (the atomistic fallacy).
Why Ordinary Regression Is Not Enough
Ordinary least squares assumes independent, homoscedastic residuals and a single set of regression coefficients shared by all observations. Nested data violate all of these. Students in the same class share a teacher, a curriculum, and a peer environment, so their residuals are correlated; schools differ in resources and policy, so intercepts and even slopes vary. Pooling everything into one regression understates standard errors and inflates significance. Aggregating to the group level first, on the other hand, discards individual variation and can yield conclusions that run opposite to the individual-level result.
HLM partitions variance across levels: the lower level explains who is higher within a group, the higher level explains which groups are higher overall and why slopes differ between groups. Fixed effects describe the average relationship in the population; random effects describe how far units at each level deviate from it. Micro-level information is preserved while macro-level heterogeneity is acknowledged.
Basic Structure of a Two-Level Model
Take students nested in classes. Level 1 (individual) is written as:
Student score = class intercept + class slope × student characteristic + individual residual
Level 2 (class) expresses the intercept and slope as a population mean plus a class random term, and can add class characteristics such as class size or teacher experience:
Class intercept = overall intercept + effect of class characteristics + intercept random term
Class slope = overall slope + moderation of the slope by class characteristics + slope random term
Substituting gives the combined model: an overall fixed part, cross-level interactions, and the individual residual together with the class random effects. A random intercept means class baselines differ; a random slope means the same predictor has a stronger or weaker effect in different classes. The covariance between the two indicates whether classes with higher baselines have steeper or flatter slopes.
The structure extends to three or more levels (student–class–school). It also applies with time points as level 1 and individuals as level 2, producing a growth curve model: the intercept is the initial level, the slope is the rate of change, and both can vary by person.
Quantities to Estimate and Model Comparison
Analysts need more than regression coefficients; they need variance components: the level-1 residual variance, the variance of each random effect, and the covariances among random effects. The intraclass correlation (ICC) is the between-group variance divided by the total variance and expresses how similar observations in the same group are. When the ICC is near zero, a multilevel model offers little; when it is non-negligible, ignoring clustering distorts inference.
Models are usually compared in nested order: random intercept only; then add random slopes; then add level-2 predictors and cross-level interactions. Comparison relies on likelihood ratio tests for nested models, information criteria, and whether a variance component is substantively meaningful. Variance explained can be computed by level: after adding a predictor at a given level, the proportional reduction in that level’s variance is a pseudo-R² for that level. It is not directly comparable to the R² of ordinary regression, because total variance has been split across levels.
Estimation and Inference Essentials
Parameters are typically estimated by maximum likelihood (ML) or restricted maximum likelihood (REML). REML adjusts the degrees of freedom for the fixed effects when estimating variance components, which makes variance estimates more reliable in small samples; when comparing models with different fixed effects, however, use ML results throughout, otherwise the likelihood ratio is not comparable.
Random effects and residuals are generally assumed normal, independent across groups, and conditionally independent of the predictors given the model specification. Coefficient inference can use standard errors based on the estimated information matrix, or a more conservative degrees-of-freedom approximation when the number of clusters is small. With too few clusters (for example, only a handful of higher-level units), both variance components and higher-level coefficients are unstable; increasing the higher-level sample size is the priority, not adding random slopes indiscriminately.
Algorithmically, a linear mixed model can be cast as a generalized least squares problem with a known covariance structure, iterating between fixed effects and variance components until convergence. A Bayesian implementation places priors on the fixed effects and variance components and draws the posterior distribution, which expresses uncertainty conveniently, but prior choice affects small-sample results and calls for a sensitivity check.
Data Preparation Before Modeling
- Define the levels and membership. Every lower-level observation must have a unique, unambiguous higher-level identifier. Cross-classified structures (students belonging simultaneously to a school and a neighborhood, neither nested in the other) require crossed random effects rather than a forced pure nesting scheme.
- Centering. Individual predictors are best group-mean centered, so the level-1 slope represents the effect of deviating from one’s own group mean; the group mean then enters as a level-2 variable representing the contextual effect. Grand-mean centering preserves the population slope in the original units, which is convenient for interpreting main effects, but changes the meaning of cross-level interactions. Do not mix centering schemes within one model without stating it.
- Scale and missingness. When continuous variables differ greatly in magnitude, standardize or change units first, otherwise the random slope variance becomes numerically unstable. If missingness is related to the outcome, simple deletion introduces bias; record the missingness mechanism at the design stage and, where necessary, use multiple imputation compatible with the multilevel structure rather than filling means arbitrarily between levels.
- Check sparse groups. When a group has very few observations, its random slope is nearly unidentified; collapse levels, simplify the random structure, or apply moderate shrinkage to the random effects (the mixed model itself pulls information-poor groups toward the population mean).
Recommended Analysis Steps
Step 1, the empty model: random intercept only, no predictors; compute the ICC and confirm the multilevel structure is worth keeping.
Step 2, a level-1 fixed-slope model: add theoretically justified individual predictors and see how much level-1 variance drops.
Step 3, random slopes: free the slope only for variables with a theoretical rationale and sufficient within-group variation; check whether the slope variance and the intercept–slope covariance are estimable and whether the model converges.
Step 4, level 2 and cross-level terms: use group characteristics to explain intercept differences and cross-level interactions to explain slope differences. Interaction terms must be interpreted together with the centering scheme.
Step 5, diagnostics: check whether level-1 residuals are approximately normal and whether variance changes with fitted values; check empirical Bayes residuals of higher-level units for extreme groups; run influence diagnostics for high-leverage groups. If convergence fails, simplify the random effects first (drop the covariance or some random slopes), then check collinearity and scaling, rather than repeatedly loosening the iteration limit to mask a specification problem.
Illustrative model notation (pseudocode, not tied to any software):
Level 1: y[i,j] = b0[j] + b1[j] * x[i,j] + e[i,j]Level 2: b0[j] = g00 + g01 * z[j] + u0[j]b1[j] = g10 + g11 * z[j] + u1[j]where e ~ Normal(0, sigma^2), (u0, u1) ~ bivariate normal, covariance matrix to be estimated
Reporting should include fixed effect estimates with intervals, all variance components, the ICC, the centering scheme, effective sample sizes (number of level-1 observations and number of level-2 clusters), and how non-convergence or boundary variance (a variance estimate pinned at zero) was handled.
Typical Applications and Common Misuses
In education and management research, achievement, performance, and satisfaction are almost always nested; in organizational research, employees sit in departments and departments in firms; in longitudinal studies, repeated measurements sit in people. The shared question in these settings is not whether a more complex regression is needed, but whether the independence assumption holds.
Common misuses include estimating many random slopes with very few clusters; describing a level-1 coefficient from group-mean-centered data as a population effect; reporting only fixed effects while suppressing variance components; substituting a regression on aggregated group data for a multilevel model and claiming the conclusions are equivalent; and applying a single nesting identifier to cross-classified data. Another error is treating random effects as fixed dummy variables: with many groups, dummies consume a large number of degrees of freedom and cannot predict for a new group, whereas random effects use partial pooling to shrink information-poor groups toward the mean and predict more stably.
Boundaries with Related Methods
If there is only grouping, the interest is in mean differences, and slope heterogeneity is not a concern, one-way ANOVA or regression with cluster-robust standard errors can serve as a comparison, but neither decomposes why slopes vary across groups. Generalized linear mixed models extend the same random-effects idea to binary, count, and other outcomes; the link function and the meaning of the residual change, and the ICC must be defined on either the latent or the observed scale. With densely spaced time points and few groups, consider first whether an individual growth curve is over-parameterized. Fixed-effects panel models emphasize removing time-invariant group confounding, while random-effects models assume group effects are uncorrelated with the predictors; when that assumption fails, random-effects estimates are biased, and the response is a correlation test or a switch to fixed effects, correlated random effects, or similar specifications, not a default assumption that the mixed model is always better.
Practical Decision Criteria
Choose a hierarchical linear model when all of the following hold: there is a clear nesting or repeated-measures structure; the ICC or the design itself shows within-group correlation is non-negligible; the research question involves group differences, slope heterogeneity, or cross-level moderation; and the number of higher-level units is large enough to support the variance components being estimated. The model should be built around theory-driven fixed effects, with a random structure that stays identifiable, convergent, and interpretable. Reporting should state the levels, the centering scheme, the estimation method, and the sample sizes so that others can reproduce the analysis, rather than presenting a single significant interaction.
Handled this way, nested data give individual differences and group differences each their proper place: class differences are not mistaken for student traits, and correlations among students are not exaggerated into school-level regularities. That is the core value of hierarchical linear models over pooled regression and simple aggregation.
