Blog
Analysis made easy

Multilevel models (HLM) explained

Why nested data need more than a regression: the ICC, random intercepts and slopes, centering, and how to report it.

Skari team7 min

You collected surveys from 600 pupils, and it turns out they sit in 30 classes. That is a reason to think twice about how to analyse them.

"Can't I just run a regression?"

Pupils in the same class share a teacher and a classroom climate, so they tend to get similar scores. Ignore that and your results look more certain than they really are. Here is what a multilevel model (HLM, or mixed-effects model) is, and how to read and report one.

What a multilevel model is

A multilevel model is a regression for data where individuals sit inside groups (nested data), taking the individual level and the group level into account together. Pupils sit in classes, classes in schools, and repeated measurements of one person sit inside that person.

The many names are confusing, but hierarchical linear model (HLM), multilevel model and mixed-effects model mostly mean the same thing. It mixes fixed effects, common to every group, with random effects that vary from group to group — hence "mixed".

Today's example

ItemDetails
Data30 primary-school classes, 600 pupils
OutcomeVocabulary score
Pupil level (level 1)Daily reading time (minutes)
Class level (level 2)Whether the class has a class library

Two questions: "Do pupils who read longer have a bigger vocabulary?" and "Do classes with a class library score higher?"

Why not an ordinary regression

Ordinary regression (OLS) assumes every response is independent. But 20 pupils from the same class are not 20 brand-new pieces of information; they overlap to some degree.

Ignore that and the standard errors come out too small, the p-values shrink too, and you are more likely to see an effect that is not there.

The problem is worst for variables set at the class level, such as the class library: the real information there is 30 classes, not 600 pupils.

Start with the ICC

The ICC (intraclass correlation) is the share of the total variance that lies between groups.

ICC = between-group variance ÷ (between-group variance + within-group variance)

An ICC of .18 means about 18% of the differences in vocabulary come from which class a pupil is in.

With the design effect 1 + (group size − 1) × ICC, 1 + 19 × .18 ≈ 4.4, so for class-level comparisons 600 pupils carry only about 140 pupils' worth of information.

Even a small-looking ICC can shift the standard errors noticeably when groups are large. If your data are nested, checking with a multilevel model is the safe choice.

Random intercepts and random slopes

The heart of a multilevel model is deciding what is allowed to differ between classes.

  • Random intercept — each class has its own starting point (average level). Some classes score higher overall, some lower. The effect of reading time (the slope) is assumed to be the same in every class.
  • Random slope — not only the starting point but the effect of reading time itself differs between classes. Reading helps a lot in some classes and less in others.

Usually you start with a random-intercept model and add a random slope when there is a theoretical reason for the effect to vary by group. Random slopes add parameters, so they need enough groups and enough people per group to be stable.

Level-1 and level-2 variables

  • Level-1 (pupil) variable — differs from pupil to pupil. E.g. daily reading time
  • Level-2 (class) variable — the same for everyone in a class. E.g. class library

Level-2 variables explain differences between classes. If adding the class library shrinks the between-class variance, that is how much of the class differences it explains.

Tests of level-2 variables take their degrees of freedom from the number of classes, not pupils. With too few groups, power drops, which is why 30 or more groups is a common recommendation.

Decide on centering

For level-1 variables, which mean you subtract changes what a coefficient means.

  • Grand-mean centering — subtract the mean of all pupils. The intercept becomes "the vocabulary of a pupil who reads an average amount".
  • Group-mean centering — subtract that class's mean. The coefficient becomes the effect of "differences within the same class".

If you want to know "within a class, do pupils who read more have a bigger vocabulary?", group-mean centering is the usual choice; for an effect relative to all pupils, grand-mean centering.

With group-mean centering, a common approach is to put the class mean back in as a level-2 variable (e.g. the class's average reading time) to see the between-class effect too. Create the centred variables as new columns before the analysis.

How to read the results

  • Fixed effects — the average effect shared by all classes (B, standard error, t, df, p, 95% CI)
  • Random effects (variance components) — between-class variance and within-class (residual) variance
  • ICC — the share of differences that lies between classes
  • Marginal R² · conditional R² — variance explained by fixed effects alone · with random effects added
  • Model comparison — AIC · BIC, likelihood-ratio test

In the example, every extra 10 minutes of daily reading went with about 1.8 points more vocabulary, and classes with a class library scored 4.1 points higher on average.

An ordinary regression would have put the class library's standard error at 0.95; in the multilevel model it was 1.93, almost twice as large. That is how overconfident you become when you ignore the classes.

How to write it up

A random-intercept multilevel model was fitted to data from 600 pupils in 30 primary-school classes. About 18% of the variance in vocabulary scores lay between classes (ICC = .18). At the pupil level, daily reading time was positively related to vocabulary (B = 0.18, SE = 0.03, t(569) = 6.00, p < .001, 95% CI [0.12, 0.24]); at the class level, classes with a class library scored 4.10 points higher on average than those without (B = 4.10, SE = 1.93, t(28) = 2.12, p = .043, 95% CI [0.15, 8.05]).

Example sentence · the numbers are illustrative

Stating the model structure (random intercept · random slope), the estimation method (e.g. REML) and how you centred the variables heads off questions from examiners.

In Skari

In Skari you can run a multilevel model straight from Relationship → Regression → Mixed Effects Model (HLM).

In the variables step, pick the group ID (class), the dependent variable (vocabulary) and the predictors (reading time, class library). A variable that is the same for everyone in a class, like the class library, goes in as a predictor too. A column coded 0 · 1 is read as binary, so set its measurement level to scale in Variable View and it appears in the predictor list.

Picking the group ID, outcome and predictors — data like the example (600 pupils in 30 classes) uploaded
Picking the group ID, outcome and predictors — data like the example (600 pupils in 30 classes) uploaded

The settings step defaults to a random intercept; tick Also fit a random slope for one predictor to run a random-slope model.

Configuration summary and the random-slope option
Configuration summary and the random-slope option

Run a multilevel model on your data

Opens straight from Relationship → Regression

Open Mixed Effects Model

Before the analysis, the data validation step checks the number of groups, observations per group and missing values.

Data validation — 30 groups, 20 observations per group on average
Data validation — 30 groups, 20 observations per group on average

The result summary gathers the ICC, marginal and conditional R² and the likelihood-ratio test against plain OLS into key figures and a results paragraph.

Key figures and results paragraph at the top of the report — example result (Orthodont data: 27 children measured at four ages, random intercept + slope)
Key figures and results paragraph at the top of the report — example result (Orthodont data: 27 children measured at four ages, random intercept + slope)

The report also holds the fixed-effects table (with df and 95% CIs), variance components, random effects by group (BLUPs), predicted values and residual diagnostics.

In particular, it sets the coefficients and standard errors of plain OLS and the mixed model side by side, so you can see at once how small the standard errors get when groups are ignored.

Fixed-effects table and the OLS vs mixed comparison — same example result
Fixed-effects table and the OLS vs mixed comparison — same example result

You can download the report as Word and the result tables as Excel.

Wrapping up

The heart of a multilevel model is building "members of the same group are alike" into the model. Check group differences with the ICC, start from a random intercept, and decide your level-1 and level-2 variables and centering — the results tables become much easier to read.

Want the theory behind it?The Academy's Mixed-Effects Models chapter covers fixed and random effects and the ICC in depth →

Keep reading

Every feature free through Dec 31, 2026

Run the analyses from these posts on your own data