Algorithm Search⌘K

Modelcore

Linear mixed model

Also called mixed-effects model, random effects model, hierarchical linear model.

A linear model y = X b + Z u + e with fixed effects b and random effects u. It models grouped or repeated measures with correlated errors.

A linear mixed model, or mixed-effects model, is a linear regression in which part of the coefficients are fixed unknown numbers and part are random variables with mean 0. In matrix form y=Xb+Zu+ey = Xb + Zu + e, where bb is the vector of fixed effects (on this page the coefficient vector is written bb), u∼N(0,G)u \sim N(0, G) is the vector of random effects and e∼N(0,R)e \sim N(0, R) is the error. The random effects make the observations of the same group, subject or plot correlated, so the model fits clustered data, repeated measures and longitudinal studies, split plots, and genetic evaluation of animals. Given the covariance parameters, bb is estimated by generalized least squares and uu is predicted by BLUP, both from Henderson's mixed model equations. The covariance parameters themselves are usually estimated by restricted maximum likelihood.

The machine

Data. A response y∈Rny \in \mathbb R^n, a fixed-effects design XX (n×pn \times p, rank pp, usually with an intercept column) and a random-effects design ZZ (n×qn \times q).

Model.

y=Xb+Zu+e,u∼Nq(0,G(θ)),e∼Nn(0,R(θ)),u and e independent.y = Xb + Zu + e, \qquad u \sim N_q(0, G(\theta)), \qquad e \sim N_n(0, R(\theta)), \qquad u \text{ and } e \text{ independent}.

The matrices GG and RR depend on a short vector θ\theta of covariance parameters. The commonest choice is R=σe2IR = \sigma_e^2 I, and GG block diagonal with one block for each random factor.

The marginal law. Since yy is a linear function of the independent normal vectors uu and ee,

y∼Nn(Xb,V(θ)),V=ZGZ⊤+R.y \sim N_n(Xb, V(\theta)), \qquad V = ZGZ^\top + R.

All inference on bb and θ\theta uses this law; uu is not a parameter and is predicted, not estimated.

Parameter space. b∈Rpb \in \mathbb R^p, and θ\theta in the set where G(θ)G(\theta) is positive semidefinite and R(θ)R(\theta) is positive definite. A variance component equal to 0 is allowed, and it is a boundary point of this set.

Common layouts.

  • Random intercepts (one-way). Groups i=1,…,ai = 1, \dots, a with nin_i observations, yij=b0+ui+eijy_{ij} = b_0 + u_i + e_{ij}, ui∼N(0,σu2)u_i \sim N(0, \sigma_u^2), eij∼N(0,σe2)e_{ij} \sim N(0, \sigma_e^2). Here ZZ is the n×an \times a matrix of group indicators and G=σu2IaG = \sigma_u^2 I_a.
  • Random intercepts and slopes (Laird and Ware 1982). For subject ii, yi=Xib+Ziui+eiy_i = X_ib + Z_iu_i + e_i with ui∼N(0,D)u_i \sim N(0, D) and ei∼N(0,σe2I)e_i \sim N(0, \sigma_e^2 I); for a straight line in time, ZiZ_i has columns 1\mathbf 1 and the times, and DD is a 2×22 \times 2 covariance matrix.
  • Nested and crossed factors. Pupils in classes in schools give nested blocks of GG; subjects crossed with test items give two random factors whose indicators overlap, and VV has no block diagonal form.
  • Known relationships. In animal breeding G=σa2AG = \sigma_a^2\mathcal A, where A\mathcal A is the matrix of additive relationships computed from the pedigree.

What it counts

  • The fixed effects bb. In a linear mixed model E[y]=XbE[y] = Xb, so bb is both the effect within a group and the effect averaged over the population. (In a mixed model with a nonlinear link these two differ.)
  • The variance components θ\theta, for example σu2\sigma_u^2 and σe2\sigma_e^2, and functions of them such as the intraclass correlation ρ=σu2/(σu2+σe2)\rho = \sigma_u^2/(\sigma_u^2 + \sigma_e^2).
  • The predicted random effects u~=GZ⊤V−1(y−Xb^)\tilde u = GZ^\top V^{-1}(y - X\hat b), the best linear unbiased predictor, and predictions such as x0⊤b^+z0⊤u~x_0^\top\hat b + z_0^\top\tilde u for a known group. In the one-way layout, u~i=niσu2niσu2+σe2(yˉi⋅−b^0)\tilde u_i = \frac{n_i\sigma_u^2}{n_i\sigma_u^2 + \sigma_e^2}(\bar y_{i\cdot} - \hat b_0): the group mean is pulled toward the overall mean, more for small groups.
  • Standard errors from Cov⁡(b^)=(X⊤V−1X)−1\operatorname{Cov}(\hat b) = (X^\top V^{-1}X)^{-1} and from the prediction error variance of u~\tilde u, both at the true θ\theta; plugging in θ^\hat\theta makes them too small in small samples.

