Multilevel model

Intermediate

What you need first. Nothing else on this path comes first. This page is part of Correlated data.

In correlated data, a multilevel model is a regression that lets coefficients vary across groups, including groups that sit inside other groups. Pupils share a classroom, classrooms share a school, and schools share a district. Measurements inside one of those groups resemble each other more than measurements from different groups. A multilevel model gives the coefficients of a regression permission to vary from group to group, and it can do so at more than one grouping at once. The groups may be nested, one inside another, or crossed, so that a unit belongs to two groupings neither of which contains the other.[1][2]

Multilevel model

Multilevel model
Fact Value
Topic Correlated data
Listed on Correlated data
Worked example 1

Motivating example

Two clinics each record a blood pressure for three patients, once. The six numbers are not six independent draws from one population: the three patients in a clinic share a staff, a protocol, and a local case-mix. A single regression line ignores that sharing and treats the clinic as invisible. A separate line for every clinic, with no link between the lines, fits the six numbers and says nothing about a clinic that was not in the file. A multilevel model puts a clinic shift around a common line and gives that shift a variance, so that both the common line and the size of the clinic differences are part of the fit.[1][2]

Definition

A multilevel model is a regression in which some coefficients are constant across groups and others vary, with the varying coefficients given a distribution, and in which the groups may be nested or crossed. Nested groups sit inside one another: patients in clinics in districts. Crossed groups cut across one another: pupils taught by a teacher and also belonging to a neighbourhood, with teachers not confined to one neighbourhood. Classical analysis of variance already batched effects this way, and it became awkward once nesting, crossing, and unequal group sizes appeared together. The hierarchical version keeps the batches and estimates a variance for each batch.[1]

For a Gaussian response the conditional model is

(Y∣B=b)∼N(Xβ+Zb, σ2W−1),B∼N(0,Σ),(Y\mid B=b)\sim N(X\beta+Zb,\ \sigma^2 W^{-1}), \qquad B\sim N(0,\Sigma),

with Σ\Sigma a positive semidefinite covariance. The term XβX\beta holds the constant coefficients. The term ZbZb holds the varying coefficients, and the pattern of ZZ says which observations share a group. A random intercept for clinic ii is the special case Yij=xij⊤β+bi+εijY_{ij}=x_{ij}^\top\beta+b_i+\varepsilon_{ij} with bi∼N(0,τ2)b_i\sim N(0,\tau^2) and εij∼N(0,σ2)\varepsilon_{ij}\sim N(0,\sigma^2), independent across clinics and independent of the clinic effects.[2]

A generalised linear mixed model keeps a linear predictor of the same shape, x⊤β+z⊤bx^\top\beta+z^\top b, and replaces the normal conditional distribution by a distribution suited to the response, through a link function. A binary outcome is not made normal by the normal distribution on bb. The normal law is the law of the group coefficient. Counts and binary outcomes are the cases in which ecology and medicine usually meet the model.[3]

Interpretation

Under the random-intercept model, two distinct patients in clinic ii have covariance τ2\tau^2, and one patient has variance τ2+σ2\tau^2+\sigma^2. Their correlation is

τ2τ2+σ2.\frac{\tau^2}{\tau^2+\sigma^2}.

Patients in different clinics have covariance 00 when the clinic effects are independent. The correlation cannot be negative in this one-parameter form, because τ2\tau^2 and σ2\sigma^2 are variances. A model with varying slopes can produce a correlation that changes with the covariate. The correlation is a description of the population of patients, marginal over the clinic effect. It is not the residual correlation after the clinic effect has been conditioned on. Conditional on bib_i, the patients in a clinic are independent in this model.[2]

With τ2=9\tau^2=9 and σ2=3\sigma^2=3, the marginal variance of one observation is 1212 and the within-clinic correlation is 9/12=3/49/12=3/4. The difference of two observations in the same clinic cancels bib_i, so its variance is 3+3=63+3=6, not 12+12=2412+12=24. The shared level is a feature of the level, not extra noise in the contrast inside the clinic. The ratio of those two difference-variances is 24/6=424/6=4. The within-clinic contrast is the more precise one because the clinic level cancels.

Nesting adds a variance at each level that is shared by every observation under that level. If clinics sit inside districts, two patients in the same clinic share the district effect and the clinic effect. Two patients in the same district but different clinics share only the district effect. Crossing does not create that inclusion. A teacher effect and a neighbourhood effect can both touch a pupil without either group containing the other.[1][2]

The constant coefficients describe the population pattern. The varying coefficients describe how far groups depart from it, and they support a prediction for a group that was sparsely measured, pulled toward the pattern of the other groups. One of the incompatible vocabularies for this split says that fixed effects are constant across individuals and random effects vary. Another says that fixed effects are estimated by least squares and random effects are estimated with shrinkage. The fitted model has to say which coefficients are constant and which are varying, because the two words do not pick out one definition.[1]

