Linear mixed models (LMMs)—also called mixed-effects models, multilevel models, or hierarchical linear models—extend ordinary linear regression to analyze continuous outcomes when observations are grouped into clusters, measured repeatedly over time, or structured across nested levels. In biostatistics, psychology, education, ecology, organizational research, economics, and industrial testing, standard regression assumes that every observation has independent errors and shares the exact same baseline and slope parameters. In practice, patients are tracked across clinic visits, students learn inside classrooms nested within schools, employees belong to teams or divisions, and sensors record repeated readings across units. Linear mixed models handle this reality by combining fixed effects—population-average parameters shared across the dataset—with random effects—group-, subject-, or cluster-specific deviations—alongside flexible error covariance structures.
Why Ordinary Least Squares Breaks Down on Grouped or Repeated Data
Fitting standard ordinary least squares (OLS) regression to clustered or longitudinal data creates two major problems:
- Invalid Standard Errors and False Positives: Observations from the same subject, household, school, or site tend to resemble one another more than observations from different clusters. Treating correlated rows as independent ignores within-cluster similarity, causing OLS standard errors to be underestimated, t- and F-statistics to be inflated, and Type I error rates to rise above nominal levels.
- Ignoring Between-Group Differences in Trajectories: A single global regression line forces every individual or group to share the same intercept and slope. When subjects start at different baselines or respond at different rates over time or across conditions, pooling everything into one flat equation obscures genuine heterogeneity and can distort group comparisons.
Linear mixed models solve both problems directly by modeling group-level variation explicitly while estimating valid uncertainty across hierarchical levels.
Mathematical Formulation: Fixed Effects, Random Effects, and Error Structure
For an n×1 continuous outcome vector y, a standard linear mixed model writes:
y=Xβ+Zu+ε
where:
- XβX\betaXβ is the fixed-effects component: X is an n×p design matrix of observed predictors (such as treatment group, time, age, or covariates), and β is the p×1 vector of population-level fixed parameters.
- ZuZuZu is the random-effects component: Z is an n×q design matrix linking observations to grouping factors (such as subject ID or school ID), and u∼N(0,G) is a q×1 vector of unobservable random effects with covariance matrix G.
- ε∼N(0,R)\varepsilon \sim \mathcal{N}(0, R)ε∼N(0,R) is the n×1 residual error vector with covariance matrix R, which defaults to σ2In (independent homoscedastic errors) but can also model serial autocorrelation over time or unequal variance across groups/time points.
Random Intercepts and Random Slopes
In longitudinal or clustered data for observation j in cluster i, a common specification is a random-intercept and random-slope model:
yij=β0+β1tij+u0i+u1itij+εij,(u0iu1i)∼N((00),G)
Here:
- β0\beta_0β0 and β1\beta_1β1 capture the average baseline and average slope across the population.
- u0iu_{0i}u0i is subject/cluster i’s random intercept (how much subject i’s baseline shifts from the population average).
- u1iu_{1i}u1i is subject/cluster i’s random slope (how much subject i’s rate of change over tij differs from the average slope), with off-diagonal elements of G capturing covariance between baseline and slope.
Under this model, the marginal covariance of y is V=ZGZ′+R, which automatically builds within-cluster correlation and heterogeneous variance across time or predictors into likelihood estimation.
ML vs. REML Estimation and Related Frameworks
Estimating variance components in G and R alongside fixed effects β commonly uses two likelihood approaches:
- Maximum Likelihood (ML): Maximizes the joint marginal log-likelihood of β and variance parameters simultaneously. Because ML does not account for degrees of freedom lost in estimating fixed effects β, variance component estimates tend to be downwardly biased—especially when sample size is modest or fixed-effect count p is relatively large. However, ML is useful when comparing models that differ in fixed effects via likelihood-ratio tests.
- Restricted Maximum Likelihood (REML): Maximizes the likelihood of linear combinations (error contrasts) orthogonal to the fixed effects X, removing degrees-of-freedom bias in variance component estimates. REML is widely preferred for estimating variance components and comparing nested random-effects structures (with identical fixed effects), though comparing models with different fixed effects using REML requires caution and typically uses ML or appropriate information criteria/tests.
| Method / Framework | Primary Outcome Type | How Grouping / Dependence Is Handled | Key Strength & Trade-Off |
|---|---|---|---|
| Ordinary Least Squares (OLS) | Continuous | Assumes independent errors (or post-hoc cluster-robust SEs) | Simple & fast; ignores random effects & group trajectories unless explicitly modeled |
| Linear Mixed Model (LMM) | Continuous Gaussian | Fixed effects + random effects (u∼N(0,G)) + error covariance R | Models hierarchical/repeated continuous data, shrinkage, & variance components; assumes Gaussian errors |
| Generalized Linear Mixed Model (GLMM) | Non-normal (binary, counts, proportions) | Fixed + random effects inside a nonlinear link function g(μc) | Handles non-Gaussian outcomes & links; requires numerical/approximate integration |
| Fixed-Effects Panel Regression | Continuous (panel data) | Group-specific fixed intercepts (within transformation) | Controls time-invariant observed/unobserved group confounders; absorbs time-invariant covariates |
Diagnostics, Degrees of Freedom, and Practical Best Practices
A reliable LMM analysis goes beyond looking only at fixed-effect p-values:
- Inspect Variance Components and Shrinkage: Check estimated variances in G and R, intraclass correlation (ICC) (which summarizes what share of total variance lies between clusters rather than within clusters), and BLUPs / empirical Bayes estimates of random effects. Near-zero variance estimates or boundary/singular fits often signal an overly complex random-effects structure for the available data.
- Use Appropriate Degrees of Freedom for Inference: In finite samples, denominator degrees of freedom for fixed-effect t and F tests in mixed models are not always obvious; methods such as Kenward–Roger or Satterthwaite approximations provide more reliable small-sample inference than naive asymptotic approximations.
- Check Residual and Random-Effects Assumptions: Inspect conditional residuals (y−Xβ^−Zu^) and marginal residuals (y−Xβ^) for nonlinearity, heteroscedasticity, serial correlation, or influential clusters, and verify that random effects do not show severe non-normality or outliers that distort estimates.
- Build Structure Deliberately: Start with clear fixed effects and a sensible baseline random-effects structure (such as a random intercept per cluster/subject), add random slopes or serial residual structures only when supported by design and model comparison, and present both population-average trends and individual/group variability clearly.
Conclusion
Linear mixed models provide a flexible, statistically sound framework for analyzing continuous outcomes across clustered, nested, and longitudinal designs. By pairing population-level fixed effects with subject- or group-level random effects and structured error covariances, LMMs account for within-cluster dependence, capture heterogeneous trajectories, and support accurate inference across complex applied datasets.