Relation to other models

  • Ordinary least squares is the case G=0G = 0, R=σ2IR = \sigma^2 I.
  • Generalized least squares is the case of a known VV. The mixed model gives VV a structure with few parameters, so that it can be estimated.
  • Fixed group effects. Treating the uiu_i as fixed (one indicator column for each group) is the limit σu2→∞\sigma_u^2 \to \infty of the mixed model; then u~i\tilde u_i becomes the plain group mean minus the overall mean, and the model cannot estimate effects of variables that are constant within groups.
  • Ridge regression. With G=σu2IG = \sigma_u^2 I and R=σe2IR = \sigma_e^2 I, the BLUP of uu is the ridge estimate with penalty σe2/σu2\sigma_e^2/\sigma_u^2, as Henderson's equations show. Penalized splines and smoothing splines can be written as mixed models in the same way, so REML chooses their smoothing parameter.
  • Bayesian models. With a flat prior on bb and θ\theta known, the posterior mean of uu is the BLUP. Putting a prior on θ\theta as well gives a hierarchical Bayesian model; plugging in an estimate θ^\hat\theta is empirical Bayes.
  • Kriging and Gaussian processes. A spatial process with a parametric covariance is a mixed model with Z=IZ = I; the kriging predictor is the BLUP, and universal kriging estimates the mean by GLS.
  • Marginal models. Generalized estimating equations and cluster-robust standard errors target bb only and do not need the normal law or a model for GG; they give no predictions of group effects.
  • One-way ANOVA with a random factor is the balanced one-way layout below.
  • Survival data. A random effect inside a hazard model is a frailty model. Non-normal responses with random effects in a generalized linear model need numerical integration or a Laplace approximation for the likelihood.

Known results in the model

1. Within-group correlation (proved here). In the one-way layout, Var⁡(yij)=σu2+σe2\operatorname{Var}(y_{ij}) = \sigma_u^2 + \sigma_e^2, Cov⁡(yij,yik)=σu2\operatorname{Cov}(y_{ij}, y_{ik}) = \sigma_u^2 for j≠kj \ne k, and observations in different groups are independent. Proof. Cov⁡(b0+ui+eij,b0+ui′+ei′k)=Cov⁡(ui,ui′)+Cov⁡(eij,ei′k)\operatorname{Cov}(b_0 + u_i + e_{ij}, b_0 + u_{i'} + e_{i'k}) = \operatorname{Cov}(u_i, u_{i'}) + \operatorname{Cov}(e_{ij}, e_{i'k}) by independence of uu and ee; the first term is σu2\sigma_u^2 when i=i′i = i' and 0 otherwise, the second is σe2\sigma_e^2 when (i,j)=(i′,k)(i, j) = (i', k) and 0 otherwise. □\square So each block of VV has the compound symmetry form σe2I+σu211⊤\sigma_e^2 I + \sigma_u^2\mathbf 1\mathbf 1^\top, and the correlation of two observations in one group is ρ\rho. A test or interval that treats the nn observations as independent uses the wrong variance: the variance of a group mean is σu2+σe2/ni\sigma_u^2 + \sigma_e^2/n_i, and the σu2\sigma_u^2 part does not shrink with nin_i.

2. Estimation and prediction for known θ\theta. The GLS estimate b^=(X⊤V−1X)−1X⊤V−1y\hat b = (X^\top V^{-1}X)^{-1}X^\top V^{-1}y is the maximum likelihood estimate of bb and the best linear unbiased estimator (Aitken). The predictor u~=GZ⊤V−1(y−Xb^)\tilde u = GZ^\top V^{-1}(y - X\hat b) has the smallest mean squared error among linear predictors u~=Ly\tilde u = Ly with E[Ly−u]=0E[Ly - u] = 0 for all bb (Henderson 1975). Both come from one linear system; the proofs are on the mixed model equations page.