For a non-Gaussian response the coefficients are conditional on the group effect. An odds ratio from a logistic multilevel model is an odds ratio given the group effect. Averaging the probability over groups is not the same operation as transforming the averaged predictor. Reporting the conditional odds ratio as the population-average odds ratio changes the question.[3]

Worked example

Take τ2=9\tau^2=9 and σ2=3\sigma^2=3 in a random-intercept model. One reading has variance 9+3=129+3=12. Two readings in the same clinic have correlation 9/12=0.759/12=0.75 and covariance 99. Their difference has variance 66. Two readings in different clinics have correlation 00 and a difference with variance 12+12=2412+12=24. The within-clinic difference is the more precise contrast, by a factor of 24/6=424/6=4 in variance, because the clinic level cancels.[2]

Your turn. A random-intercept model has τ2=4\tau^2=4 and σ2=12\sigma^2=12. Find the marginal variance of one observation, the within-group correlation, and the variance of the difference of two observations in the same group.

The marginal variance is 4+12=164+12=16. The within-group correlation is 4/16=0.254/16=0.25. The shared intercept cancels in a difference, leaving variance 12+12=2412+12=24.

Connections

The Gaussian specification is a linear mixed model, and its one-group case is a random-intercept model whose within-group resemblance is an intraclass correlation. The non-Gaussian specification is a generalised linear mixed model. Fixed and random effects is the older vocabulary for constant and varying terms, and the five definitions in the analysis-of-variance literature do not agree. A Bayesian treatment with a prior on the group distribution is a hierarchical Bayesian model. The data layouts that most often need the grouping are panel data, repeated measures, and a cross-sectional data set whose units sit inside regions.[1][2][3]

Check yourself

Try these questions before opening an answer.

Sign of the correlation

Why can the within-group correlation of a random-intercept model with one variance component not be negative?

The covariance of two observations in the same group is the group variance, and the marginal variance is the sum of the group variance and the residual variance. A ratio of nonnegative variances is nonnegative.

Conditional odds

Why is an odds ratio from a logistic multilevel model not automatically the population-average odds ratio?

The coefficient is conditional on the group effect. Averaging the probability over groups is not the same operation as transforming the average of the linear predictor.

History

Analysis of variance organised effects into batches and compared the variance of each batch, but the classical calculations became awkward once nesting, crossing, and unequal group sizes appeared together. Recasting those batches as varying coefficients in a hierarchical model made the same comparisons available in unbalanced designs, and it made the fixed-or-random question a question about how a batch of coefficients would be used.[1]

Software for linear mixed models then made nested and crossed group factors ordinary specifications, with the conditional normal model written as Xβ+ZbX\beta+Zb and the group covariance left as a parameter. Maximum likelihood and restricted maximum likelihood are the fitting criteria for the Gaussian case. Generalised linear mixed models extended the same predictor to binary and count data. That is the form in which ecology, medicine, and the social sciences usually meet a multilevel model when the outcome is not a normal measurement.[2][3]

See also

Line chart · Apriori algorithm · Asymptotic analysis · Average treatment effect · Base rate · Bayesian inference · Bayesian model · Bayesian probability

Glossary and index

References

  1. ^ a b c d e f g a. (pp. 1–2) b. (pp. 1–2) c. (pp. 1–2 and 20–21) d. (p. 2) e. (pp. 20–21) f. (pp. 20–21) g. (pp. 1–2 and 20–21) Gelman, A. (2005). Analysis of variance—why it is more important than ever. The Annals of Statistics, 33(1), 1–53. https://doi.org/10.1214/009053604000001048
  2. ^ a b c d e f g h a. (p. 3, equations 2 and 3) b. (p. 1, §1) c. (p. 3, equations 2 and 3) d. (p. 3, equations 2 and 3) e. (p. 2) f. (p. 3, equations 2 and 3) g. (pp. 1–3) h. (pp. 1–3) Bates, D., Mächler, M., Bolker, B. & Walker, S. (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1). https://doi.org/10.18637/jss.v067.i01
  3. ^ a b c d a. (p. 127) b. (p. 127) c. (p. 127) d. (p. 127) Bolker, B. M., Brooks, M. E., Clark, C. J., Geange, S. W., Poulsen, J. R., Stevens, M. H. H. & White, J.-S. S. (2009). Generalized linear mixed models: a practical guide for ecology and evolution. Trends in Ecology & Evolution, 24(3), 127–135. https://doi.org/10.1016/j.tree.2008.10.008
Cite this page
Plain text
StatWiki (2026). "Multilevel model." StatWiki. Last updated 2 December 2026. https://www.statwiki.io/articles/multilevel-model.html
BibTeX
@misc{statwiki_multilevel_model,
  author = {{StatWiki}},
  title = {{Multilevel model}},
  year = {2026},
  url = {https://www.statwiki.io/articles/multilevel-model.html},
  urldate = {2026-12-02},
  note = {StatWiki, last updated 2 December 2026}
}