A linear mixed model (also called a multilevel model or mixed-effects model) extends regression to data where observations are grouped, such as repeated measures within people, students within schools, or time points within subjects. The outcome is correlated within groups because each group has its own random intercept or slope, or both. This guide gives you the exact APA 7 format for every part of the output: fixed effects, random effects, ICC, model fit, and assumption checks.
When to use a linear mixed model instead of a repeated-measures ANOVA
A repeated-measures ANOVA answers the same question when all participants have the same number of time points and no missing data. If some participants are missing observations, have unequal spacing between time points, or if you want to model how participants differ in their rate of change over time (random slopes), use a linear mixed model. It is also the standard when you have three or more levels of grouping, such as students within schools within districts.
What you need before you write a single word
An APA 7 write-up of a linear mixed model has several layers.
Software and method:
- State which software you used: R, Python, SPSS, Stata, jamovi, or other.
- Which package: lme4 or nlme in R, statsmodels in Python.
- Whether you used REML or maximum likelihood (ML) for estimation. Use REML for final estimates and hypothesis tests on fixed effects; use ML when comparing models with different fixed-effects structures via likelihood-ratio test.
Model specification:
- Write the model formula showing all fixed effects and how random effects are structured.
- Say why you chose this random structure: e.g., "Each person had a random intercept because the same person was measured four times. We also allowed the effect of time to vary randomly by person because preliminary inspection suggested heterogeneity in trajectories."
Fixed effects table:
- For each fixed effect: b, SE, 95% CI, and p value.
- Note: statsmodels reports Wald z statistics; R's lme4 with lmerTest reports t statistics with Satterthwaite degrees of freedom. Say which one you used.
Random effects:
- Standard deviation (not variance) of each random intercept or slope.
- If you have both random intercepts and slopes, report their correlation.
- Residual standard deviation.
Model fit and assumption checks:
- Intra-class correlation from a null model to show what proportion of variance is at the group level.
- R² marginal (fixed effects only) and R² conditional (fixed plus random effects), computed using Nakagawa & Schielzeth (2013) with Johnson's (2014) extension for random slopes.
- When comparing models, report AIC, BIC, −2 log-likelihood, and likelihood-ratio test (χ² and p). Note: testing random slopes involves variance on the parameter boundary, so the naive p value is conservative.
- Check residual normality and homoscedasticity visually.
The APA 7 format template
We fit a linear mixed model predicting [outcome] from [fixed effects], with observations nested within [grouping, e.g., 40 participants]. The model was estimated using [software and package, e.g., Python's statsmodels with REML]. Each participant received a random intercept and a random slope for [time predictor]. Fixed effects showed that [interpretation of each significant effect]. The random-intercept standard deviation was [SD], and the random slope for [predictor] had SD = [SD], with an intercept–slope correlation of [r]. The intra-class correlation from a null model was [ICC], indicating [interpretation]. The conditional R² was [value] (fixed and random effects), compared to [value] for the marginal R² (fixed effects only); both computed using Nakagawa & Schielzeth with Johnson's extension. To test whether random slopes improved fit over random intercepts only, we compared models using a likelihood-ratio test: χ²([df]) = [χ²], p [significance]. (Note: this test involves variance on the boundary; the naive p value is conservative.)
Formatting rules reviewers actually check:
- Software method: say REML or ML.
- Random structure justified: explain why you chose the random effects you did.
- No leading zero on p, ICC, or R².
- Standard deviations for random effects, not variances.
- Confidence intervals for fixed effects: report a 95% CI for each and say which method you used (Wald, b ± 1.96 × SE, as statsmodels gives; profile or bootstrap CIs from
confint()in lme4). - Which test statistic: say if you used Wald z or t with Satterthwaite df.
- R² method stated: specify Nakagawa & Schielzeth with Johnson extension when random slopes are present.
A worked example
Suppose you have N = 40 adults (20 randomised to treatment, 20 to control) measured on an outcome at four time points (0, 1, 2, 3). You want to know whether the treatment group improves faster over time.
Model specification: You allow each person to have their own starting point (random intercept) and their own rate of improvement (random slope for time). The fixed effects are time (0–3, raw), condition (treatment vs. control), and the time × condition interaction, which tests whether the groups improve at different rates.
Estimation: We fit the model with REML to estimate the fixed effects and random effects, and then refit with maximum likelihood to compare models.
Written up in APA 7:
We fit a linear mixed model predicting improvement from time (0–3, raw), condition (treatment = 1, control = 0), and their interaction, with observations nested within 40 participants. The model was estimated using Python's statsmodels MixedLM with restricted maximum likelihood (REML). Each participant received a random intercept and a random slope for time. Fixed effects indicated that the control group's baseline (intercept) was b = 25.17, SE = 0.55, 95% CI [24.09, 26.25], z = 45.56, p < .001. The treatment group started higher by b = 3.65, SE = 0.78, 95% CI [2.12, 5.18], z = 4.67, p < .001. Over the four time points, scores increased by b = 1.93 per unit, SE = 0.31, 95% CI [1.32, 2.53], z = 6.26, p < .001, and the treatment group increased an additional b = 1.10 per unit per time point, SE = 0.44, 95% CI [0.24, 1.95], z = 2.52, p = .012. Random intercepts had SD = 1.74; random slopes for time had SD = 1.01; the intercept–slope correlation was .22. The intra-class correlation from the null model was .38, indicating 38% of variance was between persons. Conditional R² was .84 (fixed and random effects), compared to .56 for the marginal R² (fixed only), computed using Nakagawa & Schielzeth (2013) with Johnson's (2014) extension. Adding random slopes improved fit over a model with random intercepts only, χ²(2) = 19.14, p < .001 (note: the naive p is conservative because the tested variance is on the boundary).
The APA 7 table for fixed effects
Mixed models usually present fixed effects in a table:
| Effect | b | SE | 95% CI | z | p |
|---|---|---|---|---|---|
| Intercept | 25.17 | 0.55 | [24.09, 26.25] | 45.56 | < .001 |
| Time | 1.93 | 0.31 | [1.32, 2.53] | 6.26 | < .001 |
| Condition (treatment) | 3.65 | 0.78 | [2.12, 5.18] | 4.67 | < .001 |
| Time × Condition | 1.10 | 0.44 | [0.24, 1.95] | 2.52 | .012 |
Note. N = 40 participants, 160 observations. Estimation method: REML. Wald z statistics from statsmodels. ICC = .38; R² marginal = .56, R² conditional = .84.
The random effects block
After the fixed effects table, report the random structure (from the full model):
Random Effects
| Level | Effect | SD |
|---|---|---|
| Participant (n = 40) | Intercept | 1.74 |
| Participant (n = 40) | Time | 1.01 |
| Residual | 2.09 |
Note. Intercept–Time correlation = .22.
Reporting model comparisons
When you test whether adding random slopes improves the model, use a likelihood-ratio test with ML estimates:
Model comparison: To determine whether allowing slopes for time to vary randomly by participant improved fit, we compared a model with random intercepts only (−2LL = 802.10, AIC = 814.10, BIC = 832.55) to one with random intercepts and slopes (−2LL = 782.96, AIC = 798.96, BIC = 823.56). The likelihood-ratio test was significant, χ²(2) = 19.14, p < .001, indicating that the random-slope model fits better. (Here, df = 2 because we added two variance parameters: the slope variance and the intercept–slope covariance. Note: this test involves variance on the boundary of the parameter space, so the naive p value is conservative; a 50:50 mixture of χ²(1) and χ²(2) is often used as a correction, but p remains < .001 either way.)
Where to find these numbers in SPSS MIXED
SPSS's MIXED procedure shows these tables:
- Estimates of Fixed Effects: b, SE, t (with Satterthwaite df shown in a column), Sig., and 95% CI bounds.
- Estimates of Covariance Parameters: variances and covariances of random effects (report as SDs by taking the square root).
- Information Criteria: appears near the top of the output after Model Dimension, showing AIC, BIC, and −2 log-likelihood.
SPSS does not compute ICC or R² directly; you must calculate them by hand using the formulas shown below.
Where to find these numbers in R (lme4 + lmerTest)
library(lme4)
library(lmerTest)
model <- lmer(outcome ~ time + condition + time:condition + (1 + time | participant_id),
data = df, REML = TRUE)
summary(model)
confint(model) # for 95% CIs on fixed effectsOutput:
- Fixed effects: shown in the first table. lmerTest adds t values and p values with Satterthwaite degrees of freedom.
- Confidence intervals: use
confint()to get 95% CIs for fixed effects. - Random effects: the "Random effects" block shows Std. Dev. (SDs, which is what you want) and Corr.
- ICC: fit the intercept-only (null) model and run
performance::icc(null_model)on it; on the full model it gives a different quantity. - R²: use
performance::r2(model)for both marginal and conditional (computed using Nakagawa & Schielzeth). - Model comparison: fit two models and use
anova(m1, m2)oranova(m1, m2, refit = TRUE); lme4 automatically refits to ML.
Computing ICC and R² by hand
Intra-class correlation (ICC) from the null model (only a random intercept, no fixed effects):
ICC = τ² / (τ² + σ²)
where τ² is the random-intercept variance from the null model and σ² is the residual variance from the null model. In the null model: τ² = 10.41 and σ² = 16.66, so ICC = 10.41 / (10.41 + 16.66) = .38.
R² marginal and conditional (Nakagawa & Schielzeth with Johnson's extension for random slopes):
The random-effects variance with random slopes is:
random-effects variance = τ₀₀ + 2·τ₀₁·E[t] + τ₁₁·E[t²]
where τ₀₀ is the random-intercept variance, τ₁₁ is the random-slope variance, τ₀₁ is their covariance, and E[·] is the expectation over the observed time values.
Then:
marginal R² = fixed-effects variance / (fixed-effects variance + random-effects variance + residual variance) conditional R² = (fixed-effects variance + random-effects variance) / (the same total)
where the fixed-effects variance is the sample variance (n − 1, as R's var() computes it) of the fixed-effects predictions Xb, and the residual variance is the model's residual variance. With the population variance (n) instead, the marginal R² here would be .55.
In the example: τ₀₀ = 3.034, τ₁₁ = 1.022, τ₀₁ = 0.382, E[t] = 1.50, E[t²] = 3.50. So the random-effects variance = 3.034 + 2(0.382)(1.50) + 1.022(3.50) = 7.757. With a fixed-effects variance of 15.155 and a residual variance of 4.386, the total is 27.298. Thus the marginal R² = 15.155 / 27.298 = .56 and the conditional R² = (15.155 + 7.757) / 27.298 = .84.
Mistakes reviewers catch
- Reporting raw variance instead of standard deviation for random effects. Random effects are reported as SD (√variance), not as variance.
- Using the null model's random-effects variances in the R² or write-up. All random effects should come from the full model you estimated, not the null model. Use the null model only for ICC.
- Ignoring the random-slope model check. If you allow random slopes, say whether adding them improves fit. Use a likelihood-ratio test.
- Singular fit. If the optimiser reports a singular fit (usually a warning), the data do not support the random structure you specified. Simplify the model (remove random slopes, reduce their complexity, or fix their correlations to zero) or collect more data. Do not report a singular fit as a valid result.
- Forgetting the ICC. ICC quantifies within-group dependence and is essential for readers to understand your design.
- Wrong R² method. Nakagawa & Schielzeth R² is designed for mixed models. The Johnson (2014) extension is needed when random slopes are present. Cite both papers.
- Mixing tests from different software. If you used SPSS, report t (not z); if you used statsmodels, report z; if you used R's lme4+lmerTest, report t with Satterthwaite df. Say which.
Before you report: did the model's assumptions hold?
Mixed models assume linear relationships, normally distributed residuals at both the group and individual levels, and homoscedasticity (equal variance across the predictor range). Plot the residuals against fitted values and against predictors to check for patterns. Plot a Q-Q plot to check normality. For a large sample, minor departures from normality are usually harmless. Singular fits (in the variance-covariance matrix of random effects) indicate the model is over-specified for your data; simplify and refit.
Let KyroStat do the write-up for you
Building a linear mixed model, fitting random intercepts and slopes, checking singular fits, computing ICC and R² via Nakagawa & Schielzeth with Johnson's extension, and running a likelihood-ratio test with proper boundary correction are places errors creep in. KyroStat recognises repeated measures or grouped data, fits the model automatically, checks assumptions, and hands you the finished APA 7 sentences, coefficient tables, the random effects block, model comparisons, and the underlying Python or R code. Upload your spreadsheet, and the report is done in seconds.
Also useful for the write-up (affiliate links): Proofreading for your thesis or paper (20% off with code PAP20): Paperpal
Frequently asked questions
Should I use REML or ML? Use REML for the final model and hypothesis tests on fixed effects (the default in lme4 and statsmodels). Use ML only when comparing models with different fixed-effects structures via likelihood-ratio test.
What if the random slopes make the model singular?
A singular fit usually means your data do not have enough within-group variation to estimate that random effect. Try: (1) removing the random slope; (2) allowing a random intercept and a random slope but fixing their correlation to zero using (1 + time || id) in R; or (3) collecting more data. Do not report a singular fit.
Do I report variance or standard deviation? Standard deviation for random effects. Report the square root of the variance printed by the software.
How do I report intercept–slope correlation? As a decimal r, not as a percentage. In the example, r = .22.
What is the intra-class correlation and why report it? ICC is the proportion of variance at the group level, computed from the null model. If ICC = .38, then 38% of variation is between persons and 62% is within persons (across time points). It tells readers how strongly observations are clustered within groups.
Why do I need both marginal and conditional R²? Marginal R² shows what fixed effects alone explain; conditional R² adds the random structure. Together, they let readers see how much of the model's explanatory power comes from grouping differences (the gap between them).
Which related guides might I need? Often these: how to report a repeated-measures ANOVA (simpler, when all participants have the same number of time points), how to report a mixed ANOVA (if you have both between and within factors but no missing data), how to report hierarchical regression (when predictors are entered in blocks; it is not a multilevel model), and how to interpret repeated-measures ANOVA output from SPSS for the SPSS mechanics.