3. The balanced one-way layout (proved here). Let ni=mn_i = m for all aa groups and N=amN = am. Let SSA=m∑i(yˉi⋅−yˉ⋅⋅)2\mathrm{SSA} = m\sum_i(\bar y_{i\cdot} - \bar y_{\cdot\cdot})^2 with a−1a - 1 degrees of freedom and SSE=∑i,j(yij−yˉi⋅)2\mathrm{SSE} = \sum_{i,j}(y_{ij} - \bar y_{i\cdot})^2 with a(m−1)a(m - 1), and MSA\mathrm{MSA}, MSE\mathrm{MSE} the mean squares. Then SSA/(σe2+mσu2)∼χa−12\mathrm{SSA}/(\sigma_e^2 + m\sigma_u^2) \sim \chi^2_{a-1} and SSE/σe2∼χa(m−1)2\mathrm{SSE}/\sigma_e^2 \sim \chi^2_{a(m-1)}, and they are independent.

Proof. Write yij=b0+ui+eijy_{ij} = b_0 + u_i + e_{ij}. The within deviations yij−yˉi⋅=eij−eˉi⋅y_{ij} - \bar y_{i\cdot} = e_{ij} - \bar e_{i\cdot} do not involve uu, and for each ii the vector (eij−eˉi⋅)j(e_{ij} - \bar e_{i\cdot})_j is independent of eˉi⋅\bar e_{i\cdot} (the sample mean and the deviations of a normal sample are independent), so SSE/σe2=∑i∑j(eij−eˉi⋅)2/σe2\mathrm{SSE}/\sigma_e^2 = \sum_i\sum_j(e_{ij} - \bar e_{i\cdot})^2/\sigma_e^2 is a sum of aa independent χm−12\chi^2_{m-1} variables. The group means yˉi⋅=b0+ui+eˉi⋅\bar y_{i\cdot} = b_0 + u_i + \bar e_{i\cdot} are functions of uu and the eˉi⋅\bar e_{i\cdot} only, hence independent of SSE\mathrm{SSE}, and they are iid N(b0,σu2+σe2/m)N(b_0, \sigma_u^2 + \sigma_e^2/m). So ∑i(yˉi⋅−yˉ⋅⋅)2/(σu2+σe2/m)∼χa−12\sum_i(\bar y_{i\cdot} - \bar y_{\cdot\cdot})^2/(\sigma_u^2 + \sigma_e^2/m) \sim \chi^2_{a-1}, which is the claim for SSA\mathrm{SSA}. □\square

So E[MSA]=σe2+mσu2E[\mathrm{MSA}] = \sigma_e^2 + m\sigma_u^2 and E[MSE]=σe2E[\mathrm{MSE}] = \sigma_e^2, and the ANOVA estimator σ^u2=(MSA−MSE)/m\hat\sigma_u^2 = (\mathrm{MSA} - \mathrm{MSE})/m is unbiased. It is negative exactly when MSA<MSE\mathrm{MSA} < \mathrm{MSE}. With γ=σu2/σe2\gamma = \sigma_u^2/\sigma_e^2, the ratio F=MSA/(1+mγ)MSEF = \frac{\mathrm{MSA}/(1 + m\gamma)}{\mathrm{MSE}} has the Fa−1,a(m−1)F_{a-1, a(m-1)} law, so

P(σ^u2<0)=P(Fa−1,a(m−1)<11+mγ).P(\hat\sigma_u^2 < 0) = P\Bigl(F_{a-1, a(m-1)} < \frac{1}{1 + m\gamma}\Bigr).

For γ=0\gamma = 0 and m=4m = 4 this is 0.595, 0.562, 0.539 and 0.521 for a=3,5,10,30a = 3, 5, 10, 30. For a=5a = 5 and γ=1\gamma = 1 it is 0.066. W. A. Thompson (1962) and Searle, Casella and McCulloch discuss what to do with a negative estimate; REML and ML both return 0 instead, as the REML page shows.

