Multilevel Modeling for Psychology and the Social Sciences: Models, Graphs, and PracticeHsiu-Ting Yu 游琇婷 Hsiu-Ting Yu游琇婷
中文
AppendixB

Likelihood, REML, and Empirical Bayes Derivations

In this appendixthe marginal likelihood and its score equations; GLS and the profile likelihood; REML from error contrasts and from the integrated likelihood; information and standard errors of variance components; algorithms in brief; empirical Bayes prediction, BLUP, and Henderson's mixed-model equations; the likelihood of generalized linear mixed models, the Laplace approximation, adaptive quadrature, and PQL; likelihood-ratio tests on the boundary.

about 25 min read4,164 words2 figures1 table

Chapters 9, 11, 12, and 23 state results whose derivations would interrupt them. This appendix gives those derivations for the linear mixed model with , , and marginal covariance , in the notation of Appendix A, and extends them to generalized linear mixed models. Symbols without the subscript refer to all clusters together: and stack the and , and is block diagonal with blocks (Appendix A, Section A.5); is the total number of observations and the number of fixed effects. Most results are checked numerically in the text with the random-intercept model for mathematics achievement and homework in the 23-school NELS:88 subsample (Kreft & de Leeuw, 1998), and the approximations for binary outcomes with the Bangladesh contraception data of Chapter 23 (Huq & Cleland, 1990); the algorithms of Section B.5 and the boundary tests of Section B.8 are illustrated numerically in Chapters 9 and 11, respectively.

B.1The Marginal Likelihood and Its Score Equations#

Let collect the variance components, the distinct elements of and . Because the clusters are independent and , the log-likelihood is the sum of multivariate normal log-densities (Appendix A, Section A.8):

It is called the marginal likelihood because the random effects have been integrated out: , and for normal distributions this integral is the normal density with covariance . Differentiating with the rules of Appendix A (Section A.9) gives the score equations. For the fixed effects,

and for each variance component , with and residual ,

For the random intercept, is for and for . Equation (B.3) equates an observed quadratic form with its expectation when is known: the ML estimates are the values at which the residuals are, in this weighted sense, as variable as the model says they should be. For the NELS:88 model, the analytic log-likelihood (B.1) reproduces the lme4 value to within , and all four scores vanish at the lme4 ML estimates (, ) to within .

B.2GLS and the Profile Likelihood#

For fixed , Equation (B.2) is linear in and is solved by the GLS estimator (Appendix A, Section A.7). Substituting it into Equation (B.1) gives the profile log-likelihood , which depends on the variance components only; maximizing over and then computing gives the ML estimates of all parameters. Software reduces the problem further. lme4 parameterizes in terms of the relative covariance factor (Appendix A, Section A.4) and profiles out as well, so that the optimizer searches only over the elements of (Bates et al., 2015).

Profiling also yields likelihood-based intervals. For a single parameter, the profile likelihood of that parameter maximizes over all others, and the values within of the maximum form a 95% likelihood-ratio interval. Figure B.1 shows the profile log-likelihood and the profile restricted log-likelihood (Section B.3) of the school standard deviation . The ML curve peaks at and gives the interval [3.23, 6.46], which agrees with the profile interval computed by lme4 ([3.23, 6.46]); the REML curve peaks at 4.62 and gives [3.31, 6.68]. Both intervals are asymmetric around the estimate, as the skewed shape of the likelihood implies, which is why profile intervals are preferred to symmetric Wald intervals for variance components (profile intervals: Chapter 10; the failure of Wald inference for variances: Chapter 11).

Figure B.1 Profile Log-Likelihood and Profile Restricted Log-Likelihood of the School Standard Deviation
Figure B.1: Profile Log-Likelihood and Profile Restricted Log-Likelihood of the School Standard Deviation

Note. NELS:88 subsample, random-intercept model for mathematics with homework. Curves: maximized log-likelihood (dashed, ML) and restricted log-likelihood (solid, REML) as functions of , each relative to its maximum, with (and, for ML, the fixed effects) maximized out. Vertical lines: the ML (dashed) and REML (solid) estimates. Dotted horizontal line: , the cutoff for 95% likelihood-ratio intervals.

B.3Restricted Maximum Likelihood#

