Introduction to Multilevel Models
IntermediateLesson 10 of 10 in Intermediate Statistics – Regression and ANOVA Course
What you will learn
- Identify when observations are grouped or repeated, explain why ordinary regression misleads with such data, and use the intraclass correlation to measure how much observations in the same group resemble each other.
- Recognize nested, clustered and repeated-measures dataIdentify the levels in a data set, tell level-1 observations from level-2 groups and arrange the data in long format.
- Explain why clustering changes the analysisExplain how clustering breaks the independence assumption, what this does to standard errors and p-values, and why analyzing group means or one regression per group are weaker alternatives.
- Measure clustering with the intraclass correlationFit the empty multilevel model, split the outcome's variance into a between-group and a within-group part, and compute and interpret the intraclass correlation.
- Recognize nested, clustered and repeated-measures data
- Distinguish fixed from random effects, fit models in which each group has its own intercept, add predictors at both levels with suitable centering and interpret the results.
- Distinguish fixed effects from random effectsExplain what fixed and random effects mean in a mixed model, decide whether a grouping factor should be modeled as random or fixed, and describe how random effects pool information across groups.
- Write, fit and read a random-intercept modelWrite a random-intercept model as two levels and as one combined equation, fit it in software, and interpret its fixed effects, variance components and predictions.
- Add predictors at both levels and choose their centeringAdd level-1 and level-2 predictors, separate within-group from between-group effects, and center predictors so that each coefficient answers the intended question.
- Distinguish fixed effects from random effects
- Let the effect of a level-1 predictor differ between groups, interpret the slope variance and the intercept-slope covariance, and explain differences in slopes with group-level predictors.
- Let slopes vary across groupsWrite and fit a model with a random slope, interpret the slope variance and the intercept-slope correlation, and see how the spread between groups changes along the predictor.
- Explain differences in slopes with cross-level interactionsUse a group-level predictor to explain why a level-1 relation is stronger in some groups, and interpret the cross-level interaction and the conditional effects around it.
- Let slopes vary across groups
- Choose between estimation methods, compare nested models and test effects correctly, build a model in sensible steps, check its assumptions and report it in a standard format.
- Estimate models and test their effectsUse maximum likelihood and REML for the right purposes, compare nested models with likelihood-ratio tests and information criteria, test fixed effects and variance components, and handle singular fits.
- Build, check and report a multilevel modelBuild a model in a defensible order, check its assumptions and sample size, and report it so that readers can see the design, the estimates and the decisions taken.
- Estimate models and test their effects
- Treat repeated measurements as occasions nested in people, describe each person's trajectory with random intercepts and slopes for time, and test whether change depends on characteristics of the person.
- Set up and interpret a basic growth modelArrange repeated measurements as occasions within people, code time so that the intercept has a clear meaning, and interpret average change and individual differences in change.
- Explain differences in change and model curved trajectoriesAdd person-level predictors of starting level and rate of change, interpret the time-by-group interaction, and extend the model with a quadratic trend, a residual covariance structure and time-varying predictors.
- Set up and interpret a basic growth model
Multilevel Models study guide
1Recognize multilevel data and measure clustering
Grouped observations share information. A school contributes many students, and a person contributes several measurements, so the row count alone cannot describe the study's precision. Learn to identify the levels and arrange the data, then trace what clustering does to standard errors. The empty model separates between-group from within-group variation and turns that split into an intraclass correlation you can interpret.
1.1 Recognize nested, clustered and repeated-measures data
A row is a record of an observation. It is not necessarily an independent piece of information. Before choosing a model, identify who or what was measured and which observations share a setting or a person.
Name the levels
In student data, students are level 1 and schools are level 2. A school is a cluster: several students belong to it. In repeated-measures data, occasions are level 1 and people are level 2. A diary with 150 people observed on 14 evenings has up to rows, but only 150 people.
Classify a variable by asking whether it can differ between two observations in the same cluster. Homework hours can differ between students in one school, so homework is a level-1 predictor. School size has one value for everyone in the school, so it is level 2. Each school's average homework is also level 2, even though it was calculated from a level-1 variable.
This distinction follows the study design. A person's age is a person-level variable in a short diary study, while a daily sleep measure varies across that person's occasions. The column's name alone does not determine its level.
Give each observation its own row
Long format stores one row per level-1 observation, with the cluster ID repeated. For a growth study, the columns might be person, week, and anxiety. Someone measured at weeks 0, 2, and 6 contributes three rows with the same person ID and three different time values.
| Layout | What a row represents | How occasions appear |
|---|---|---|
| Long | One person at one occasion | A time column identifies the occasion |
| Wide | One person | Separate score columns represent occasions |
A wide file prepared for repeated-measures ANOVA must be reshaped before fitting a growth model. Preserve the actual time values during the reshape. A missed occasion leaves fewer observed rows; it does not turn week 6 into week 4. Schools may also have unequal numbers of students. Such unbalanced data can be used in a multilevel model.
Check which groups contain which units
A hierarchy can have three levels, such as students within classes within schools. Make IDs unique across the data set. If every school numbers its classes 1, 2, and 3, the label "class 1" is ambiguous. IDs such as "S12-C1" and "S18-C1" identify different classes.
Nested factors form a containment structure: each class belongs to one school. Crossed factors classify the same observation in two ways without one containing the other. If every participant rates every photo, a rating belongs to a participant and a photo; neither participants nor photos sit inside the other factor.
To inspect a new file, trace one observation back to each shared influence. Then count distinct IDs and rows per ID. Repeated clinic IDs identify patients sharing a clinic; repeated person IDs identify measurements sharing a person. Treating every long-format row as independent misses the dependency that the model needs to represent.
Key Takeaways
- Identify level 1 as the observations and level 2 as their groups.
- A variable is level 1 if it can vary within a group; a group mean is level 2.
- Use long format with an explicit, unambiguous grouping ID.
- Nested groups form a hierarchy; crossed factors classify observations in overlapping ways.
- Unequal group sizes and missing occasions are compatible with multilevel analysis.
1.2 Explain why clustering changes the analysis
Students from one school share teachers, resources, and local conditions. Their scores therefore carry overlapping information. Ordinary regression's independence assumption concerns errors, so a file with many rows can still provide much less independent information than its row count suggests.
Follow the effect on precision
With positive clustering, treating group members as independent commonly makes standard errors too small for group-level comparisons. Confidence intervals become too narrow and false positives become too frequent. A coefficient can look reasonable while its reported precision is misleading. This is especially serious for a school-level predictor because every student in a school repeats the same predictor value.
For equal-sized groups, the design effect for a mean is
where is group size and is the intraclass correlation. This gives an approximate information count, . The standard-error multiplier is the square root of the design effect, because standard errors are square roots of sampling variances.
For 2000 students in 80 schools of 25, with an ICC of 0.20:
- Subtract one from group size: .
- Calculate .
- Divide independent-observation equivalents.
- Take for the standard-error multiplier.
These calculations describe the mean and illustrate the loss of information for group-level comparisons; they are not a universal correction for every regression slope. Even a small ICC matters with large groups: at 0.05, groups of 25 give a design effect of 2.2, while groups of 100 give 5.95.
Compare the alternatives
| Approach | What it estimates | What it loses or requires |
|---|---|---|
| Analyze group means | A relation between groups | Individual variation and within-group relations |
| Separate regressions | Each group's intercept and slopes | Many parameters; small groups give noisy estimates |
| Group indicator variables | Separate intercepts, common slopes | Interactions are needed for separate slopes |
| Multilevel model | Average effects and group variation | A specified model for the dependence |
Aggregation can invite the ecological fallacy. A relation between average homework and average score across schools need not describe the relation between students within a school. School means also differ in precision when sample sizes differ.
School indicators absorb every school-level constant. With a full set of school intercepts, a tutoring-program indicator that is constant within each school cannot have a separately estimated coefficient. Random intercepts instead describe school differences with a variance and allow school-level predictors in the model.
Plan information at the right level
For a question about school policy, recruiting more schools usually adds more useful information than recruiting the same number of additional students from existing schools. More students improve each school's estimate, but they do not create new independent school policies. Report both the number of observations and the number of groups so readers can judge the information behind an effect.
Key Takeaways
- Positive clustering can make ordinary-regression inference overstate precision, especially for group-level predictors.
- For equal-sized clusters, a mean has design effect .
- Effective sample size divides the row count by the design effect; the SE multiplier is its square root.
- A group-level association need not describe a within-group association.
- Group indicators give separate intercepts; separate slopes require interactions.
- For group-level questions, the number of groups is a central part of sample size.
1.3 Measure clustering with the intraclass correlation
The empty model separates differences between groups from differences inside groups before adding predictors. It supplies a baseline description of clustering and a reference for examining how predictors change the unexplained variance.
Read the empty model
For observation in group ,
The fixed intercept is the overall mean. The random intercept shifts the mean for group . The residual is an individual's departure from that group mean. The basic model gives the random intercepts mean 0 and variance , and residuals mean 0 and variance . The two parts are independent and normally distributed.
Two students in the same school share but have different residuals. Students from different schools share neither term. This shared random intercept is how the model represents dependence.
Calculate the ICC from variances
The intraclass correlation is
The numerator is between-group variance; the denominator is total variance. With between-school variance 18 and within-school variance 72, total variance is 90 and the ICC is . Thus 20% of score variation lies between schools and 80% within schools. Equivalently, the model gives a correlation of 0.20 for two different students in the same school.
The ICC is a variance share, not a percentage of people. An ICC of 0.20 does not identify a special 20% of students. It summarizes how outcomes vary across the whole hierarchy.
Read software output and recover the units
In R, fit lmer(math ~ 1 + (1 | school), data = students). The Random effects output gives the school intercept variance and the Residual variance. SPSS calls its corresponding table Estimates of Covariance Parameters. Check whether the displayed column contains variances or standard deviations.
If software gives SDs, square them before computing the ICC. Dividing the school SD by the sum of the two SDs gives a different quantity. To describe the spread in score points, go the other way: points is the school-intercept SD.
With overall mean 52, the normal random-intercept distribution places about 95% of true school means between and . This describes a distribution of school means. It is not a confidence interval for the overall mean or a range containing 95% of individual scores.
Distinguish initial from remaining clustering
After adding predictors, use the remaining variances for the conditional ICC. Variances 14 and 60 give . Label which ICC you report. The empty-model ICC describes initial clustering; the conditional ICC describes clustering after adjustment.
School-achievement ICCs around 0.10 to 0.25 are common; repeated scores from one person often have stronger clustering. A small ICC is not a prerequisite test that decides whether the study has groups. The design supplies that structure. ML and REML keep estimated variances nonnegative, so an estimate can stop at zero. Testing a single random-intercept variance uses a boundary-adjusted likelihood comparison, not an ordinary unconstrained coefficient test.
Key Takeaways
- The empty model divides total variance into between-group and residual components.
- Compute ICC using variances: .
- The ICC is both a variance share and a same-group correlation in the empty model.
- Take a square root to express a variance component in outcome units.
- Distinguish the empty-model ICC from the conditional ICC after predictors.
2Build and interpret random-intercept models
A mixed model combines population coefficients with group-specific deviations. Begin by deciding what should be fixed and what should vary across groups, then read a random-intercept model and build predictions from it. Centering makes the intercept meaningful, but different centering choices also answer different questions. Separating individual deviations from group means lets you distinguish within-group, between-group, and contextual effects.
2.1 Distinguish fixed effects from random effects
A mixed model describes the average relation and the ways groups depart from it. Fixed and random name parts of that description. They do not say whether a predictor was randomly assigned or whether it matters scientifically.
Separate a coefficient from a deviation
A fixed effect has one population value: the average intercept or average homework slope, for example. It is estimated with a coefficient, standard error, and confidence interval, much as in multiple regression.
A random effect is a group-specific deviation. A school's intercept may be above or below the population intercept. The model treats those deviations as draws from a distribution with mean zero and estimates the distribution's variance. For 80 schools, an intercept variance replaces the 79 school-indicator coefficients that would describe fixed school differences.
Homework can have both parts. Its fixed slope describes the average relation. Its random slopes describe departures from that average across schools. Calling homework simply "fixed" or "random" can hide this distinction; name the coefficient and the group over which it varies.
Decide how to represent a factor
| Question and design | Useful representation |
|---|---|
| Generalize from many sampled schools to a population of schools | School as a random grouping factor |
| Compare three specific teaching methods | Method as a fixed categorical predictor |
| Explain school differences with school-level predictors | Random school effects plus those fixed predictors |
With fewer than about 5 to 10 groups, a variance estimate is very imprecise. Modeling the specific groups with indicators is a common choice in that situation. This is a planning rule of thumb, not a guarantee that one model will fit every small study.
A fixed-effects model in econometrics often means a separate intercept for every group, or the equivalent within-group transformation. That usage differs from the phrase "fixed effects" in a mixed-model output table. Group intercepts absorb predictors that are constant inside a group, preventing separate estimation of their effects.
See how partial pooling works
Partial pooling combines a group's own information with information from other groups. A small or noisy group's predicted deviation is pulled more strongly toward zero. This pull is shrinkage.
In the empty model, an approximate shrinkage weight is
Suppose the overall mean is 52, a school's observed mean is 60, and the variances are 18 between schools and 72 within schools. The observed school deviation is 8 points. With 25 students, , giving a predicted deviation of about 6.9 points. With four students, , giving 4.0 points.
Complete pooling predicts zero deviation for both schools. No pooling keeps the observed deviation of 8 for both. Partial pooling allows the amount of evidence from each school to affect its prediction.
R's ranef() returns predicted random effects, often called conditional modes or BLUPs. These predictions can describe group differences, but they are not exact school effects. A ranking based on them still has uncertainty, especially when groups are small.
Key Takeaways
- Fixed effects describe population coefficients; random effects describe group deviations.
- One predictor can have both an average slope and random slope deviations.
- Choose a grouping representation from the study question, generalization, and number of groups.
- Partial pooling shrinks small or noisy groups more strongly.
- Predicted random effects carry uncertainty and should not be treated as exact rankings.
- The econometric phrase "fixed-effects model" often means group-specific intercepts.
2.2 Write, fit and read a random-intercept model
A random-intercept model gives every school its own starting height while keeping one common predictor slope. Its group lines are parallel. The random intercept accounts for clustering without requiring a separate fixed coefficient for every school.
Combine the two levels
At level 1, write . At level 2, write . Substituting the second equation into the first gives
Here is the average intercept and is the common slope. The school deviation changes height, not slope. Some books use the letter b for coefficients that other books call beta or gamma; follow each symbol's role.
Fit the same model in different software
| Software | Model setup |
|---|---|
| R, lme4 | Fixed homework slope with a random school intercept |
| SPSS | Analyze > Mixed Models > Linear; school in Subjects, homework as a fixed covariate, intercept in Random |
| jamovi, GAMLj | Mixed Models; school in Cluster, homework as covariate, random intercept selected |
| JASP | Mixed Models > Linear Mixed Models; school as grouping factor, homework fixed, intercept random |
In R, fit lmer(math ~ homework_c + (1 | school), data = students). Use the same long data and predictor coding. A continuous homework variable and a categorical school ID play different roles, even if both columns contain numbers. Request fixed-effect estimates and the random-effect variances or SDs.
Build a prediction
For 2000 students in 80 equal-sized schools, let homework be centered at 5 hours per week. Estimates are intercept 52.0, homework slope 1.5, school-intercept variance 14, and residual variance 60. The intercept is the predicted score at 5 homework hours in a school whose random deviation is zero.
For a student doing 8 hours, the centered value is . In a sampled school with predicted deviation 3.0, the prediction is . For a new school whose deviation is unknown, the population prediction sets that deviation to zero: . The unknown residual is also set to its mean of zero for either prediction.
The common slope blends within-school and between-school associations when the predictor's school mean is absent. Centering at the overall mean does not turn it into a pure within-school effect.
Interpret the remaining variation
The school-intercept SD is score points. Around 95% of school intercepts fall between approximately 44.7 and 59.3 under the normal random-effects distribution. The variance 14 itself is in squared score units, not score points.
Compared with empty-model variances 18 and 72, the proportional reductions are between schools and within schools. These are level-specific pseudo-R-squared measures. A component can increase after adding a predictor, so these measures can be slightly negative. The conditional ICC is .
Key Takeaways
- Random intercepts shift parallel regression lines up or down.
- Interpret an intercept at predictor zero and state how the predictor was centered.
- Add a sampled group's predicted deviation for a group-specific prediction.
- Use variance reductions separately at each level; they are not ordinary regression R-squared.
2.3 Add predictors at both levels and choose their centering
A predictor can answer different questions at different levels. A student's extra hour of homework compared with schoolmates is not the same comparison as attending a school where average homework is an hour higher. Centering helps define these comparisons.
Add a school-level predictor
Let tutoring equal 1 for a school with a program and 0 otherwise. Its fixed coefficient enters the intercept equation:
An estimate of 4.0 means a four-point adjusted difference between program and non-program schools. With SE 1.6, the Wald statistic is . About 78 Satterthwaite degrees of freedom give a p-value of .015 and a 95% interval of , or approximately 0.81 to 7.19 points. The information comes from the 80 schools, not 2000 independent program assignments.
A school-level predictor mainly explains between-school variation. If intercept variance falls from 14 to 10.5, the reduction is , or 25% of the remaining between-school variance. The residual variance may change little because program status does not vary within a school.
Choose a meaningful zero
Grand-mean centering subtracts the overall mean. If average homework is 5 hours, use . In an additive random-intercept model, this moves the intercept to 5 hours without changing the slope or model fit.
Group-mean centering subtracts the school's own mean: . A value of 2 now means two hours above that student's school average. Two students with this same centered value may have different raw homework hours if their schools have different means.
| Predictor | Comparison it supports |
|---|---|
| Homework minus overall mean, entered alone | A blend of within-school and between-school relations |
| Homework minus school mean | Students compared with schoolmates |
| School mean, alongside within-school deviations | Schools compared with schools |
Separate within, between, and contextual effects
Enter both the within-school deviation and the school mean:
If and , one more hour relative to schoolmates is associated with 1.5 more points. A school average one hour higher is associated with 3.0 more points. The contextual effect is : the school-average difference when students' own homework is held constant.
Why subtract? Expanding the equation gives . Thus, when raw homework and the school mean are entered together, the school-mean coefficient is contextual. When deviations and the mean are entered together, that coefficient is between-school. Read the coding before naming the effect.
For a program comparison adjusted for homework composition, include both deviations and school means so the two homework relations can differ. Keep 0/1 predictors on their meaningful scale, and compare variance reductions using consistent centering and cases.
Key Takeaways
- Level-2 predictors enter the group-intercept equation and mainly explain between-group variation.
- Grand-mean centering changes the reference point; group-mean centering creates within-group deviations.
- Include deviations and group means to estimate within and between effects separately.
- The contextual effect equals the between effect minus the within effect.
- The group-mean coefficient changes meaning when raw values replace within-group deviations.
- Use group-level information and appropriate degrees of freedom for group-level effects.
- Hold coding and the analyzed cases consistent when comparing variance reductions.
3Fit and interpret random-slope models
The same predictor can have different slopes in different groups. Random slopes describe that spread, while a cross-level interaction asks whether a group characteristic explains part of it. Learn to read slope variances and intercept-slope covariance, follow the changing distance between group lines, and calculate conditional slopes and group differences. Keep the predictor's zero point visible throughout the interpretation.
3.1 Let slopes vary across groups
Parallel school lines are a strong restriction. If homework relates more strongly to scores in some schools than in others, a random-slope model gives the slope its own school-specific deviation.
Give the slope a random part
Write . The combined model is
The fixed slope is the average slope. The random deviation is added to it for school . The random part now estimates intercept variance , slope variance , and intercept-slope covariance .
In R, lmer(math ~ homework_c + (1 + homework_c | school), data = students) fits both random effects with a freely estimated covariance. Replacing | with || sets the covariance to zero for this numeric predictor. In SPSS, put intercept and homework in Random and choose Unstructured covariance; Variance Components gives a diagonal structure. In GAMLj and JASP, select homework as a random coefficient alongside the intercept and check whether their correlation is estimated.
A predictor must vary within the grouping units to support its slope variation across those units. A school-level program indicator is constant inside each school, so it cannot have an identifiable random slope across those same schools.
Put slope variation into useful units
With average slope 1.5 and slope variance 0.25, the slope SD is points per homework hour. The normal random-slope distribution places about 95% of school slopes between and . This is a distribution of school slopes, not the confidence interval for their average.
With intercept variance 14 and covariance −0.6, the intercept-slope correlation is
At homework centered at 5 hours, schools with higher predicted scores at 5 hours tend to have flatter slopes. The zero point matters: moving it changes which school heights count as intercepts and can change this correlation.
Track how the group spread changes
At centered predictor value , between-school variance is
At 2 homework hours, , giving . At 5 hours, and the variance is 14. It reaches its minimum at , corresponding to 7.4 hours, where it is 12.56. At 8 hours it rises slightly to 12.65.
Negative covariance therefore means the lines initially fan in as the predictor rises from zero; it does not mean their spread shrinks forever. There is no single constant ICC across predictor values in this model.
An average slope near zero can coexist with substantial slope variation. Omitting real slope variation can overstate the precision of the average slope. Conversely, adding many random slopes with limited group information can produce zero variances or perfect correlations: signs of a singular fit that needs investigation.
Key Takeaways
- A random slope adds a group-specific deviation to the average slope.
- The random intercept-slope model estimates two variances and a covariance.
- Take the square root of slope variance to describe slope spread in slope units.
- Interpret intercept-slope covariance at the chosen predictor zero.
- Between-group variance changes with the predictor through .
- A near-zero average slope does not rule out substantial differences between group slopes.
3.2 Explain differences in slopes with cross-level interactions
A random slope shows that a relation varies across groups. A cross-level interaction asks whether a measured group characteristic helps explain that variation. The interaction is a fixed predictor of the slope; random slope variation remains around the predicted slopes.
Put the group predictor into the slope equation
Let be centered homework and indicate a school tutoring program. Use
Substitution produces the fixed interaction term alongside both lower-order terms. Its coefficient tells how much the homework slope changes when program status changes from 0 to 1.
In R, use lmer(math ~ homework_c * tutoring + (1 + homework_c | school), data = students). The * adds both fixed main terms and their interaction. In SPSS, GAMLj, and JASP, include the product in the fixed-effects model and retain the random homework slope. Set the same 0/1 reference coding before comparing output across programs.
Calculate each group's slope
Suppose the fixed intercept is 50.5, program coefficient 4.0, homework coefficient 1.8, and interaction −0.6. For a school with random deviations zero:
| School type | Predicted line | Homework slope |
|---|---|---|
| No program, | 1.8 points per hour | |
| Program, | 1.2 points per hour |
The negative interaction reduces the slope by 0.6; it does not make the slope negative. At 2 hours of homework, , predicted scores are 45.1 without the program and 50.9 with it. At 5 hours, they are 50.5 and 54.5; at 8 hours, they are 55.9 and 58.1.
Interpret the program difference at a stated homework value
The program gap is . It is 5.8 points at 2 hours, 4.0 at 5 hours, and 2.2 at 8 hours. The program coefficient 4.0 is the difference only at centered homework zero. The homework coefficient 1.8 is the slope only for the reference category, schools without a program. These are conditional effects.
If the scientific question is specifically about within-school homework relations, use within-school-centered homework with school means in the model. Grand-mean-centered homework alone can mix within-school and between-school relations, even when an interaction is present.
Describe what the interaction explains
If slope variance falls from 0.25 to 0.16, the proportional reduction is . Program status explains 36% of the previously unexplained slope variation. The remaining 0.16 represents differences not accounted for by program status.
Keep the random slope when testing the interaction so uncertainty reflects residual slope variation. Theory can justify testing a cross-level interaction even if a separate test of slope variance is not significant. A fixed interaction and a random slope answer different questions: a systematic difference linked to a predictor and the remaining spread around that difference.
Key Takeaways
- A cross-level interaction lets a level-2 predictor explain a level-1 slope.
- Calculate a conditional slope by adding the interaction contribution to the reference slope.
- With an interaction, a group coefficient describes the gap at predictor zero.
- Retain random slope variation when testing the fixed interaction.
- Compare slope variances to describe how much slope variation the group predictor explains.
4Estimate, compare, check and report multilevel models
A useful model needs estimates, defensible comparisons, and checks of the assumptions behind them. Choose ML or REML to match the comparison, account for the boundary when testing variances, and read fixed-effect tests with their degrees-of-freedom method. Then examine residuals and influential groups, judge the information supplied by the group count, and report enough of the fixed and random parts for readers to assess the analysis.
4.1 Estimate models and test their effects
Model output combines estimation, fit comparisons, and tests of individual effects. These tools use different reference distributions. Start each comparison by checking what changed and whether both models used exactly the same observations.
Match estimation to the comparison
Maximum likelihood (ML) estimates parameters by maximizing the likelihood. Restricted maximum likelihood (REML) accounts for estimating fixed effects when estimating variance components, reducing their small-sample bias. REML is the default in lme4 and SPSS MIXED.
| Task | Estimation choice |
|---|---|
| Compare models with different fixed effects | ML for both models |
| Compare random structures with the same fixed effects | REML is a usual choice |
| Estimate the final selected model | REML |
REML likelihoods with different fixed effects are not comparable. In R, anova() on fitted lme4 models refits REML models with ML by default. For a deliberate REML comparison of random structures, keep the fixed effects identical and use refit = FALSE.
Compare nested models
Deviance is minus twice the log-likelihood. The likelihood-ratio statistic subtracts the larger model's deviance from the smaller model's deviance. For ordinary fixed-effect comparisons, compare it with chi-square degrees of freedom equal to the added parameter count. The models must be nested: the smaller must be obtained by restricting the larger.
A variance of zero is on a boundary because variances cannot be negative. For one added random-intercept variance, the usual asymptotic boundary test halves the ordinary one-df chi-square p-value. A statistic of 3.2 gives about .074 before correction and .037 after it.
Adding a random slope and its covariance to an existing random-intercept model adds two parameters. The boundary reference is a 50:50 mixture of chi-square with one and two df. Deviances 14620.4 and 14608.9 differ by 11.5. The mixture gives about .0019, while an ordinary two-df test gives about .0032. Do not halve every random-effects p-value: identify which variance and covariance parameters were added.
Balance fit against complexity
For the same data and comparable likelihoods,
Here is deviance and counts estimated parameters. Lower is preferred. With ML, the intercept model has four parameters and the slope model six. Their AICs are 14628.4 and 14620.9, favoring random slopes. Using , their BICs are approximately 14650.8 and 14654.5, favoring the simpler model. BIC applies a larger penalty here; programs may use different definitions of its sample size. Information criteria also allow nonnested comparisons when the likelihoods are comparable.
Test coefficients and diagnose the fit
A fixed-effect Wald statistic is . Mixed-model degrees of freedom are approximated. lmerTest and SPSS MIXED use Satterthwaite by default; Kenward–Roger is another small-sample method. lme4 alone gives t values without p-values. Report the method, especially for group-level effects whose information is tied to the number of groups.
Wald z tests for variance components are unreliable near zero because the sampling distribution is bounded and skewed. Use an appropriate likelihood comparison or profile interval.
A singular fit has a degenerate random-effects covariance matrix: in an intercept-slope model, a variance near zero or correlation near ±1. Check the data and scaling, then consider dropping the correlation or an unsupported random slope. Singularity and failure to converge are different problems; resolve convergence warnings before interpreting estimates.
Key Takeaways
- Use ML to compare different fixed-effects models and REML for final variance estimation.
- Compare nested models on exactly the same observations.
- Variance-component LRTs need a boundary reference distribution.
- Lower AIC or BIC trades improved fit against added parameters.
- Report the approximation used for fixed-effect degrees of freedom.
- Investigate singularity and resolve nonconvergence before interpreting a model.
4.2 Build, check and report a multilevel model
A defensible model starts with a research question and a description of the data structure. Fit comparisons help evaluate candidates, but they cannot choose the scientific question or repair an incorrect hierarchy.
Build in interpretable steps
Start with the empty model and its ICC. Add relevant level-1 predictors, then level-2 predictors. Consider random slopes for level-1 relations that theory suggests may differ, and cross-level interactions that could explain those differences. Keep track of the analyzed cases and predictor coding at every stage.
Compare fixed-effects changes with ML. After selecting the model, refit with REML for the reported estimates. An added predictor with missing values can reduce the case count; refit comparison models on the same rows before comparing likelihoods. A lower deviance obtained from fewer observations is not evidence of better fit.
Check assumptions at both levels
The basic linear mixed model assumes linear relations, approximately normal residuals with constant variance, normal random effects with mean zero, and independence of residual observations after the modeled dependence is accounted for. It also assumes random effects are uncorrelated with predictors.
A random intercept handles a shared group offset. It does not account for every possible dependency. For repeated data, nearby occasions may still have correlated residuals, requiring a residual covariance structure.
Use residual-versus-fitted plots to look for curves and funnels. Curves suggest a missing nonlinear relation; funnels suggest unequal residual variance. Q–Q plots check residual shape. A Q–Q plot of predicted random effects is only approximate because those predictions are shrunken. Check influential groups by refitting without an unusual group and comparing substantive conclusions.
If school means of homework are related to unmeasured school differences, a single homework slope can blend within and between relations. Within-school deviations plus school means separate them and address confounding by group-constant differences for the within effect. They do not remove confounding by unmeasured differences between students inside a school.
Judge information at the group level
More groups improve information about the distribution of group effects. Common planning guidelines suggest about 30 groups for many fixed-effect questions and clearly more than 50 when variance components are central. These are rules of thumb, based partly on simulation findings, not guarantees. A study with many small groups can be informative; a huge number of individuals in only a few groups does not make a between-group variance precise.
Report enough to reconstruct the analysis
Give the number of observations and groups, the range of group sizes, and the time schedule for longitudinal data. Name the software, estimation method, predictor coding, and degrees-of-freedom method. Report model comparisons with their reference distributions, fixed estimates with SEs and confidence intervals, and random variances or SDs with their correlations. Label variance and SD columns explicitly.
For example: "Students (N = 2000) were nested in 80 schools of 25. The empty-model ICC was .20. Schools with a tutoring program scored higher, b = 4.0, SE = 1.6, t(78) = 2.50, p = .015, 95% CI [0.81, 7.19], using REML and Satterthwaite degrees of freedom."
That sentence supplies the design and a fixed effect. A full report also includes the variance components and relevant diagnostics; a table can present these without a long sequence of repeated test sentences.
Key Takeaways
- Build candidate models from the research question and retain a record of cases and coding.
- Check residual shape, spread, remaining dependence, and influential groups.
- Group count matters for precision, especially for variance components.
- Report both fixed effects and random variation, with estimation and test methods.
5Model change over time with growth curve models
Repeated measurements describe trajectories within people. Coding time gives the intercept its meaning and the slope its units; random intercepts and slopes then describe differences in starting levels and rates. Extend those trajectories with person-level predictors, interactions, and curved trends. Available observations can contribute even when visits are missed, while residual time dependence and missingness still need careful attention.
5.1 Set up and interpret a basic growth model
A growth curve model treats measurements as occasions within people. Each person has a trajectory, and the model estimates both average change and differences between people's trajectories. Time is a level-1 predictor, while stable person characteristics are level 2.
Set up the data and time scale
Use one row per person per occasion. For measurements at weeks 0, 2, 4, 6, and 8, store those values in the time column. Using 0, 1, 2, 3, and 4 instead changes the slope's unit to points per two-week interval. Unequally spaced measurements must retain their actual timing.
Time zero defines the intercept. Weeks since baseline make the intercept a baseline prediction. Subtracting 4 from week centers the intercept at week 4. In a linear model, this changes intercepts, their variance, and their covariance with slopes, but leaves the average weekly slope unchanged. Coding the first measurement as 1 puts time zero before the first measurement.
Write the individual lines
At level 1,
At level 2, and . The average starting level is and the average rate of change is . People differ through their intercept and slope deviations.
In R, use lmer(anxiety ~ week + (1 + week | person), data = long). In SPSS, choose person under Subjects and week as a fixed covariate and random coefficient. In GAMLj or JASP, choose person as the cluster and include both intercept and time in the random effects. Use a continuous time covariate for a straight-line growth model.
Read an average and an individual trajectory
For 200 adults measured over 8 weeks on an anxiety scale from 0 to 60, suppose the average intercept is 30.0 and slope −1.2 points per week. At week 4 the average prediction is ; at week 8 it is .
With intercept variance 36 and slope variance 0.16, their SDs are 6 points and 0.4 points per week. About 95% of person slopes lie between and under the normal model. Covariance −0.72 gives correlation : higher starters tend to decline faster.
A person with intercept deviation +4 and slope deviation −0.3 starts at 34 and changes by points per week. Their predicted week-8 score is . Add both deviations before using the person's line.
Use incomplete data thoughtfully
A person missing one score can contribute their other observed scores. Likelihood-based growth analysis supports missing outcomes under missing at random, with a correctly specified model: missingness may depend on observed history but not on the unseen outcome after that history is accounted for. Include relevant observed predictors of missingness. Missing predictor values can still remove rows.
Unlike standard repeated-measures ANOVA, growth models allow person-specific schedules and model dependence without sphericity. With only two common occasions per person, a freely varying intercept-slope covariance and residual variance cannot all be separated. At least three occasions for a good share of people support the basic random linear trajectory; richer random curves need more information.
Key Takeaways
- Growth models place occasions at level 1 and people at level 2.
- Time zero determines the intercept; actual spacing determines the slope units.
- Combine fixed and person-specific effects to predict an individual trajectory.
- Take square roots of growth variances to describe differences in starting level and rate.
- Use available outcomes under missing at random and a correctly specified model; check missing predictors too.
5.2 Explain differences in change and model curved trajectories
People may change at different rates because they received different treatments or have different characteristics. Change may also slow or accelerate. Extend the growth model by asking separately what predicts the starting level, what predicts the slope, and whether a straight line fits the observed period.
Let a person-level predictor explain change
For group indicator , use
The fixed time-by-group interaction is the difference in rates of change. In R: lmer(anxiety ~ week * condition + (1 + week | person), data = long). In SPSS, GAMLj, or JASP, include time, condition, and their product as fixed terms, with random intercept and time slope by person. Use 0/1 coding to match the reference-group interpretation.
Suppose waitlist is 0 and therapy is 1. Estimates are intercept 30.2, group −0.4, time −0.7, and interaction −1.0. The waitlist starts at 30.2 and declines 0.7 points per week. Therapy starts at and declines points per week.
At week 8 the predictions are 24.6 and 16.2, a therapy-minus-waitlist gap of −8.4 points. The same gap comes from . The condition coefficient is the baseline gap; the interaction describes differential change. Random assignment makes a zero baseline difference the expectation, but a sample can still have a baseline imbalance.
Fit and read a curved trajectory
Add a fixed squared-time term:
At week 8, . The instantaneous rate is the linear coefficient plus twice the quadratic coefficient times time: . It is −2 at baseline and −0.4 at week 8. The positive quadratic term bends a declining trajectory upward, so improvement slows during the observed weeks.
The lowest point is at week 10, beyond the observed period. Do not use that fitted turning point to claim a later reversal. In a quadratic model, the linear coefficient is the rate at time zero, so recentering time changes it. Three distinct times can identify an average quadratic trend; a freely varying random quadratic term generally needs at least four common occasions. With about five occasions, avoid adding higher-order polynomials without strong support.
Check remaining time dependence
Random trajectories may leave residual correlation between nearby occasions. For equally spaced occasions, an AR(1) residual structure gives correlation one interval apart, two intervals apart, and so on. A missing visit does not shorten the elapsed gap. For irregular timing, use a structure that represents actual time distances.
SPSS offers residual structures through Repeated. In R, nlme or glmmTMB supports residual structures; lme4 does not directly specify them. Compare candidate residual structures on the same data with the same fixed effects.
A time-varying predictor such as sleep can be split into each person's average sleep and the occasion's deviation from that average. Their coefficients separate differences between people from differences within a person. Entering sleep alone can blend the two relations.
Key Takeaways
- Time-by-group interactions describe differences in rates; group coefficients describe gaps at time zero.
- Add the interaction to the reference slope before predicting the second group.
- A positive quadratic term can describe a slowing decline.
- Interpret a curve within the observed time range.
- Residual time dependence can remain after random intercepts and slopes.
- Separate person means from occasion deviations for time-varying predictors.
Multilevel Models examples
1Find the groups and calculate their shared variation
12 steps
- 1IntroductionStart with who shares what
A study records 2000 students in 80 schools. Two students from one school share an environment, so their scores need not be independent. The ICC measures how strongly scores cluster within schools, and ignoring that clustering overstates precision.
First identify the observations and their groups. Then follow how shared information affects precision (the design effect), and use a model with no predictors, the empty model, to measure the variation between schools.
- 2ExplanationName the observations and groups
Students are level 1; schools are level 2. A student's homework can differ from a classmate's, so it is level 1. School size is the same for all rows from one school, so it is level 2.
For repeated measurements, replace students with occasions and schools with people. The lower level is the measurement occasion, even though a person supplied the score.
- 3ExampleGive the groups usable IDs
Long data keep one student per row, with school ID beside the score and predictors. If classes are also recorded, a class ID must identify one actual class across the whole file.
"S3-C1" and "S9-C1" distinguish class 1 in two different schools. A plain class number of 1 would merge them. In repeated data, long format instead gives one person-occasion per row, retaining the actual measurement time.
- 4ChallengeLocate the repeated units
A study records pain on six occasions for each of 120 people. What are the level-1 and level-2 units, and how many long-format rows can there be?
---reveal---
The occasions are level 1 and the 120 people are level 2. With complete observations there are rows. A missed occasion reduces the observed row count; it does not create a new person or erase the person's other scores.
- 5ExplanationFollow dependence into the SE
Same-school students share influences that make their outcomes correlated. For a school-level comparison, ignoring that dependence counts repeated school information as if it were new.
The coefficient may still look reasonable, while its standard error is too small and its confidence interval too narrow. This explains why a large individual sample does not by itself make a school-level effect precise.
- 6ExampleCalculate the design effect
For equally sized groups, a mean has design effect . Each school has 25 students, and suppose the ICC is 0.20.
The design effect is . Dividing gives about 345 independent-observation equivalents. The SE multiplier is , not 5.8, because standard errors use the square root of sampling variance.
- 7ChallengeDecide where new information comes from
For a school-level policy question, why could adding 20 new schools be more useful than adding many students to the same schools?
---reveal---
New schools supply new group-level information about policies and school differences. More students in existing schools improve estimates of those schools' means, but they do not create new school-level realizations. The number of groups limits what can be learned about group-level effects.
- 8ExplanationSplit a score into three pieces
The empty model is . A score combines the overall mean, the school's departure from it, and the student's residual.
The school deviations have variance , and residuals have variance . Students in one school share the school deviation. That shared part creates the model's same-school correlation.
- 9ExampleTurn the variance split into an ICC
Suppose the empty model gives between-school variance 18 and residual variance 72. Add them to get total variance 90.
The ICC is . Thus 20% of variation lies between schools. It is also the model's correlation for two different students from the same school. It does not mean that exactly 20% of students are influenced by their school.
- 10ChallengeUse the right output column
Software reports a group SD of 2 and residual SD of 4. What is the ICC?
---reveal---
Square the SDs first: between variance is 4 and residual variance is 16. The ICC is . Using would partition standard deviations instead of variances. An SD is useful for describing spread in outcome units, but it does not go directly into the ICC formula.
- 11ChallengeCheck a claim about many rows
A researcher says, "The file has one row per student, so its 2000 rows are independent." What design information and model result would help correct that claim?
---reveal---
Identify which rows share a school ID, then use the empty-model variance split to describe their clustering. Separate rows preserve individual records; they do not remove shared school influences. Report school count alongside student count and use a model that represents the dependence.
- 12RecapConnect the design to the information
Identify the observation and group before counting independent information. Long format preserves the records and IDs needed to fit that structure.
The design effect illustrates the loss of information from positive clustering for a mean. The empty model estimates the between and residual variances, and their ratio gives the ICC. Group averages answer a group question and cannot substitute for an individual-level relation.
2Build predictions and separate the two levels
14 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionGive each group a starting height
- 2ExplanationSeparate average effects from departures
- 3ExampleShrink a noisy group prediction
- 4ChallengeCompare the amount of shrinkage
- 5ExplanationWrite the model you will predict from
- 6ExampleCenter before multiplying
- 7ExampleAdd the sampled school deviation
- 8ChallengeKeep slope and height separate
- 9ExplanationChoose the comparison before centering
- 10ExamplePut deviations and group means together
- 11ExplanationHold the student's own hours constant
- 12ChallengeRead a differently coded output
- 13ChallengeAdjust a school comparison
- 14RecapRead the coding alongside the coefficients
3Let group slopes differ and explain the differences
11 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionMove beyond parallel lines
- 2ExplanationGive each school its own slope
- 3ExampleRead the slope distribution
- 4ExplanationInterpret covariance at the reference point
- 5ExampleLocate where group spread is smallest
- 6ChallengeAvoid a constant-ICC shortcut
- 7ExplanationLet a school characteristic predict the slope
- 8ExampleCalculate both lines
- 9ChallengeFind the gap away from zero
- 10ChallengeExplain the remaining slope variation
- 11RecapSeparate average, systematic, and remaining differences
4Choose a valid comparison and check the fitted model
13 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionMake each comparison answer one question
- 2ExplanationUse ML and REML for the right tasks
- 3ExplanationCheck nesting and the observations
- 4ExampleAdjust a variance-component test
- 5ExampleAccount for the added covariance
- 6ConnectionBalance fit against extra parameters
- 7ChallengeRepair an invalid test
- 8ExplanationBuild from the scientific question
- 9ExampleRead the residual pattern
- 10TipCount groups and examine influence
- 11ChallengeComplete the report
- 12ChallengeCheck a claim that convergence is enough
- 13RecapLink the test to the fitted structure
5Follow average and individual change
14 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionTreat occasions as observations within people
- 2ExplanationGive the time column a meaningful zero
- 3ExampleBuild the average trajectory
- 4ExampleAdd the person's own departures
- 5ChallengeRead the time origin
- 6TipKeep the observed visits
- 7ExplanationSeparate the baseline gap from the rate gap
- 8ExampleCalculate the treatment trajectory
- 9ChallengePredict a gap at a later visit
- 10ExampleRead a slowing decline
- 11ExplanationCheck dependence left after the trajectories
- 12ConnectionSeparate a person's usual level from a daily departure
- 13ChallengeMove the clock in a treatment model
- 14RecapKeep time, people, and comparisons aligned
Multilevel Models practice questions
Set 1: Practice 1: Read the hierarchy and basic models10 Practice Questions
Question 1 of 10
Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
Show answerHide answer
Question 4 of 10
Show answerHide answer
Question 5 of 10
Show answerHide answer
Question 6 of 10
Show answerHide answer
Question 7 of 10
Show answerHide answer
Question 8 of 10
Show answerHide answer
Question 9 of 10
Show answerHide answer
Question 10 of 10
Show answerHide answer
Set 2: Practice 2: Compare effects and predictions10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 3: Practice 3: Diagnose model choices10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 4: Practice 4: Transfer the reasoning10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
A
Aggregation
AIC
AR(1)
B
Between-group effect
Between-group variance
BIC
BLUP
C
Conditional effect
Conditional ICC
Contextual effect
Cross-level interaction
Crossed factors
D
Design effect
Deviance
Dummy coding
E
Ecological fallacy
Effective sample size
Empty model
F
Fixed effect
G
Grand-mean centering
Group-mean centering
Group-specific prediction
Growth curve model
I
Independence
Influential group
Intercept-slope covariance
Intraclass correlation
L
Level-1 variable
Level-2 variable
Likelihood-ratio test
Linear mixed model
Long format
M
Maximum likelihood
Missing at random
Multilevel data
N
Nested factors
P
Partial pooling
Person-specific trajectory
Population prediction
Pseudo-R-squared
Q
Q–Q plot
Quadratic trend
R
Random effect
Random-intercept model
Random-slope model
Residual covariance structure
Residual diagnostic
Residual variance
Restricted maximum likelihood
S
Satterthwaite approximation
Sensitivity analysis
Shrinkage
Simple slope
Singular fit
Slope variance
T
Time coding
Time-by-group interaction
Time-varying predictor
U
Unbalanced data
Unconditional growth model
Unstructured covariance matrix
V
Variance component
W
Within-group effect
Within-person effect
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.