4. Testing a variance component on the boundary. The null σu2=0\sigma_u^2 = 0 is on the edge of the parameter space, so Wilks' theorem does not apply. When the data have many independent groups, the likelihood ratio statistic Λ\Lambda for one variance component has the limit law 12χ02+12χ12\frac12\chi^2_0 + \frac12\chi^2_1 under the null (Chernoff 1954; Self and Liang 1987): Λ=0\Lambda = 0 with probability 12\frac12, as when the estimate falls on the boundary, and otherwise χ12\chi^2_1. The right p-value is half the χ12\chi^2_1 tail, P=12P(χ12≥Λ)P = \frac12P(\chi^2_1 \ge \Lambda) for Λ>0\Lambda > 0, and the 5% cut is 2.706 instead of 3.841. For a random slope added to a random intercept, the limit is 12χ12+12χ22\frac12\chi^2_1 + \frac12\chi^2_2 (Stram and Lee 1994). The χ12\chi^2_1 test is conservative. In the balanced example y=(10,12,14; 15,16,17; 18,20,22)y = (10, 12, 14;\ 15, 16, 17;\ 18, 20, 22) with a=m=3a = m = 3, the REML fits give Λ=6.920\Lambda = 6.920, so the χ12\chi^2_1 p-value is 0.0085 and the mixture p-value is 0.0043.

The mixture is a large-sample result in the number of groups. In the balanced layout the restricted likelihood ratio is 0 exactly when MSA≤MSE\mathrm{MSA} \le \mathrm{MSE}, so by Result 3 its mass at 0 under the null is P(Fa−1,a(m−1)≤1)P(F_{a-1, a(m-1)} \le 1), the γ=0\gamma = 0 values above. This tends to 12\frac12 only as a→∞a \to \infty; with aa fixed and m→∞m \to \infty it tends to P(χa−12≤a−1)P(\chi^2_{a-1} \le a - 1), which is 1−e−1=0.6321 - e^{-1} = 0.632 for a=3a = 3. Crainiceanu and Ruppert (2004) give the exact finite sample law for one variance component and show cases where the mass at 0 is far above 12\frac12. A parametric bootstrap under the null fit is a safe check.

5. Tests of fixed effects. Wald and FF tests for bb use (X⊤V^−1X)−1(X^\top\hat V^{-1}X)^{-1}, which ignores the error in θ^\hat\theta. The Kenward-Roger (1997) correction adjusts this covariance and the degrees of freedom of the FF reference law. Likelihood ratio tests of fixed effects use maximum likelihood fits, not REML fits.

References

  1. Nan M. Laird and James H. Ware, Random-effects models for longitudinal data, Biometrics 38(4), 1982, pp. 963 to 974, The whole paper (the two-stage model y_i = X_i b + Z_i u_i + e_i for repeated measures, and its fit by EM with ML and REML)
  2. C. R. Henderson, Best linear unbiased estimation and prediction under a selection model, Biometrics 31(2), 1975, pp. 423 to 447, The mixed model equations and the BLUE and BLUP they give
  3. G. K. Robinson, That BLUP is a good thing: the estimation of random effects, Statistical Science 6(1), 1991, pp. 15 to 32, The whole paper (derivations of BLUP, its links to Bayes, kriging and smoothing, and the one-way example)
  4. David A. Harville, Maximum likelihood approaches to variance component estimation and to related problems, Journal of the American Statistical Association 72(358), 1977, pp. 320 to 338, The whole paper (ML and REML for the mixed model, their properties and algorithms)
  5. Steven G. Self and Kung-Yee Liang, Asymptotic properties of maximum likelihood estimators and likelihood ratio tests under nonstandard conditions, Journal of the American Statistical Association 82(398), 1987, pp. 605 to 610, The mixture of chi-squared laws for a parameter on the boundary, case 5 (one variance component)
  6. Daniel O. Stram and Jae Won Lee, Variance components testing in the longitudinal mixed effects model, Biometrics 50(4), 1994, pp. 1171 to 1177, The whole paper (the mixtures for tests of random intercepts and random slopes)
  7. Ciprian M. Crainiceanu and David Ruppert, Likelihood ratio tests in linear mixed models with one variance component, Journal of the Royal Statistical Society Series B 66(1), 2004, pp. 165 to 185, The whole paper (the exact finite sample null law of the LR and restricted LR statistics, and when the 50:50 mixture fails)
  8. Michael G. Kenward and James H. Roger, Small sample inference for fixed effects from restricted maximum likelihood, Biometrics 53(3), 1997, pp. 983 to 997, The whole paper (the adjusted covariance and the F approximation for tests of fixed effects)
  9. Shayle R. Searle, George Casella and Charles E. McCulloch, Variance Components, Wiley, 1992, Chapter 3 (the balanced one-way classification, ANOVA estimators and their distributions) and Chapter 7 (prediction of random variables, BLUP)
  10. José C. Pinheiro and Douglas M. Bates, Mixed-Effects Models in S and S-PLUS, Springer, 2000, Chapters 1 and 2 (the model, ML and REML, tests of variance components on the boundary)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/RBPBWM/text.yaml