The ML estimator of a variance is biased downward because it ignores the degrees of freedom used to estimate the fixed effects; in ordinary regression, ML divides the residual sum of squares by and REML by (Chapter 9). REML has two equivalent derivations (Harville, 1974; Patterson & Thompson, 1971).

Error contrasts. Choose an matrix of full column rank with . The transformed data do not depend on , and REML maximizes their likelihood. Two matrix identities show that the result does not depend on the choice of : for any such , , the matrix of Appendix A (Section A.7), and , so that different choices of change the log-likelihood only by the constant . For with orthonormal columns, , and therefore

where the last term does not involve and is usually dropped by software; without it, the REML criterion changes when a predictor is rescaled (Chapter 10). For the NELS:88 data, the log-likelihood of computed directly from a 519 517 orthonormal differs from the formula without the constant by 6.65, which equals , at every value of tried (to within ).

Integrated likelihood. The same function arises by integrating the likelihood over the fixed effects with a flat prior, (Harville, 1974). Because is quadratic in , , and the integral of the exponential of the second term is . The factor is the REML correction: it penalizes values of under which the fixed effects are estimated precisely, which offsets the too-small residuals that arise when is fitted to the same data. At , the quadratic form of Equation (B.3) equals , where is block diagonal with blocks , and its expectation is , not . The REML score equations use this trace, so they equate the quadratic form with its expectation after has been estimated. REML estimates of the fixed effects are the GLS estimates at . Because is the likelihood of the error contrasts , and depends on , models with different fixed effects have REML likelihoods of different data, which cannot be compared (Chapters 9 and 10).

B.4Information and Standard Errors of Variance Components#

The expected information matrix of the linear mixed model is block diagonal: the ML estimators of the fixed effects and of the variance components are asymptotically independent. The block for is , whose inverse is the GLS covariance matrix, and the block for the variance components has elements

For the NELS:88 model at the ML estimates, the inverse of Equation (B.5) gives standard errors of 7.06 for and 4.52 for . The delta method (Appendix A, Section A.9) converts them into 0.79 for and, for the residual intraclass correlation , into a standard error of 0.062. Under REML, the elements of Equation (B.5) become , and many programs use the observed information, the negative Hessian, often computed numerically, in place of the expected information; the two agree in large samples. Large here means many clusters: the asymptotic results for the cluster-level parameters rest on a growing number of clusters , and more observations per cluster do not substitute for more clusters. Wald intervals built from these standard errors assume a normal, symmetric sampling distribution; with 23 schools, the profile interval of Section B.2 is more trustworthy.

B.5Algorithms in Brief#

Newton–Raphson iterates with the score and the Hessian of the log-likelihood; Fisher scoring replaces by the expected information (B.5), which is easier to compute and positive definite whenever the variance components are identified, whereas need not be positive definite far from the maximum; Fisher scoring is therefore often more stable in early iterations. Goldstein’s iterative generalized least squares alternates GLS for with a GLS regression of the squared and cross-product residuals on the design of (Goldstein, 1986). The EM algorithm treats the random effects as missing data (Dempster et al., 1977; Laird & Ware, 1982): the E-step computes and at the current parameters (Section B.6), and the M-step updates to the average of , to the average expected squared level-1 residual, and by least squares applied to (Chapter 9) or, in a common variant, by GLS. EM never decreases the likelihood but converges slowly near the maximum, and Lindstrom & Bates (1988) concluded that a well-implemented Newton–Raphson algorithm is preferable in most situations. lme4 minimizes the profiled deviance over the elements of with derivative-free bounded optimizers, using sparse Cholesky factorizations (Bates et al., 2015); Chapter 9 runs Newton–Raphson, Fisher scoring, and EM on the NELS:88 empty model (Table 9.3) and discusses estimation problems and their remedies.

B.6Empirical Bayes Prediction, BLUP, and Henderson’s Equations#

The posterior of the random effects. Treating as a prior and as the likelihood, Bayes’ theorem gives a normal posterior, because the exponent of the product of the two densities is quadratic in . Collecting the quadratic and linear terms,

By the Woodbury identity (Appendix A, Section A.5), the mean equals and the variance equals , the conditional-normal results of Appendix A (Section A.8). Replacing and by estimates gives the empirical Bayes predictions of Chapter 12. For the random intercept, the posterior mean is the shrinkage estimator with .

