Introduction
Longitudinal clinical studies measure the same participant repeatedly over time. A patient may have a baseline measurement followed by assessments at Week 2, Week 4, Week 8, and Week 12. These observations are informative precisely because they come from the same individual—but that also means they are not independent.
A linear mixed effects model (LMM) is one of the standard approaches for analyzing a continuous longitudinal endpoint. It separates the population-average effects of interest from subject-specific sources of variation and explicitly models the dependence among repeated observations.
The Longitudinal Data Structure
Suppose participant \(i\) is measured at times \(t=1,\ldots,m_i\). Let \(Y_{it}\) denote the continuous outcome. A typical clinical-trial dataset might look like this:
| Subject | Treatment | Visit | Time | Outcome |
|---|---|---|---|---|
| 001 | Active | Baseline | 0 | 72.4 |
| 001 | Active | Week 4 | 4 | 68.1 |
| 001 | Active | Week 8 | 8 | 63.5 |
| 002 | Placebo | Baseline | 0 | 70.2 |
| 002 | Placebo | Week 4 | 4 | 69.8 |
| 002 | Placebo | Week 8 | 8 | 69.1 |
The repeated outcomes for Subject 001 tend to resemble one another more than an outcome from a randomly selected participant. That dependence is the central statistical feature that a longitudinal mixed model must address.
Why Not Use Ordinary Linear Regression?
Ordinary linear regression assumes that, conditional on the covariates, the observations are independent. If the same patient contributes several observations, this assumption is generally false.
For example, if a study has 100 patients measured at 5 visits, there are 500 rows of data but not 500 independent experimental units. The independent units are the patients.
The Basic Linear Mixed Model
A useful general form is:
Here:
- \(Y_i\) is the vector of repeated outcomes for subject \(i\).
- \(X_i\) is the fixed-effects design matrix.
- \(\beta\) contains the fixed-effect parameters.
- \(Z_i\) is the random-effects design matrix.
- \(b_i\) contains subject-specific random effects.
- \(\varepsilon_i\) is the within-subject residual vector.
A common assumption is:
The marginal covariance of the repeated outcomes is then:
This equation is central to understanding mixed models. The covariance among observations can arise from shared random effects, from a specified residual covariance structure, or from both.
Fixed Effects vs. Random Effects
| Component | Purpose | Typical examples |
|---|---|---|
| Fixed effect | Population-level systematic effect | Treatment, visit, baseline, sex, treatment × visit |
| Random effect | Subject-specific deviation from the population pattern | Random intercept, random slope |
| Residual covariance | Remaining within-subject dependence | Compound symmetry, AR(1), unstructured |
The distinction is conceptual rather than simply a question of whether a variable is categorical or continuous. Fixed effects describe parameters of scientific interest; random effects describe a probability distribution for subject-specific deviations.
A Simple Random-Intercept Model
The simplest longitudinal mixed model gives each participant a personal baseline level:
where \(b_{0i}\) is the random intercept for subject \(i\).
The interpretation is intuitive: every subject starts from a different underlying level, but the fixed effects describe the common population pattern.
If the random intercept has variance \(\sigma_b^2\), then two observations from the same subject share the random intercept. Even if the residual errors are independent, this creates positive within-subject correlation.
Under a random-intercept model with independent residual errors, the corresponding intraclass correlation is:
A larger ICC means a greater proportion of the total variability is attributable to persistent differences between subjects.
Random Slopes: Subjects Can Change Differently
A random intercept allows participants to have different levels. A random slope additionally allows them to have different trajectories over time:
Now \(b_{1i}\) represents subject \(i\)'s deviation from the average time trend.
For example, one patient may improve rapidly, another may improve slowly, and another may deteriorate. A random-slope model allows these trajectories to vary.
The random effects are often modeled jointly:
The covariance \(\sigma_{01}\) describes whether participants with higher-than-average baseline values tend to have higher or lower-than-average slopes.
Time Should Usually Be Treated Carefully
Longitudinal time can be represented in several ways. The choice changes the scientific question being asked.
| Time representation | What it assumes | Typical use |
|---|---|---|
| Continuous numeric time | A functional relationship with time | Approximately linear trajectories |
| Categorical visit | No particular shape across visits | Clinical trials with scheduled visits |
| Polynomial terms | A smooth nonlinear trajectory | Curved time trends |
| Spline terms | Flexible nonlinear trajectory | Complex longitudinal patterns |
In many confirmatory clinical trials, visit is modeled as a categorical fixed effect because it avoids imposing a linear trajectory that may not be clinically justified.
Treatment, Visit, and Treatment-by-Visit Interaction
A common clinical-trial model contains treatment, visit, and their interaction:
The treatment-by-visit interaction is often the most important part of the model when the treatment effect is expected to change over time.
A Worked Clinical Trial Example
Consider a randomized trial comparing an active treatment with placebo. The primary continuous endpoint is measured at baseline and Weeks 4, 8, and 12. The scientific question is the difference between treatments at Week 12, adjusted for baseline.
| Design feature | Example |
|---|---|
| Population | Adults randomized 1:1 |
| Treatment | Active vs placebo |
| Outcome | Continuous clinical score |
| Post-baseline visits | Weeks 4, 8, 12 |
| Primary contrast | Active − placebo at Week 12 |
| Covariate | Baseline outcome |
A reasonable model could include baseline outcome as a covariate, categorical visit, treatment, treatment-by-visit interaction, and a subject-level random intercept.
Why Baseline Adjustment Matters
Baseline is often strongly associated with subsequent measurements. Including baseline can improve precision and account for chance baseline imbalance.
A typical post-baseline model is conceptually:
The baseline coefficient \(\beta_1\) measures the association between baseline status and post-baseline outcome, while the treatment-by-visit terms define how the treatment difference evolves across follow-up.
Covariance Structures
The covariance structure determines how repeated observations within a participant are related after accounting for the fixed and random effects. Common choices include:
| Structure | Main assumption | Strength | Limitation |
|---|---|---|---|
| Independent | No residual correlation | Simple | Often unrealistic for longitudinal data |
| Compound symmetry (CS) | Common variance and common covariance | Parsimonious | Correlation does not depend on time separation |
| AR(1) | Correlation declines with lag | Natural for equally spaced visits | Less suitable when visit spacing is irregular or correlation is not monotone |
| Unstructured (UN) | Each variance and covariance is estimated | Flexible | Many parameters |
| Toeplitz | Covariance depends on lag, without AR(1)'s geometric restriction | Flexible lag-based model | More parameters than AR(1) |
There is no universally correct covariance structure. The choice should reflect the design, measurement schedule, scientific understanding, model diagnostics, and prespecified analysis strategy.
Compound Symmetry
Under compound symmetry, all measurements have a common variance and every pair of distinct measurements has the same covariance:
This can be reasonable when measurements are exchangeable, but it may be restrictive when observations that are close in time are expected to be more strongly correlated.
Autoregressive AR(1)
For equally spaced visits, AR(1) assumes that correlation declines geometrically with the time lag:
Thus adjacent visits have correlation \(\rho\), visits two lags apart have correlation \(\rho^2\), and so on.
Unstructured Covariance
An unstructured covariance matrix estimates a separate variance for each visit and a separate covariance for each pair of visits. For four visits:
UN is highly flexible and is frequently considered in clinical-trial repeated-measures analyses when the number of scheduled visits is modest. Its price is a larger number of covariance parameters and potentially unstable estimation in smaller datasets.
Random Effects and Covariance Are Not the Same Thing
A common source of confusion is the relationship between random effects and residual covariance.
A random intercept itself induces within-subject correlation. A model can therefore contain both a random intercept and a residual covariance structure, but this should be done intentionally rather than automatically.
Conceptually:
Maximum Likelihood vs. REML
Mixed models are commonly estimated using either maximum likelihood (ML) or restricted maximum likelihood (REML).
REML accounts for the loss of degrees of freedom associated with estimating fixed effects and is often preferred for estimating variance components when comparing models with the same fixed-effects structure.
ML is generally used when comparing models that differ in their fixed effects because likelihood comparisons need to be based on a common likelihood framework for the fixed-effect specification.
Interpreting Fixed Effects
Suppose treatment is coded 1 for active and 0 for placebo and visit is categorical. The treatment coefficient at the reference visit represents the treatment difference at that reference visit. The interaction coefficients describe how that treatment difference changes at other visits.
For example, if Week 12 is represented by an indicator and the estimated treatment-by-Week-12 interaction is \(-4.2\), that coefficient contributes to the active-versus-placebo contrast at Week 12. It should not automatically be interpreted as the entire Week-12 treatment effect unless the model parameterization makes it so.
Estimated Marginal Means
Estimated marginal means (EMMs), also called least-squares means in some software, are model-based means or contrasts evaluated at specified covariate settings. They are particularly useful when a treatment-by-visit interaction is present.
For a two-arm trial, the key result may be:
| Visit | Active adjusted mean | Placebo adjusted mean | Difference | 95% CI | P-value |
|---|---|---|---|---|---|
| Week 4 | 64.8 | 67.1 | −2.3 | (−4.8, 0.2) | 0.071 |
| Week 8 | 61.2 | 66.0 | −4.8 | (−7.3, −2.3) | <0.001 |
| Week 12 | 58.5 | 65.1 | −6.6 | (−9.2, −4.0) | <0.001 |
The table is usually much more clinically interpretable than a list of raw model coefficients.
Handling Unequal Numbers of Observations
One major advantage of mixed models is that they can use participants with incomplete longitudinal records without requiring every participant to have the same number of observations.
For example, if a participant has baseline, Week 4, and Week 8 measurements but misses Week 12, the observed data can still contribute to the likelihood under the fitted model.
Missing at Random in Plain Language
MAR does not mean that missingness is unrelated to everything. It means that, after conditioning on relevant observed information, the probability of missingness does not depend on the unobserved value itself.
For example, if patients with poor observed Week 4 outcomes are more likely to miss Week 12, including Week 4 outcome in the analysis model may help make the MAR assumption more plausible.
MAR is an assumption that should be considered and supported through the study's data-collection and sensitivity-analysis strategy; it cannot be proven from the observed data alone.
Model Diagnostics
Mixed models still require assessment of whether the chosen mean and covariance structures are reasonable.
- Inspect residual distributions and identify influential observations.
- Assess whether residual variance changes over time or across treatment groups.
- Consider whether the assumed covariance structure adequately captures within-subject dependence.
- Check whether a linear time specification is plausible if time is modeled continuously.
- Examine random-effect estimates cautiously, especially when the number of subjects is small.
- Evaluate convergence warnings and boundary estimates rather than treating software output as automatically valid.
Model Convergence
A mixed model can fail to converge when the covariance structure is too complex for the available data, parameters are weakly identified, or the optimization problem is difficult.
Common warning signs include:
- Nonconvergence or optimizer failure.
- Estimated variances essentially equal to zero.
- Correlations at or extremely close to \(\pm1\).
- Very large standard errors.
- Different optimizers producing materially different solutions.
A convergence warning should never be handled simply by hiding the warning. Investigate the model, simplify the random-effects or covariance structure when scientifically justified, and document the final specification.
Random-Effects Selection
A random intercept is often a natural starting point for repeated subject-level measurements. A random slope can be valuable when subjects plausibly have different rates of change, but it introduces additional variance and covariance parameters.
Adding random effects solely because they improve an information criterion can be problematic. The random-effects structure should have a scientific rationale and should be supported by the data.
Fixed Effects vs. Random Effects: A Clinical Example
| Variable | Possible role | Reason |
|---|---|---|
| Treatment | Fixed | Specific treatment groups are of scientific interest |
| Visit | Fixed | Specific scheduled visits are of interest |
| Treatment × Visit | Fixed | Tests/estimates differential longitudinal effects |
| Subject | Random | Subjects represent a sampled population |
| Subject-specific intercept | Random | Accounts for persistent subject heterogeneity |
| Subject-specific slope | Random, if justified | Allows heterogeneous trajectories |
R Implementation with lme4
The following example uses lme4 for a random-intercept model with categorical visit and a treatment-by-visit interaction.
library(lme4) fit <- lmer( outcome ~ baseline + treatment * visit + (1 | subject), data = dat, REML = TRUE ) summary(fit)
A random-intercept and random-slope model can be specified as:
fit_rs <- lmer(
outcome ~ baseline + treatment * visit +
(1 + time | subject),
data = dat,
REML = TRUE
)
summary(fit_rs)
The syntax (1 + time | subject) allows a subject-specific intercept, a subject-specific time slope, and their covariance.
R Implementation with nlme
The nlme package is particularly useful when you want explicit control over residual correlation and variance structures.
library(nlme) fit_ar1 <- lme( outcome ~ baseline + treatment * visit, random = ~ 1 | subject, correlation = corAR1(form = ~ time | subject), data = dat, method = "REML" ) summary(fit_ar1)
For example, an unstructured random-effects covariance can be represented through the random-effects specification, while residual correlation can be specified separately. This separation is one reason nlme is useful for advanced longitudinal modeling.
SAS Implementation with PROC MIXED
In SAS, PROC MIXED is a standard procedure for linear mixed models.
proc mixed data=dat method=reml;
class subject treatment visit;
model outcome =
baseline
treatment
visit
treatment*visit
/ solution ddfm=kr;
random intercept / subject=subject;
lsmeans treatment*visit
/ diff cl;
run;
The DDFM=KR option requests the Kenward–Roger denominator degrees-of-freedom approach, which is commonly used in clinical-trial mixed-model analyses when appropriate.
SAS Residual Covariance Structures
For a residual repeated-measures covariance model, SAS can use the REPEATED statement. For example:
proc mixed data=dat method=reml;
class subject treatment visit;
model outcome =
baseline
treatment
visit
treatment*visit
/ solution ddfm=kr;
repeated visit / subject=subject type=un;
lsmeans treatment*visit
/ diff cl;
run;
For AR(1), replace TYPE=UN with TYPE=AR(1). For compound symmetry, use TYPE=CS.
Random-Effects Model vs. Repeated-Covariance Model
There are two closely related ways to formulate longitudinal mixed models.
| Approach | Typical formulation | Conceptual emphasis |
|---|---|---|
| Random-effects model | Random intercept/slope | Subject-specific trajectories |
| Repeated covariance model | Residual covariance such as UN, CS, AR(1) | Within-subject covariance directly |
| Combined model | Random effects + residual covariance | Both subject heterogeneity and residual dependence |
These formulations can produce similar marginal covariance patterns in some settings, but they are not interchangeable in every model. The correct specification depends on the scientific estimand and the assumed data-generating process.
Marginal vs. Subject-Specific Interpretation
A mixed model with random effects can support subject-specific interpretations, but many clinical-trial treatment effects are ultimately presented as population-level estimated marginal means and contrasts.
This distinction matters because a random-effects model is not automatically a statement that the clinical treatment effect should be interpreted for an individual patient. The reporting estimand should be defined independently of the software's model syntax.
Degrees of Freedom and Small-Sample Inference
Mixed models do not generally have a single obvious residual degrees of freedom like ordinary linear regression. Different approximations can be used, including residual, Satterthwaite, and Kenward–Roger methods.
For clinical-trial inference, the denominator degrees-of-freedom method should be selected deliberately and prespecified where appropriate.
Likelihood Ratio Tests and Information Criteria
Likelihood ratio tests can be useful for comparing nested covariance or random-effects models, subject to the usual boundary and estimation considerations. Information criteria such as AIC and BIC can also help compare competing specifications.
Model selection should not be driven exclusively by an automated criterion. Clinical interpretability, convergence, parameter stability, design considerations, and prespecified analysis rules matter as well.
What Is the Primary Treatment Effect?
Suppose the protocol defines the primary endpoint as the treatment difference at Week 12. Then the model should produce a direct Week-12 treatment contrast.
Conceptually, if \(\mu_{A,12}\) is the adjusted mean for active treatment at Week 12 and \(\mu_{P,12}\) is the corresponding placebo mean, the estimand is:
The corresponding estimate, confidence interval, and p-value should be reported directly. This is preferable to reporting a coefficient whose interpretation depends on the reference coding of visit.
What Does the Random Intercept Mean?
The random intercept is not simply "baseline." It represents an unobserved subject-specific deviation from the population intercept under the model. If baseline is included as an observed covariate, the random intercept remains a separate model component.
This distinction is especially important when explaining a model to programmers or clinicians: baseline is an observed measurement; a random intercept is a latent subject-specific model parameter.
What Does the Random Slope Mean?
A random slope means that the rate of change associated with time varies among subjects. If the estimated random-slope variance is large, subjects have heterogeneous trajectories around the population-average trajectory.
However, random-slope estimates should not be interpreted as directly observed individual treatment effects. They are estimated components of the hierarchical model.
Prediction vs. Inference
Mixed models can be used both to estimate population-level effects and to predict subject-specific random effects. These are different goals.
| Goal | Typical quantity | Example |
|---|---|---|
| Population inference | Fixed-effect contrast | Active − placebo at Week 12 |
| Mean trajectory | Estimated marginal mean | Adjusted mean at Week 8 |
| Subject prediction | Conditional random effect | Estimated patient's deviation from average trajectory |
Common Mistakes
- Treating repeated observations as independent. This ignores the defining feature of longitudinal data.
- Interpreting the treatment main effect as the treatment effect at every visit. With a treatment-by-visit interaction, treatment effects depend on visit.
- Using continuous time without checking the trajectory. A linear time effect can be too restrictive.
- Adding a random slope automatically. More complexity is not always better.
- Ignoring covariance structure. The within-subject covariance is central to inference.
- Ignoring convergence warnings. A numerical warning can indicate an inadequately identified model.
- Comparing fixed-effects models using REML. ML is generally used when the fixed-effects structure changes.
- Assuming mixed models eliminate missing-data bias. They provide likelihood-based inference under assumptions such as MAR; they do not make missingness irrelevant.
- Reporting only model coefficients. Clinical reports should emphasize the prespecified estimand and corresponding treatment contrast.
- Choosing a covariance structure after seeing the primary result. Covariance selection should be prespecified or handled according to a clearly defined modeling strategy.
A Practical Longitudinal Modeling Workflow
What Should Be Reported in a Statistical Analysis Plan?
A reproducible SAP section for an LMM should specify the analysis population, endpoint definition, timing of measurements, fixed-effects structure, covariance/random-effects structure, estimation method, degrees-of-freedom method, contrast of interest, and missing-data strategy.
- Outcome definition and units
- Analysis population
- Baseline adjustment
- Treatment and visit coding
- Treatment-by-visit interaction
- Random-effects specification, if used
- Residual covariance structure
- Estimation method (ML or REML)
- Denominator degrees-of-freedom method
- Primary treatment contrast and confidence interval
- Multiplicity strategy, if multiple contrasts are tested
- Handling of missing and post-baseline data
- Sensitivity analyses
- Software and version
How to Think About the Model in One Equation
The most useful mental model is:
In symbols:
This decomposition explains why mixed models are so useful: they do not force all participants to follow exactly the same trajectory, but they also do not treat each measurement as an unrelated observation.
Worked Interpretation
Suppose the fitted model estimates a Week-12 active-versus-placebo difference of \(-6.6\) units with a 95% confidence interval of \((-9.2,-4.0)\).
A clinically appropriate interpretation is:
The interpretation should be tied to the endpoint's clinical direction. A lower value is not automatically better; the meaning depends on what the outcome measures.
When Linear Mixed Models Are Appropriate
LMMs are especially useful when:
- The outcome is approximately continuous.
- The same subjects are measured repeatedly.
- The mean trajectory can be described adequately by the chosen fixed-effects structure.
- Within-subject covariance is important.
- Incomplete repeated measurements occur and a likelihood-based analysis under a defensible missing-data assumption is appropriate.
When a Different Model May Be Better
An LMM is not a universal solution.
| Outcome/data feature | Potential alternative |
|---|---|
| Binary repeated outcome | Generalized linear mixed model |
| Count outcome | Poisson or negative-binomial mixed model |
| Strongly non-Gaussian continuous outcome | Transformation or another appropriate model |
| Time-to-event endpoint | Survival analysis / mixed-effects survival methods where appropriate |
| Highly nonlinear trajectory | Nonlinear mixed model or flexible spline-based model |
| Ordinal repeated outcome | Ordinal mixed model |
The endpoint scale and scientific estimand should drive model selection.
Bottom Line
References
Laird, N.M. & Ware, J.H. (1982). Random-effects models for longitudinal data. Biometrics, 38(4), 963–974.
Verbeke, G. & Molenberghs, G. (2000). Linear Mixed Models for Longitudinal Data. Springer.
Fitzmaurice, G.M., Laird, N.M. & Ware, J.H. (2011). Applied Longitudinal Analysis. Wiley.
Pinheiro, J.C. & Bates, D.M. (2000). Mixed-Effects Models in S and S-PLUS. Springer.
West, B.T., Welch, K.B. & Galecki, A.T. (2015). Linear Mixed Models: A Step-by-Step Approach. CRC Press.
Kenward, M.G. & Roger, J.H. (1997). Small sample inference for fixed effects from restricted maximum likelihood. Biometrics, 53, 983–997.