Written and maintained by CASRAI Editorial Board
Last updated
If your data are clustered — repeated measures within participants, patients within clinics, pupils within schools, cells within plates — ordinary regression is the wrong tool, and the reason is not a technicality.
Three names, one model
Before anything else: mixed-effects model, multilevel model, hierarchical linear model and (in some literatures) random-effects model all refer to the same class of model. The names come from different disciplines — psychology and ecology say mixed effects, education and sociology say multilevel, biostatistics often says hierarchical.
This matters practically. Searching one name finds one literature, and people conclude a method is unavailable in their field when it is simply called something else next door. If a technique you need is described under one of these labels, it applies under all of them.
Why clustered data breaks ordinary regression
Ordinary least squares assumes observations are independent. Clustered data violate that: two measurements from the same participant, or two pupils in the same school, are more alike than two drawn at random. The effective amount of independent information is smaller than the row count suggests.
Fitting OLS anyway does not usually move the coefficient much — it distorts the uncertainty. The model behaves as though it has more independent data than it does, which produces standard errors that are too small, confidence intervals that are too narrow, and p-values that are too enthusiastic. The result is a finding that looks solid and does not replicate.
How much clustering there is can be quantified with the intraclass correlation coefficient, which expresses the share of total variance that sits between clusters rather than within them.
Fixed and random effects
The “mixed” in mixed-effects is the combination of two kinds of term.
- Fixed effects are the population-level relationships you want to estimate and report — the treatment effect, the dose slope, the group difference.
- Random effects model the structure of the clustering itself. Rather than estimating a separate parameter for every school, the model treats school-level deviations as draws from a distribution and estimates that distribution’s variance.
That is the efficiency gain: forty clusters cost you one variance parameter, not forty intercepts. It also changes what you are claiming — random effects support inference about the population of clusters, not just the ones you sampled.
Random intercepts and random slopes
A random intercept lets each cluster sit at its own baseline level: some clinics start higher than others, but the effect of your predictor is assumed identical everywhere.
A random slope additionally lets the effect itself vary by cluster: the treatment works better in some clinics than others.
Choosing between them is not cosmetic, because the random structure feeds back into the fixed-effect inference. Both under-parameterising and over-parameterising the random structure bias the standard errors of the fixed effects — so “add every random slope that will converge” is as wrong as “always use a random intercept”. Under-parameterisation in particular has been shown to underestimate standard errors for within-subject effects.
Let the design decide. If a predictor varies within clusters and could plausibly act differently across them, a random slope is the honest specification. If it varies only between clusters, a random slope for it is not estimable in the first place.
REML or ML
Two estimation methods, and the choice depends on what you are comparing.
REML maximises the likelihood of the variance parameters after accounting for the fixed effects. This removes the downward bias that ML has on variance estimates — the same correction in spirit as dividing by n−1 rather than n for a sample variance. Variance components come out larger under REML, and standard-error bias is lower than under ML.
Fixed-effect estimates are equivalent under both. The methods differ in the variance-covariance components, not the coefficients.
The rule that follows: use REML for reporting variance components and the final model; refit with ML when comparing models that differ in their fixed effects via a likelihood-ratio test. REML likelihoods from models with different fixed-effect structures are not comparable, because they are computed on different residual contrasts. Comparing them is a real error, and software will usually let you do it without complaint.
The degrees-of-freedom problem
Mixed models do not have an obvious residual degrees-of-freedom count — part of the information is spent estimating variance components. With few clusters this matters, and naive tests are anti-conservative.
Two established small-sample corrections address it: the Kenward-Roger adjustment and the Satterthwaite approximation for t-tests, alongside adjusted cluster-robust standard errors. With a small number of clusters these are not optional refinements; they are what makes the inference valid.
Common mistakes
- Ignoring clustering entirely and reporting OLS standard errors. The most common and the most consequential.
- Comparing REML likelihoods across different fixed-effect structures. Refit with ML first.
- Treating a convergence warning as cosmetic. It usually means the random structure is not supported by the data — simplify it rather than switching optimiser until the warning disappears.
- Too few clusters. Five schools is not enough to estimate a between-school variance well, whatever the total row count. Use a small-sample correction and be explicit about the limitation.
- Fitting a random slope for a between-cluster predictor. If it does not vary within clusters, there is no within-cluster slope to be random.
Related
For the classical approach to within-subject designs, see repeated-measures ANOVA — a mixed model handles the same designs with fewer assumptions and tolerates missing data far better. If you are still choosing an approach, how to choose a statistical test is the starting point, and note that collinearity diagnostics such as VIF apply to the fixed-effects part in the usual way.
Frequently asked questions
Are mixed-effects and multilevel models different?
No. Mixed-effects, multilevel, hierarchical and (in this sense) random-effects models are the same class of model under names inherited from different fields.
When do I need one?
When observations are not independent because they are grouped — repeated measures, nesting, or any clustering that makes two observations from the same unit more alike than two at random.
Random intercept or random slope?
Random intercept when clusters differ in baseline. Random slope when the effect itself plausibly differs across clusters and the predictor varies within them. Both under- and over-specifying the random part bias fixed-effect standard errors, so let the design decide rather than fitting the maximum that converges.
REML or ML?
REML for the final model and variance components; ML when likelihood-ratio testing models with different fixed effects. Fixed-effect estimates are the same either way.
Why does my model not converge?
Usually a random structure the data cannot support — too many random slopes, or too few clusters. Simplify the random part first; changing optimiser hides the symptom rather than fixing it.
How many clusters do I need?
There is no single number, but with few clusters the variance estimate is poor and naive tests are anti-conservative. Apply a Kenward-Roger or Satterthwaite correction and state the constraint rather than treating the output as if it came from many clusters.
References
- Evaluating two small-sample corrections for fixed-effects standard errors in multilevel models — PMC11541410
- Linear mixed-effect regression models in translational biostatistics — PMC2147003
- Maintaining validity of inference from linear mixed models under misspecified random-effects structures — PMC11499024
- Effect size measures for linear multilevel models — UCLA OARC