BLUP and the mixed-model equations. Without the normality assumption, the posterior mean with replaced by its GLS estimate, , is the best linear unbiased predictor (BLUP) when is known: among linear functions of whose prediction errors have mean zero for every , it minimizes the mean squared prediction error (Henderson, 1975; Robinson, 1991). With estimated , it is the empirical BLUP (Chapter 12). Henderson obtained the estimates of and the predictions of jointly by maximizing the joint density of and , which is equivalent to minimizing the penalized sum of squares with and . Setting the derivatives to zero gives the mixed-model equations

Solving the second block for and substituting into the first gives by the Woodbury identity (Appendix A, Section A.5), so is the GLS estimator, and is the posterior mean (B.6) evaluated at . Multiplied by , the penalty is, for a random intercept, , the ridge penalty of Chapter 32 with penalty parameter . The inverse of the coefficient matrix in Equation (B.7) contains the covariance matrix of in its upper-left block and, in its lower-right block, the prediction error variances , which, unlike the posterior variances of Equation (B.6), include the uncertainty of .

For the NELS:88 model with the REML variance components, the solution of Equation (B.7) equals the lme4 fixed effects, their covariance matrix, and the predicted school effects to within . For the smallest school (), the posterior standard deviation reported by lme4 is 2.92 and the prediction error standard deviation is 2.99; for the largest school (), they are 1.01 and 1.47. For a random intercept, the uncertainty of adds to the posterior variance, and this addition tends to be largest for the schools whose own data determine their effect most precisely, because their predictions are shrunken least.

B.7Generalized Linear Mixed Models: Laplace, Quadrature, and PQL#

For a GLMM, the conditional distribution of given is, for example, Bernoulli, binomial, or Poisson, and the marginal likelihood of cluster ,

has no closed form. Three approximations are in common use (Chapter 23).

Laplace approximation. Expand to second order around its maximum , the conditional mode: with at . The remaining integral is a normal integral, so that, with the dimension of ,

The approximation is exact when the integrand is proportional to a normal density and deteriorates when it is skewed, as it is with few binary observations per cluster; its asymptotic bias is larger for binary and ordinal than for count responses and decreases as the cluster size grows (Joe, 2008).

Adaptive Gauss–Hermite quadrature. Quadrature replaces the integral by a weighted sum over nodes. Nonadaptive quadrature uses the same nodes for every cluster, such as the fixed grid of mirt (Chapter 30), and needs many of them. Adaptive quadrature centers the nodes at and scales them by , so that they fall where the integrand has its mass; with a single node it reduces to the Laplace approximation, and the error decreases rapidly as grows (Pinheiro & Bates, 1995; Rabe-Hesketh et al., 2002). The number of function evaluations grows as with the dimension of , and glmer offers quadrature only for models with a single scalar random-effects term.

Penalized quasi-likelihood. PQL linearizes the model around the current predictions and fits a linear mixed model to a working response, iterating to convergence (Breslow & Clayton, 1993). It is fast and extends to complex random-effects structures, but with binary outcomes, small clusters, and a large variance, it underestimates variance components and attenuates the fixed effects on the logit scale toward zero, as Rodríguez & Goldman (1995) showed for the closely related MQL and Rodríguez & Goldman (2001) for PQL, and as the simulation of Chapter 23 confirms.

Example. Figure B.2 shows for district 41 of the contraception data (26 women, 13 of them using contraception), the district whose likelihood contribution the Laplace approximation reproduces least well. Even here the two curves cannot be told apart, so the figure shows how the approximation works, not how it fails: the Laplace error for this district is 0.3% (median over districts 0.2%), and five adaptive quadrature nodes reduce it below in relative terms. Table B.1 compares the approximations for the whole model. The Laplace exceeds the 25-node quadrature value by 0.27, almost all of it approximation error rather than a difference in fit (likelihoods from different approximations should therefore not be compared; Chapters 23 and 24), and the district standard deviation moves from 0.474 to 0.477; three nodes come within 0.02 of the converged , and from seven nodes on nothing changes at the precision shown. PQL gives a smaller standard deviation (0.464) and a smaller urban coefficient (0.681 against 0.692), in the direction of its known bias. With districts of median size 26 and a small variance, as here, the Laplace approximation is adequate. With five binary items per person, it underestimated the person standard deviation of a simulated Rasch model by about 5% (Chapter 30), and with clusters of two, it underestimated the variance by 26% to 33% for true variances from 0.5 to 5 (Chapter 23).

