A linear mixed model (LMM) is a statistical model in which a response is expressed as a linear combination of fixed effects, random effects, and residual error. Fixed effects describe systematic relationships represented by common population parameters; random effects describe variation among sampled units, groups, or other sources of heterogeneity. By combining these components, an LMM extends linear regression to observations that are dependent because they share a school, experimental block, individual, genetic background, or another source of variation.
Linear mixed models are important when the organization of the data is part of the scientific problem. Repeated measurements on one person generally contain less independent information than measurements on different people, and pupils in the same school may resemble one another even after measured characteristics are considered. An LMM represents such dependence explicitly rather than treating every observation as an independent replicate. It can estimate population-level relationships, quantify sources of variation, and predict group-specific departures from the population mean.
The standard Gaussian formulation combines a linear mean structure with normally distributed random effects and errors. Its theory connects covariance modeling, likelihood estimation, and prediction through a common matrix framework. Applications range from agricultural experiments and animal breeding to longitudinal studies, education, industrial measurement, and genetic association analysis.
Mathematical formulation and interpretation
The general model is
where is an -dimensional vector of observations, is an fixed-effects design matrix, is a vector of unknown fixed coefficients, is an random-effects design matrix, and is a vector of random coefficients. The residual vector represents variation not accounted for by the fixed and random terms. Both design matrices may contain continuous predictors, indicator variables, interactions, or prespecified basis functions.
In the Gaussian model,
with and independent. Here and are covariance matrices, usually expressed through a relatively small vector of unknown parameters . A nonzero average for a random coefficient is ordinarily represented through a corresponding fixed effect, leaving the random deviation centered at zero.
There are two complementary views of this formulation. Conditional on the random effects,
After integrating out , the marginal distribution is
These statements use the multivariate normal distribution. The conditional mean describes units with particular random-effect values; the marginal mean describes the population represented by the model. Because the model uses an identity link and the random effects have mean zero, the fixed coefficients retain the same linear mean interpretation after marginalization.
“Fixed” and “random” describe modeling roles, not whether an observed variable was literally randomized or whether its values change over time. A treatment effect may be fixed even when treatment assignment was randomized. A school effect may be random when schools are treated as exchangeable realizations from a modeled population. Treating school as fixed instead estimates separate school coefficients without imposing a common distribution on them. The appropriate representation depends on the target of inference and the assumptions about those units.
The word “linear” refers to linearity in the coefficients, not necessarily in the observed predictors. A model containing age and age squared remains linear in its coefficients. So does a model using a fixed set of spline basis functions. Conversely, a response curve containing an unknown parameter inside an exponential function is generally nonlinear even if it also contains random effects.
The covariance assumptions are substantive. Independence of and , zero conditional mean for the random effects given modeled predictors, and the form of and determine what the fitted coefficients mean. A mixed model does not automatically remove confounding merely by adding a random intercept.
Random intercepts, random slopes, and dependence structures
The simplest grouped model has a random intercept:
where indexes groups and indexes observations within a group. Suppose are independent with variance , while residuals are independent with variance . Then every observation has marginal variance , and two different observations in the same group have covariance . Observations in different groups have zero covariance under these assumptions.
The resulting intraclass correlation is
It measures the proportion of marginal variance associated with between-group differences in this particular model. For equally sized groups of size , the variance inflation of the overall mean relative to independent observations with the same marginal variance is . Thus, when and , the inflation factor is . This calculation concerns the mean under a balanced random-intercept structure; it is not a universal adjustment for every regression coefficient.
A random-slope model allows trajectories or associations to vary:
with
The covariance between two observations in group , apart from residual covariance, is
Unlike a random-intercept model, this structure permits dependence and marginal variance to change with time. The intercept–slope covariance describes whether units with higher values at the reference time tend to have steeper or flatter trajectories. Changing the time origin changes the random-intercept variance and intercept–slope covariance, although an equivalent reparameterization leaves fitted response distributions unchanged.
Grouping structures need not be strictly hierarchical. Pupils can be nested within classrooms and classrooms within schools, producing several levels of random intercepts. In a crossed design, each participant may respond to several items while each item is observed for several participants. Participant and item effects then define separate, overlapping sources of dependence. Treating crossed items as if they were nested can impose an incorrect covariance structure and distort uncertainty estimates.
Residual dependence can also remain after random effects are included. An autoregressive residual structure may represent correlation that decays with measurement lag, while group-specific residual variances represent unequal measurement variability. Random slopes and serial residual correlation are not interchangeable: the former describe persistent differences in trajectories, whereas the latter describe dependence among deviations around those trajectories. Their separation requires sufficiently informative observation schedules.
Estimation by maximum likelihood and restricted likelihood
When is known and has full column rank, the fixed-effects estimator is the generalized least-squares estimator:
Its covariance is . This generalizes ordinary least squares by weighting observations according to both their variances and their dependence. In practice, is unknown, so estimating covariance parameters is a central part of fitting the model.
Under Gaussian assumptions, maximum likelihood estimation maximizes the marginal likelihood obtained after integrating out the random effects. Up to an additive constant, the log likelihood is
For any candidate , the maximizing has the generalized least-squares form. Substituting it produces a profile likelihood in the covariance parameters alone. The determinant term penalizes excessive covariance volume, while the quadratic term measures lack of fit relative to the proposed covariance.
Ordinary maximum likelihood does not explicitly account for the loss of information caused by estimating fixed effects. In the elementary model with independent normal errors and estimated regression coefficients, the maximum-likelihood residual variance divides the residual sum of squares by , rather than . The corresponding downward bias can be important in small samples and motivates restricted maximum likelihood (REML).
For full-rank , a restricted log likelihood can be written, up to terms independent of , as
where
One interpretation is that REML constructs a likelihood from error contrasts that eliminate the fixed mean. The extra determinant term accounts for estimating that mean. REML reproduces the familiar residual degrees-of-freedom correction in the simplest normal linear model, although it does not guarantee unbiased estimates for every variance component in every design.
The distinction affects model comparison. Restricted likelihoods based on different fixed-effect spaces generally are not directly comparable, because they concern different sets of contrasts. Likelihood-ratio comparisons of different fixed-effect structures ordinarily use maximum likelihood. REML can be used to compare covariance structures when the fixed-effect design is unchanged, subject to the appropriate reference distribution for the comparison.
Covariance parameters must remain in a permissible parameter space. Variances cannot be negative, and covariance matrices must be positive semidefinite. An estimate of zero for a variance component can therefore be a legitimate boundary maximum rather than a numerical error. With sparse or weakly informative data, estimates can lie on this boundary even when the corresponding population variance is positive.
Prediction, shrinkage, and partial pooling
Estimating a population coefficient and predicting an individual random effect are distinct tasks. In the frequentist formulation, is an unknown fixed parameter, whereas is an unobserved realization of a random variable. With known covariance parameters, the best linear unbiased predictor (BLUP) of is
“Best” means that it minimizes prediction-error variance within the relevant class of linear unbiased predictors; it does not mean optimal under every possible loss or distributional assumption.
For a random-intercept model containing only a common mean, the prediction for group has the form
The factor lies between zero and one. Small groups, groups with noisy observations, or groups drawn from a population with little between-group variation are pulled more strongly toward the common mean. For example, with , , and five observations in a group, , approximately . With twenty observations, it is approximately .
This mechanism is called shrinkage or partial pooling. Complete pooling assigns every group the same mean, while an unpooled analysis estimates every group independently. An LMM occupies an intermediate position, with the amount of pooling determined by the estimated variance structure and the information available for each group. The resulting predictions are related to regularization, but their shrinkage strengths arise from an explicit probability model rather than from an arbitrary penalty alone.
Under Gaussian assumptions and known ,
and
Thus, the same expression is also a conditional mean under the Gaussian model. When and covariance parameters are estimated, uncertainty about them must be distinguished from this conditional covariance. Substituting estimated variance components produces empirical BLUPs; prediction intervals that ignore variance-component estimation can be too narrow.
Prediction also depends on whether the target belongs to an observed group. A future observation in an existing group can use that group’s predicted random effect. For a previously unobserved group, its random effect has mean zero before new data are observed, but its variance still contributes to predictive uncertainty. A prediction for a new group is therefore not equivalent to a precise prediction at the population mean.
Because shrinkage deliberately pulls estimated deviations toward zero, a group-specific BLUP need not be unbiased when that group’s realized random effect is treated as fixed. Its unbiasedness property averages over the modeled random effects and errors. This distinction matters when interpreting rankings of schools, laboratories, or breeding candidates.
Statistical inference and model comparison
Inference for fixed effects commonly begins with the estimated covariance
A contrast can then be assessed using its estimate and estimated standard error. Large-sample normal approximations yield Wald tests and confidence intervals. For several coefficients jointly, the corresponding quadratic form is often compared with a chi-squared or approximate distribution.
The main finite-sample difficulty is that is estimated. Treating it as known can understate uncertainty, especially when the number of independent groups is small. The relevant information is not simply the total number of measurements: a study with hundreds of observations from six groups may still have limited information for a treatment assigned at the group level. Different contrasts can also have different effective degrees of freedom in the same model.
The Satterthwaite approximation matches moments to obtain an approximate denominator degrees of freedom for a test statistic. The Kenward–Roger approximation additionally adjusts the estimated covariance of fixed effects and derives an approximate reference distribution. These methods can improve finite-sample performance, but neither provides an exact solution for every design. Their results depend on the specified covariance model and available information.
Likelihood-ratio tests compare nested models through twice the difference in maximized log likelihoods. Standard chi-squared reference distributions require regularity conditions that fail when a tested variance is zero under the null hypothesis. In a simple one-component setting, the asymptotic distribution may be a half-and-half mixture of a point mass at zero and a chi-squared distribution with one degree of freedom. More complex random-effect tests can have different distributions, particularly when correlations or additional covariance parameters become unidentified under the null.
A parametric bootstrap offers another route: simulate data from the fitted null model, refit the competing models, and compare the observed statistic with the simulated distribution. This approach can accommodate complicated designs, although its accuracy depends on the assumed data-generating model and enough successful simulation fits. A nonparametric bootstrap requires a resampling scheme that preserves dependence; resampling individual rows as though independent generally does not do so.
Model comparison must also match the inferential target. A criterion assessing marginal likelihood evaluates the distribution after random effects are integrated out. A criterion aimed at prediction within already observed groups addresses a different task. Similarly, cross-validation that holds out observations within groups can produce substantially different error estimates from validation that holds out entire groups. Neither answers the other’s prediction question.
Statistical significance does not itself establish practical importance or causality. An estimated variance component describes modeled heterogeneity, while a fixed-effect contrast describes an association or experimental contrast under the stated design and assumptions.
Computational methods and numerical structure
Directly forming is rarely the best way to fit a mixed model. Even when is conceptually useful, it may be a large, dense matrix. Efficient algorithms instead solve linear systems and exploit the structure of , , , and . Grouping-factor designs often make highly sparse: an observation belongs to only a few groups, so most entries are zero.
For positive-definite and , fixed-effect estimates and random-effect predictions satisfy Henderson’s mixed-model equations:
They also arise by minimizing
The second term penalizes random effects relative to their modeled covariance. This formulation connects mixed models to penalized least squares and explains why random effects are shrunk rather than fitted without restriction.
Modern implementations frequently parameterize , where has identity covariance and . This representation avoids explicitly inverting and can accommodate zero variance components. A Cholesky decomposition or a related covariance factor also enforces the covariance constraints during optimization. Sparse matrix factorizations can reduce both memory use and computational cost dramatically.
Covariance estimation requires an outer numerical optimization. Newton-type methods, quasi-Newton methods, derivative-free methods, and the expectation–maximization algorithm have all been used. EM exploits the fact that the unobserved random effects have tractable conditional moments in the Gaussian model, but it can converge slowly near an optimum. Newton-type algorithms can be faster locally, while requiring reliable curvature information and safeguards near parameter-space boundaries.
A convergence warning and a singular fit indicate different issues. A convergence warning concerns whether the numerical optimizer has adequately located a solution. A singular fit means that an estimated random-effects covariance has reduced rank, for example because a variance is zero or two random coefficients are perfectly correlated. A singular optimum can be numerically well converged. Conversely, a nonsingular estimate can still come from an inadequately converged optimization.
Predictor scaling, centering, and parameterization affect numerical stability. A model mixing extremely large and small predictor scales can yield poorly conditioned systems and inaccurate derivative calculations. Re-expressing time in years rather than seconds may improve computation without changing the underlying scientific model. Software such as SAS PROC MIXED, R’s nlme and lme4, and Stata’s mixed implements different combinations of covariance structures, optimization methods, and inferential approximations; identical model names do not guarantee identical defaults.
Design requirements, identification, and diagnostics
A mixed model cannot recover sources of variation that the design does not distinguish. With one observation per group, an independent random-intercept variance and an independent residual variance enter the marginal covariance only through their sum. They therefore cannot be separately estimated without additional structure or information. Random slopes require within-group variation in their predictor, and estimating intercept–slope covariance requires information across groups as well as within them.
The number of independent groups is especially important for variance components. Many repeated observations on a few individuals can estimate those individuals’ trajectories accurately while providing little information about the population distribution of trajectories. There is no universal minimum number of groups valid for every model. Precision depends on group sizes, predictor variation, variance magnitudes, and the complexity of the proposed random-effects covariance.
Identification also concerns the relationship between covariates and random effects. Standard random-effects regression assumes the modeled random effects have mean zero conditional on the included design variables. In econometrics, an unobserved individual intercept correlated with a time-varying predictor can make the usual random-effects estimator inconsistent. A within–between specification can separate the within-group predictor from the group mean , allowing their associations with the outcome to differ. Group fixed effects offer another approach, though they cannot separately estimate coefficients for predictors constant within each group.
Diagnostics examine the mean structure and covariance assumptions separately. Residual plots can reveal nonlinear trends, unequal spread, or systematic differences among groups. Plots against time or spatial separation can identify remaining dependence. Conditional residuals subtract both fitted fixed effects and predicted random effects; marginal residuals subtract only the fixed-effect mean. They answer different questions, and neither is generally a collection of independent errors suitable for every standard regression diagnostic without adjustment.
Quantile plots of estimated random effects require particular caution. These quantities are predictions rather than direct observations of the latent effects, and their shrinkage differs with group information. A visually narrow or irregular distribution of predictions does not translate directly into the same feature of the underlying random-effects distribution. Simulation-based checks can compare diagnostic statistics with what the fitted model would generate. Influence analysis can likewise distinguish an unusual observation from a group whose removal substantially changes a variance estimate or fixed-effect contrast.
Likelihood analysis can use incomplete and unbalanced response records without requiring identical observation schedules. Under an ignorable missing-at-random mechanism and the associated parameter-distinctness conditions, the observed-data likelihood can support valid inference when the outcome model is correctly specified. This is not a general guarantee against bias from dropout: missingness depending on unobserved outcomes may require an explicit missingness model and sensitivity analysis. Missing predictors also require separate treatment.
Design-based justification remains essential for causal inference. A random intercept can represent dependence, but it does not by itself justify exchangeability of treatment groups, resolve informative cluster size, or correct selection into the observed sample.
Historical development and major applications
Linear mixed models grew from the analysis of variance components in agriculture and genetics. Early experimental problems required separation of variation among treatments, blocks, plots, and biological units. The framework of analysis of variance, developed prominently through the work of Ronald Fisher in the early twentieth century, provided a natural language for these decompositions. Balanced designs allowed variance components to be estimated from expected mean squares, but missing observations and unequal group sizes made those calculations more difficult.
Charles Roy Henderson developed mixed-model equations around 1950 in work associated with animal breeding. His 1953 paper on estimating variance and covariance components helped establish methods for unbalanced data. The prediction problem was central: breeding programs needed estimates of genetic merit for animals observed under different environmental conditions and with different amounts of information. The resulting BLUP framework allowed population effects and individual genetic predictions to be handled together.
Restricted maximum likelihood was developed by H. Desmond Patterson and Robin Thompson in 1971 through work on interblock information in designed experiments. David Harville’s 1977 treatment helped clarify likelihood-based variance-component estimation and its broader statistical foundations. In 1982, Nan Laird and James Ware presented a random-effects approach to longitudinal data that became especially influential in biostatistics. These developments connected earlier variance-component methods with general likelihood analysis and repeated-measures modeling.
In agriculture, mixed models represent blocks, locations, years, and genotype-by-environment variation. In animal breeding, random genetic effects can have a covariance proportional to a pedigree-based relationship matrix. This goes beyond independent group effects: related animals have correlated breeding values. Comparable constructions use genomic relationship matrices to represent genetic similarity among sampled individuals.
Longitudinal applications distinguish variation within individuals from variation between them. A study measuring a continuous outcome repeatedly can include a fixed mean trajectory, random individual intercepts and slopes, and residual serial correlation. Unequal observation times are represented directly through the design matrices and covariance functions rather than by forcing every participant into a balanced table.
In education, pupils may be nested within classes and schools, with school-level variation separated from pupil-level residual variation. In psychology and language research, crossed participant and item effects account for repeated responses to shared stimuli. Industrial and laboratory applications partition variability among production batches, instruments, operators, specimens, and repeated measurements, supporting studies of reproducibility and measurement uncertainty.
These applications differ in the interpretation of random effects. A school effect represents contextual heterogeneity, an animal’s breeding value represents a correlated genetic component, and an instrument effect represents systematic variation across measurement devices. The shared mathematical structure does not make those substantive assumptions interchangeable.
Relationships to other statistical models
A linear mixed model is one important form of a multilevel model, but the terms are not exact synonyms. Multilevel modeling also includes non-Gaussian outcomes, nonlinear relationships, and more elaborate hierarchical structures. Conversely, an LMM can contain crossed or spatially correlated random effects that are not naturally described by a simple sequence of nested levels. “Mixed” refers to the coexistence of fixed and random components; “multilevel” emphasizes organization across levels.
A generalized linear mixed model extends the framework to outcomes such as binary responses or counts by combining random effects with a generalized linear model. Its conditional mean typically satisfies
for a link function . Unlike the Gaussian identity-link model, integration over random effects generally does not preserve the same functional form for the marginal mean. Marginal likelihoods also usually lack a closed-form expression, requiring numerical integration or approximation. The analytic tractability of the LMM is therefore a distinctive feature, not a property of every mixed model.
A linear mixed model is also different from a finite mixture model. A Gaussian mixture model represents a population as a weighted collection of latent components, often with component-specific means and covariances. In an LMM, Gaussian random coefficients generate continuous heterogeneity and dependence through an additive structure. Mixture models can themselves contain mixed-model components, but that is an additional modeling construction.
The covariance view links LMMs to Gaussian processes. If a random-effect vector produces covariance , it induces a finite-rank Gaussian process over the observed inputs. More general Gaussian-process covariance functions need not have a small finite-dimensional random-effects representation. Spatial models, smoothing models, and repeated-measures models can nevertheless often be understood through the same decomposition of a mean function and a covariance function.
Penalized splines provide another connection. A smooth curve can be expanded in basis functions, with selected coefficients treated as random effects. The ratio of residual variance to random-coefficient variance controls smoothness, linking variance-component estimation to the choice of a smoothing penalty. Ridge regression has a related Gaussian random-coefficient interpretation when coefficient penalties correspond to a common normal variance.
Under Bayesian inference, prior distributions are assigned to fixed coefficients and covariance parameters as well as to the latent effects. Conditional on known hyperparameters and a flat prior for fixed coefficients, Gaussian posterior calculations reproduce the familiar generalized least-squares and BLUP expressions. Integrating over uncertain covariance parameters generally produces different uncertainty summaries from simply substituting their estimates. Priors on standard deviations and correlation matrices can have substantial effects when only a few groups inform the random-effects distribution.
Some linear state-space models also admit an equivalent joint Gaussian mixed-model representation. Their sequential structure makes the Kalman filter a convenient computational method, whereas a mixed-model formulation emphasizes joint estimation and covariance decomposition. The distinction is often one of representation and computational organization rather than an absolute separation between model families.