Multilevel regression is designed for data in which respondents are nested in groups such as classrooms, workplaces, or clinics. This guide explains why clustering matters, how to read the intraclass correlation, and how to run a model in AnalyZ Solutions.
Field surveys are seldom simple random samples of individuals. Pupils are sampled within schools, employees within companies, patients within clinics, and schools within regions. People in the same group resemble each other more than they resemble people elsewhere. Children in one school share teachers, resources, and neighbourhood. Employees in one company share managers, pay scales, and workplace culture.
This resemblance breaks a core assumption of ordinary regression, that each observation is independent. When it is ignored, the model behaves as though you have more independent information than you do. Standard errors come out too small, confidence intervals too narrow, and results look significant that are not. Multilevel regression, also called mixed-effects or hierarchical linear modelling, corrects this by modelling the group structure directly.
In the figure below, students in the same school share a colour, because they share teachers, resources, and surroundings. The same logic applies at every level of the structure.
The word hierarchical here describes nested data. It has no connection to hierarchical regression, which enters predictors in planned blocks.
The key number in a multilevel analysis is the intraclass correlation, or ICC. It states what share of the total variation in the outcome lies between groups rather than within them. An ICC of 0.15 for test scores across schools means 15% of the variation in scores is between schools, and 85% is between students within the same school.
A higher ICC means observations in the same group are more alike, and ignoring the clustering does more damage. In education research, ICCs of 0.10 to 0.25 are typical. In some health and community settings, values are lower. Even an ICC of 0.05 can matter when groups are large. An ICC near zero suggests grouping adds little, and an ordinary regression may do.
The ICC is also a finding in its own right. It tells you at what level most of the variation sits, and therefore whether changes aimed at schools, workplaces, or individuals have the most room to make a difference.
A random intercept model lets each group have its own average level of the outcome. Some schools score higher on average and some lower, and the model estimates how much they vary. Predictors have the same effect in every group.
A random slope model goes further and lets the effect of a chosen predictor vary between groups. The benefit of an extra hour of study, for instance, might be larger in some schools than in others. This is a richer model but needs more groups and more data, and it should be used when theory suggests the effect really varies.
Use it when respondents are nested in groups and the group structure matters, or when the sampling design was clustered. It suits students in schools, patients in clinics, employees in companies, repeated measures on the same individuals over time, and multi-country surveys. It handles continuous, binary, and count outcomes.
If your data has no meaningful grouping, use linear, logistic, or Poisson regression. For a simple repeated-measures design without predictors, repeated-measures ANOVA may be enough.
How many groups do you need? As a guide, at least 20 to 30 groups are needed for stable estimates of the between-group variation, and more if you want random slopes. With very few groups, such as five regions, treat groups as a fixed predictor instead.
A multilevel model writes the outcome for student i in school j as a school-level baseline plus the effect of the predictors plus an individual error. The simplest version is the random intercept model.
The coefficients g00, b1 and g01 are the fixed effects, which apply to everyone. The term u(j) is the random effect, the amount by which school j sits above or below the average. It is assumed to follow a normal curve with variance σ²u, and the individual error e(ij) follows one with variance σ²e. A random slope model adds a school-specific term to the effect of a predictor, so that the effect itself varies between schools.
The parameters are estimated by maximum likelihood, usually in its restricted form, REML. The software chooses the fixed effects and the two variances that make the observed data most probable.
In a model with no predictors, the example data give σ²u = 29.96 and σ²e = 153.01, so ICC = 29.96 ÷ (29.96 + 153.01) = 0.164. About 16% of the variation in scores lies between schools. The ICC shown in the results below comes from the model that includes the predictors, and it is 0.235. Study hours explain a lot of student-level variation, so what remains between schools is a larger share of what is left.
Respondents in the same school carry less independent information than respondents in different schools. The design effect measures the loss:
With m = 25 students per school and the no-predictor ICC of 0.164, the design effect is 1 + 24 × 0.164 = 4.93. The 1,000 students carry about as much information as 203 independent ones. An ordinary regression would understate the standard errors of school-level predictors by a factor of about √4.93 = 2.22, which is enough to turn many non-significant results into apparently significant ones.
The main table shows the effect of each predictor on the outcome, averaged across groups. For continuous outcomes these are coefficients in the units of the outcome. For binary outcomes they can be shown as odds ratios, and for counts as incidence rate ratios. A toggle switches to raw coefficients. Their interpretation matches the single-level counterpart, with the added phrase that the effect is estimated after accounting for the grouping.
This table gives the between-group variation and, for continuous outcomes, the within-group variation, together with the ICC and its confidence interval. With three or four levels, an ICC is reported for each level.
For binary and count outcomes, the summary includes a likelihood-ratio test comparing the multilevel model with an ordinary model. A significant result supports the multilevel structure. If the test shows no improvement, the between-group variation is close to zero and a simpler model would do.
A Wald test checks whether the fixed effects together are significant. The summary also lists the log-likelihood, AIC, and BIC.
The module shows a second estimate of the ICC, computed directly from group averages with no modelling assumptions. If it agrees with the model-based value, you can trust the estimate. If the two diverge, treat the model-based ICC with caution. Binary and count models use an approximation that can understate group variation when there are few groups or when the ICC is high, and the module warns you when that may be the case.
Open Inferential Analysis, choose Regression, then Multilevel Regression.
The figures below are invented to show the steps, and they follow the results tables in AnalyZ Solutions, with a few columns left out to save space. Suppose exam scores are recorded for 25 students in each of 40 schools. The predictors are weekly study hours (measured for each student) and whether the school provides free meals (a school-level variable), with a random intercept for school.
| Variable | B | SE | z | p-value | Sig | 95% CI lower | 95% CI upper |
|---|---|---|---|---|---|---|---|
| (Intercept) | 44.62 | 1.55 | 28.75 | < 0.001 | *** | 41.58 | 47.66 |
| Weekly study hours | 2.61 | 0.10 | 25.35 | < 0.001 | *** | 2.41 | 2.81 |
| School provides free meals (ref: No) | 5.20 | 1.79 | 2.92 | 0.0036 | ** | 1.71 | 8.70 |
| Component | Estimate |
|---|---|
| Random intercept variance (school) | 28.11 |
| Residual variance | 91.74 |
| ICC (level-2) | 0.235 |
Students in the same school resemble each other, with about 23% of the remaining variation in scores lying between schools. After accounting for this, more study time was strongly associated with higher scores, and schools that provide free meals scored about 5 points higher. The meals result is less precise than the study-hours result, and it is an association between schools.
Ignoring the clustering. This inflates significance and leads to false findings.
Too few groups. Fewer than about 20 groups give unreliable variance estimates.
Interpreting group-level predictors as individual effects. A school-level variable describes schools, so claims about individuals need care.
Adding a random slope by default. It uses up data. Add it only when there is a reason to expect the effect to vary.
Ignoring the ICC warning. If the model-based and direct ICC estimates disagree, say so in your report.
Open Regression in AnalyZ Solutions. Free to sign up, free to analyze.
Get started