Table B.1 Estimates of a Random-Intercept Logistic Model Under Three Approximations to the Likelihood
Approximation Urban SE (urban) Children
Laplace 0.693 0.121 0.860 0.474 2,373.19
AGQ, 3 nodes 0.692 0.121 0.861 0.477 2,372.93
AGQ, 7 nodes 0.692 0.121 0.861 0.477 2,372.92
AGQ, 15 nodes 0.692 0.121 0.861 0.477 2,372.92
AGQ, 25 nodes 0.692 0.121 0.861 0.477 2,372.92
PQL 0.681 0.119 0.845 0.464 –

Note. Bangladesh contraception data (Chapter 23): 1,934 women in 60 districts; model with age, age squared, having children, and urban residence, and a random district intercept. Urban and children: logit coefficients; : standard deviation of the district intercepts. Laplace and AGQ: glmer with nAGQ = 1 and the stated number of adaptive Gauss–Hermite nodes; PQL: MASS::glmmPQL with the dispersion fixed at 1, which has no likelihood (–).

Figure B.2 The Integrand of One District’s Likelihood Contribution and Its Laplace Approximation
Figure B.2: The Integrand of One District’s Likelihood Contribution and Its Laplace Approximation

Note. Thick light line: , the integrand of Equation (B.8) divided by its maximum, for one district, evaluated at the Laplace estimates of the fixed effects and the district variance; thin dashed line: the normal curve of the Laplace approximation, with the same mode and curvature. Circles: the five nodes of adaptive Gauss–Hermite quadrature.

B.8Likelihood-Ratio Tests on the Boundary#

The usual chi-square distribution of the likelihood-ratio statistic rests on a quadratic approximation of the log-likelihood around a true value in the interior of the parameter space. When the null hypothesis sets a variance to zero, the true value is on the boundary, and the estimator is constrained to be nonnegative. In large samples, the unconstrained estimate is approximately normal around zero; with probability one half it is negative, the constrained estimate is zero, and the likelihood-ratio statistic is zero; with probability one half it is positive, and the statistic is the square of an approximately standard normal variable. This heuristic, which assumes a single parameter on the boundary with all others in the interior, gives the 50:50 mixture of and (Self & Liang, 1987; Stram & Lee, 1994). Testing a random slope that is correlated with the intercept, whose variance and covariance with the intercept both vanish under the null hypothesis, leads instead to the 50:50 mixture of and ; critical values and further cases are given in Appendix A (Section A.12) and applied in Chapter 11. The asymptotic argument again rests on the number of clusters; in finite samples the mixture tends to be conservative, and a parametric bootstrap of the likelihood-ratio statistic, or, for a model with a single variance component, its exact null distribution (Crainiceanu & Ruppert, 2004), is safer (Chapter 11).

Further Reading#

Harville (1977); Searle et al. (1992)

ML and REML estimation of variance components.

Robinson (1991)

BLUP, Henderson’s equations, and their many interpretations.

Pinheiro & Bates (1995); Rabe-Hesketh et al. (2002)

The Laplace approximation and adaptive quadrature.

Verbeke & Molenberghs (2000)

The linear mixed model for longitudinal data, with derivations.

References

