If your data are nested (students within classrooms, patients within hospitals, repeated measures within persons), standard regression or ANOVA is not just suboptimal: it is incorrect. Multilevel models (also called hierarchical, mixed, or linear mixed-effects models) are the tool for those data, and they appear increasingly in education, health and psychology theses. This guide explains what they are, when you need them, and how to build them.
The problem: dependence in nested data
Classical statistics assumes that observations are independent. But two students from the same classroom resemble each other more than two students from different classrooms (they share a teacher, environment, neighborhood). That dependence violates the independence assumption, and if you ignore it with standard regression the standard errors come out too small and your false-positive rate shoots up: you will find "significant" effects that are not real.
The degree of dependence is measured with the intraclass correlation coefficient (ICC): the proportion of variance attributable to differences between groups. If the ICC is practically zero, you do not need multilevel; if it is appreciable, you do.
Fixed effects and random effects
The central idea of multilevel modeling is to separate what is constant from what varies across groups. A fixed effect is the overall average (the slope of a variable across the whole sample). A random effect allows something to vary across groups: a random intercept lets each group have its own baseline level (some classrooms start off performing better than others), and a random slope lets the effect of a predictor differ across groups (the effect of study hours varies from classroom to classroom).
How to build the model, step by step
- Null (empty) model: no predictors, just to calculate the ICC and confirm there is between-group variability that justifies multilevel.
- Level-1 predictors: individual-level variables (study hours, age). Decide on centering (group-mean centering or grand-mean centering), because it changes the interpretation of the coefficients.
- Level-2 predictors: group-level variables (class size, type of school).
- Cross-level interactions: for example, whether the effect of study hours depends on the type of school. This is where multilevel models answer questions no other model can.
Software
In R, the lme4 package (function lmer) and nlme are the standard. In SPSS, use Analyze > Mixed Models > Linear. For more complex models (multilevel with latent variables), Mplus. The key output is the variance components (how much variance remains at each level) and the fixed effects with their correct standard errors.
Relation to mixed models and repeated measures
Repeated measures are a special case of nested structure (measurements are nested within persons), which is why a mixed model is usually better than a repeated-measures ANOVA: it handles missing data without dropping the entire participant and allows flexible covariance structures. The detailed comparison is in mixed models vs repeated-measures ANOVA.
Sample size: the number of clusters matters most
In multilevel models, what limits power most is not the number of individuals but the number of clusters (groups). With few clusters, the estimates of random effects are unstable. There is no simple G*Power formula for this; sample size is estimated by simulation. Getting the sample size calculation right for these models is one of the things worth sorting before data collection begins.
Common errors
Analyzing nested data with standard regression (and publishing false positives); including only a random intercept when theory calls for a random slope; not centering variables and then misinterpreting the coefficients; having too few clusters to estimate random effects reliably; and aggregating data to the group level while losing all individual-level variability. The overall analysis workflow is in how to analyze thesis data step by step.
Your data are nested and you do not know how to model them?
I am a PhD in Psychology and I fit your multilevel models in R or SPSS (random intercepts and slopes, cross-level interactions, ICC and variance components), with interpretation and the write-up ready for the committee or journal. Free initial diagnosis.
See the statistical consulting →Frequently asked questions
When do I need multilevel models instead of regular ANOVA or regression?
You need multilevel models when your data have a nested structure: students within classrooms, patients within hospitals, repeated measures within participants, or employees within organizations. Ignoring nesting and using standard regression inflates Type I error because it assumes all observations are independent, which is violated when data are clustered.
What ICC value justifies using a multilevel model?
An ICC of .05 or higher (5% of variance attributable to group-level differences) is generally sufficient justification. Below that threshold the design effect is small and standard regression may be adequate. When the theoretical structure is clearly nested, multilevel modeling is preferred regardless of the ICC value.
What is the difference between fixed and random effects?
Fixed effects capture the average relationships across all groups (for example, the overall effect of a predictor on the outcome). Random effects capture variability in those relationships across groups: a random intercept lets each group have a different baseline level; a random slope lets the effect of a predictor vary by group.
Can I run multilevel models in SPSS?
Yes, through Analyze > Mixed Models > Linear for continuous outcomes, or Generalized Linear Mixed Models for non-normal outcomes. SPSS Mixed is adequate for standard two-level nested designs. For complex random effects structures, crossed random effects, or convergence problems, the lme4 package in R is more flexible.