Introduction to mixed-effects models
An advanced guide introducing mixed-effects models for clustered, repeated-measures and hierarchical data, including random intercepts, random slopes, interpretation and common mistakes.
Structure
Problem, intuition, method, working, limitations and discussion.
Best for
Students preparing for coursework, analysis, interpretation or revision.
Use with
Learning Hub lessons, tutoring sessions or dissertation planning.
Resource guide
Problem
Many datasets have observations that are not fully independent. Students may analyse repeated measurements from the same person, patients within hospitals, students within schools or samples within batches as if every row were unrelated. Standard regression assumes independent observations, so ignoring clustering can produce misleading standard errors, confidence intervals and p-values. Mixed-effects models are designed for data with hierarchical or repeated structure.
- Repeated measurements are treated as independent observations.
- Patients within the same hospital may be more similar to each other.
- Students within the same school may share teaching environment effects.
- Batch effects can create similarity among biological samples.
- Standard regression can underestimate uncertainty when clustering is ignored.
- Students confuse fixed effects and random effects.
- Random intercepts and random slopes are often used without interpretation.
Resource guide
Intuition
Mixed-effects models allow the analysis to include both overall population-level effects and group-specific variation. Fixed effects describe average associations across the whole dataset. Random effects describe how clusters, subjects or groups vary around that average. A random intercept allows each group to have its own baseline level. A random slope allows the effect of a predictor to vary across groups.
- Fixed effects estimate average relationships.
- Random effects account for clustering or repeated measurements.
- A random intercept allows groups to start at different baseline levels.
- A random slope allows the predictor effect to differ between groups.
- Mixed models use partial pooling, borrowing information across groups.
- They are useful for longitudinal, multilevel and hierarchical data.
Resource guide
Method
A mixed-effects modelling workflow starts by identifying the unit of observation and the clustering structure. The analyst should decide which effects are fixed and which grouping factors require random effects. A simple random-intercept model is often the starting point. More complex random-slope structures should be justified by the design, research question and available data.
- Step 1: Identify what one row represents.
- Step 2: Identify the higher-level grouping structure.
- Step 3: Decide whether observations within groups may be correlated.
- Step 4: Define the outcome and fixed-effect predictors.
- Step 5: Start with a random intercept for the grouping variable if appropriate.
- Step 6: Consider random slopes only when the predictor effect may vary by group.
- Step 7: Compare models using theory, diagnostics and fit measures where suitable.
- Step 8: Interpret fixed effects as population-average conditional estimates within the model structure.
- Step 9: Interpret random effects as variation between groups.
- Step 10: Report the model structure clearly.
Resource guide
Working
Suppose a study measures blood pressure repeatedly for each patient over four visits. A standard linear regression would treat all rows as independent, even though measurements from the same patient are likely related. A mixed-effects model can include a random intercept for patient, allowing each patient to have their own baseline blood pressure while estimating the average effect of time or treatment across patients.
- Level 1: repeated visits.
- Level 2: patients.
- Outcome: blood pressure at each visit.
- Fixed effect: average effect of time or treatment.
- Random intercept: each patient has a different baseline level.
- Random slope: each patient may have a different rate of change over time.
- Ignoring patient clustering may underestimate standard errors.
- The model separates within-patient and between-patient information more appropriately.
Resource guide
Limitations
Mixed-effects models are powerful but not automatic solutions. They require enough data within and across groups to estimate variation reliably. Complex random-effects structures can fail to converge or produce unstable estimates. Interpretation can also be difficult, especially when non-linear outcomes, interactions or random slopes are included.
- Small numbers of groups can make random effects unstable.
- Too few observations per group can limit random slope estimation.
- Overly complex models may fail to converge.
- Random effects should match the study design and research question.
- Missing data assumptions still matter.
- Mixed models do not automatically solve confounding.
- Interpretation becomes harder with interactions and non-linear links.
Resource guide
Discussion
A strong report should explain why a mixed-effects model was needed. It should describe the clustering structure, the fixed effects, the random effects and the interpretation of key estimates. Students should avoid simply saying that a mixed model was used without explaining what was mixed about the model.
- State the hierarchical or repeated-measures structure.
- Explain why ordinary regression may be inappropriate.
- Describe fixed effects clearly.
- Describe random effects clearly.
- Report the grouping variable used for random effects.
- Interpret the main fixed effects in context.
- Discuss limitations such as sample size, convergence or missing data.
Practical checklist
Before you apply this topic
- Have you identified the unit of observation?
- Have you identified clustering or repeated measurements?
- Have you defined the outcome?
- Have you defined fixed-effect predictors?
- Have you justified the random-effects structure?
- Have you considered a random intercept?
- Have you justified any random slopes?
- Have you checked whether the model converged?
- Have you interpreted fixed effects correctly?
- Have you described random effects clearly?
- Have you considered missing data and confounding?
- Have you reported the model structure transparently?
Common mistakes
What to avoid
- Using ordinary regression for repeated-measures data.
- Ignoring clustering within hospitals, schools or subjects.
- Adding random effects without understanding why.
- Confusing fixed effects with random effects.
- Using random slopes without enough data.
- Reporting mixed-model output without describing the model structure.
- Assuming mixed models automatically prove causation.
- Ignoring convergence warnings.
- Overfitting complex random-effects structures.
- Forgetting that missing data assumptions still matter.
How this connects to learning
Use the guide as a bridge between theory and application.
A resource guide should not replace a full course or live teaching session. Instead, it helps you organise your thinking. Use it to identify what you understand, what feels unclear, and what questions you should ask before applying a method to real data.
Before a lesson
Read the intuition and problem sections to prepare.
During analysis
Use the method and checklist to guide decisions.
When writing
Use limitations and discussion to improve interpretation.
Related guides