Bates, D., Mächler, M., Bolker, B., & Walker, S. (2015). Fitting linear mixed-effects models using lme4. Journal of Statistical Software, 67(1), 1–48. https://doi.org/10.18637/jss.v067.i01
Breslow, N. E., & Clayton, D. G. (1993). Approximate inference in generalized linear mixed models. Journal of the American Statistical Association, 88(421), 9–25. https://doi.org/10.1080/01621459.1993.10594284
Crainiceanu, C. M., & Ruppert, D. (2004). Likelihood ratio tests in linear mixed models with one variance component. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 66(1), 165–185. https://doi.org/10.1111/j.1467-9868.2004.00438.x
Dempster, A. P., Laird, N. M., & Rubin, D. B. (1977). Maximum likelihood from incomplete data via the EM algorithm. Journal of the Royal Statistical Society: Series B (Methodological), 39(1), 1–22. https://doi.org/10.1111/j.2517-6161.1977.tb01600.x
Goldstein, H. (1986). Multilevel mixed linear model analysis using iterative generalized least squares. Biometrika, 73(1), 43–56. https://doi.org/10.1093/biomet/73.1.43
Harville, D. A. (1974). Bayesian inference for variance components using only error contrasts. Biometrika, 61(2), 383–385. https://doi.org/10.1093/biomet/61.2.383
Harville, D. A. (1977). Maximum likelihood approaches to variance component estimation and to related problems. Journal of the American Statistical Association, 72(358), 320–338. https://doi.org/10.1080/01621459.1977.10480998
Henderson, C. R. (1975). Best linear unbiased estimation and prediction under a selection model. Biometrics, 31(2), 423–447. https://doi.org/10.2307/2529430
Huq, N. M., & Cleland, J. (1990). Bangladesh fertility survey 1989 (main report). National Institute of Population Research; Training.
Joe, H. (2008). Accuracy of Laplace approximation for discrete response mixed models. Computational Statistics & Data Analysis, 52(12), 5066–5074. https://doi.org/10.1016/j.csda.2008.05.002
Kreft, I. G. G., & de Leeuw, J. (1998). Introducing multilevel modeling. Sage. https://doi.org/10.4135/9781849209366
Laird, N. M., & Ware, J. H. (1982). Random-effects models for longitudinal data. Biometrics, 38(4), 963–974. https://doi.org/10.2307/2529876
Lindstrom, M. J., & Bates, D. M. (1988). Newton–Raphson and EM algorithms for linear mixed-effects models for repeated-measures data. Journal of the American Statistical Association, 83(404), 1014–1022. https://doi.org/10.1080/01621459.1988.10478693
Patterson, H. D., & Thompson, R. (1971). Recovery of inter-block information when block sizes are unequal. Biometrika, 58(3), 545–554. https://doi.org/10.1093/biomet/58.3.545
Pinheiro, J. C., & Bates, D. M. (1995). Approximations to the log-likelihood function in the nonlinear mixed-effects model. Journal of Computational and Graphical Statistics, 4(1), 12–35. https://doi.org/10.1080/10618600.1995.10474663
Rabe-Hesketh, S., Skrondal, A., & Pickles, A. (2002). Reliable estimation of generalized linear mixed models using adaptive quadrature. The Stata Journal, 2(1), 1–21. https://doi.org/10.1177/1536867X0200200101
Robinson, G. K. (1991). That BLUP is a good thing: The estimation of random effects. Statistical Science, 6(1), 15–32. https://doi.org/10.1214/ss/1177011926
Rodríguez, G., & Goldman, N. (1995). An assessment of estimation procedures for multilevel models with binary responses. Journal of the Royal Statistical Society: Series A (Statistics in Society), 158(1), 73–89. https://doi.org/10.2307/2983404
Rodríguez, G., & Goldman, N. (2001). Improved estimation procedures for multilevel models with binary response: A case-study. Journal of the Royal Statistical Society: Series A (Statistics in Society), 164(2), 339–355. https://doi.org/10.1111/1467-985X.00206
Searle, S. R., Casella, G., & McCulloch, C. E. (1992). Variance components. Wiley. https://doi.org/10.1002/9780470316856
Self, S. G., & Liang, K.-Y. (1987). Asymptotic properties of maximum likelihood estimators and likelihood ratio tests under nonstandard conditions. Journal of the American Statistical Association, 82(398), 605–610. https://doi.org/10.1080/01621459.1987.10478472
Stram, D. O., & Lee, J. W. (1994). Variance components testing in the longitudinal mixed effects model. Biometrics, 50(4), 1171–1177. https://doi.org/10.2307/2533455
Verbeke, G., & Molenberghs, G. (2000). Linear mixed models for longitudinal data. Springer. https://doi.org/10.1007/978-1-4419-0300-6
Cite this bookYu, H.-T. (2026). Multilevel modeling for psychology and the social sciences: Models, graphs, and practice (Web ed.). Appendix B.