Tutorials › Generalized Linear Mixed Models (GLMM) › ML and REML Comparisons for Random-Effect Structures

Testing Fixed and Random Effects · Tutorial 382 of 698

ML and REML Comparisons for Random-Effect Structures

Distinguish valid ML comparisons from valid REML comparisons, and check that the data, fixed-effects space, and likelihood calculation make the comparison meaningful.

Advanced 12 min read

What You'll Learn

  • Define the integrated likelihood used to compare random-effects structures in a GLMM.
  • Identify the conditions for a meaningful ML comparison.
  • Explain why exact REML comparisons require the same fixed-effects column space.
  • Use the orthonormal-contrast likelihood and its determinant form correctly.
  • Recognize why GLMM “REML” calculations may be approximation-dependent.
  • Diagnose common causes of invalid or unreliable likelihood comparisons.

Why the likelihood calculation matters

A richer random-effects structure can describe more sources of variation, but its likelihood value is comparable with that of a simpler structure only when both values refer to the same data and the same probability model conventions. The distinction between maximum likelihood (ML) and restricted maximum likelihood (REML) is especially important: ML is based on the response likelihood, whereas exact REML in a Gaussian linear mixed model is based on likelihood information in contrasts that eliminate the fixed effects.

This tutorial concerns comparability, not the reference distribution for a likelihood-ratio test. A positive difference in optimized likelihoods can be calculated only after checking that the fits are comparable; its inferential calibration is a separate question. In particular, variance-component tests may involve parameter-space boundaries, as in the earlier material on variance components and boundary tests.

Definition: Two fitted random-effects structures are ML-comparable when their maximized likelihoods are calculated for the same observed response data under the same response distribution, link, fixed-effects specification, offsets, weights, and likelihood convention. For a comparison intended to isolate random-effects structure, hold the fixed-effects design constant. The random-effects structures may differ, and for a nested comparison the smaller structure must be obtainable from the larger one by imposing parameter constraints.

ML for random-effects structures

Write a GLMM in terms of responses \(Y_i\), fixed-effects design matrix \(X\), fixed-effect vector \(\beta\), and random effects \(b\). Conditional on \(b\), the responses follow the specified exponential-family response model, with linear predictor \(X\beta+Zb\) (including any stated offset). A usual random-effects assumption is \(b\sim N(0,G_\psi)\), independent of the response sampling given \(b\). The marginal likelihood integrates out the random effects:

$$ L(\beta,\psi;y)=\int f(y\mid b;\beta)\,f(b;\psi)\,db, \qquad \ell(\beta,\psi;y)=\log L(\beta,\psi;y). $$

ML estimates \(\beta\) and the covariance parameters \(\psi\) by maximizing this marginal log likelihood. A likelihood value based only on the conditional response density evaluated at an estimated or predicted \(b\) is not this marginal likelihood. The integration may be evaluated numerically or approximated, for example by a Laplace approximation; the method used must be reported and applied consistently to both fits.

For a nested comparison, let model 0 be the smaller random-effects structure and model 1 the larger. If the fixed-effects specification and all other likelihood conventions are the same, the parameter space of model 0 is contained in that of model 1. Therefore the optimized ML log likelihoods satisfy:

$$ \widehat{\ell}_{1,\mathrm{ML}}\geq \widehat{\ell}_{0,\mathrm{ML}}, \qquad D_{\mathrm{ML}}=2\left(\widehat{\ell}_{1,\mathrm{ML}}-\widehat{\ell}_{0,\mathrm{ML}}\right)\geq 0. $$

This inequality follows because maximizing over a parameter space that includes every value allowed by the smaller model cannot produce a lower maximum. A materially negative difference is a warning to check convergence, model nesting, data alignment, and whether the two reported likelihoods use the same convention. Tiny negative differences can arise from numerical optimization error.

Worked Example: ML Comparison of a Random Intercept and Slope

Suppose hypothetical binary responses from the same 120 individuals in 30 clusters are fitted with the same fixed-effects predictors and link. Model 0 has a cluster random intercept; model 1 adds a random slope for a continuous time variable. Assume both fits use the same observations and the same Laplace-approximation settings, converge successfully, and model 0 is obtained from model 1 by setting the slope variance and its covariance with the intercept to zero.

Suppose the optimized marginal log likelihoods are \(\widehat{\ell}_{0,\mathrm{ML}}=-184.6\) and \(\widehat{\ell}_{1,\mathrm{ML}}=-181.9\). The ML likelihood-ratio statistic is

$$ D_{\mathrm{ML}} =2\left[(-181.9)-(-184.6)\right] =2(2.7) =5.4. $$

The richer model has a larger maximized likelihood, as nesting requires, and the observed improvement is 5.4 on the likelihood-ratio statistic scale. This calculation does not by itself supply a p-value: the appropriate reference law depends on the testing problem, including whether a variance is on the boundary of its allowed range. It would be invalid to make this comparison if one fit used a different set of individuals, fixed-effects predictors, or likelihood approximation.

What REML compares

Exact REML is naturally defined for the Gaussian linear mixed model \(y\sim N(X\beta,V_\theta)\), where \(V_\theta\) is the marginal covariance matrix determined by the residual and random-effects parameters \(\theta\). Let \(X\) have full column rank \(p\). Choose an \(n\times(n-p)\) matrix \(K\) whose columns are orthonormal and span the orthogonal complement of the columns of \(X\). Thus \(K'K=I\) and \(K'X=0\). The contrast vector \(K'y\) has a normal distribution with mean zero and covariance \(K'V_\theta K\). Its log likelihood is the exact restricted log likelihood:

$$ \ell_K(\theta) =-\frac{1}{2}\left[ (n-p)\log(2\pi) +\log|K'V_\theta K| +y'K(K'V_\theta K)^{-1}K'y \right]. $$

The contrast likelihood eliminates the unknown fixed effects because \(K'X\beta=0\). It depends on the fixed-effects column space, since that space determines which directions are removed, rather than on a particular scaling of its basis columns. Consequently, exact REML likelihoods for random-effects structures are comparable when the data and the fixed-effects column space are the same. Changing the fixed-effects column space changes the contrasts and hence changes the likelihood being evaluated.

For a full-column-rank \(X\), the same contrast likelihood can be written using \(P_\theta=V_\theta^{-1}-V_\theta^{-1}X(X'V_\theta^{-1}X)^{-1}X'V_\theta^{-1}\):

$$ \ell_K(\theta) =-\frac{1}{2}\left[ (n-p)\log(2\pi) +\log|V_\theta| +\log|X'V_\theta^{-1}X| -\log|X'X| +y'P_\theta y \right]. $$

The \(-\log|X'X|\) term inside the brackets is important. If the alternative determinant formula is written without it, that expression is not invariant to rescaling the columns of \(X\). The inverse and determinants involving \(X\) also require full column rank. If a design is rank deficient, use a full-rank basis for its column space or work directly with orthonormal contrasts. When the same design matrix parameterization is used in every fit, the \(\log|X'X|\) term is constant across those fits and cancels in their difference; it must not be dropped when claiming the formula is invariant to a change of parameterization.

A practical consequence is that REML likelihoods are not the appropriate basis for comparing different fixed-effects column spaces. Such comparisons alter the contrast construction. For Gaussian mixed models, use ML when fixed-effects specifications differ; for random-effects comparisons with the same fixed-effects space, REML can be used. The introductory material on ML and REML comparisons for fixed effects covers the corresponding fixed-effects comparison issue.

Worked Example: Comparing Two REML Fits With a Common Fixed-Effects Space

Consider hypothetical Gaussian measurements from 18 subjects. Both fits use the same response values and the same fixed-effects design \(X\), containing an intercept and a treatment indicator. The smaller random structure has a subject random intercept; the larger structure adds a subject-specific random slope. Assume the Gaussian mixed-model assumptions are used in both fits and both optimizations converge.

Suppose the REML log likelihoods computed from the same orthonormal contrast basis are \(-42.7\) for the smaller structure and \(-39.8\) for the larger structure. The difference is

$$ 2\left[(-39.8)-(-42.7)\right] =2(2.9) =5.8. $$

The restricted likelihood is higher for the larger random-effects structure, and the numerical comparison is meaningful because the response data and fixed-effects column space are identical. If the larger fit instead added a fixed-effects time trend, its REML value would be based on a different contrast space; the value 5.8 would then not be a valid REML comparison of these structures.

Worked Example: Checking REML Invariance to Fixed-Design Scaling

Suppose a one-column fixed-effects design \(X\) has \(X'X=4\), and an equivalent design is \(X_*=2X\). The two matrices span the same fixed-effects column space. Since \(X_*'X_*=4X'X\), its determinant is \(16\), rather than \(4\).

In the determinant expression for the contrast likelihood, the change in \(\log|X'X|\) is \(\log(16)-\log(4)=\log(4)\). The conventional expression that omits \(-\log|X'X|\) inside the brackets would therefore change by \(-\tfrac12\log(4)=-\log(2)\). That change is an artifact of the parameterization, not a change in the contrast likelihood.

Including the correction gives an outside-the-brackets contribution of \(+\tfrac12\log|X'X|\). Rescaling adds \(+\tfrac12\log(4)=+\log(2)\), exactly cancelling the spurious \(-\log(2)\). Thus the contrast likelihood is unchanged. This invariance depends on using a full-rank basis; if the design is rank deficient, the inverse-based determinant formula cannot be used as written.

GLMMs, diagnostics, and alternatives

For a non-Gaussian GLMM, the exact Gaussian contrast construction above generally does not provide a REML likelihood: linear contrasts of a non-Gaussian response do not generally have the required normal likelihood. Some software offers a restricted or adjusted likelihood approximation for GLMMs, but the construction can depend on the approximation and implementation. A reported GLMM “REML” value should therefore not automatically be treated as the exact Gaussian restricted likelihood or compared across packages and methods. For GLMM random-effects comparisons, marginal ML is the usual likelihood basis; if an approximate restricted criterion is used, its definition and comparability conditions must be established for that specific method.

Before comparing fits, check the following:

  • Same response data: confirm identical observations, response coding, missing-data handling, offsets, and prior or sampling weights.
  • Same model conventions: use the same response distribution, link, integration method, approximation settings, and likelihood normalization.
  • Correct nesting: verify that the smaller random-effects model is obtained by constraints within the larger model, not by changing the fixed-effects part or data.
  • Successful fitting: inspect convergence messages, gradients, optimizer sensitivity, and whether estimated covariance matrices are singular or near singular.
  • Numerical accuracy: for approximate marginal likelihoods, check whether quadrature or integration settings materially change the reported values.

AIC or another information criterion can be an alternative for comparing non-nested candidate structures when their likelihoods refer to the same response data and likelihood convention. It does not repair incompatible likelihoods, and a REML-based criterion should not be used to compare different fixed-effects spaces. Predictive validation answers a different question—how well models predict new data—and may be preferable when prediction is the goal. Neither an information criterion nor predictive performance replaces checking model assumptions and the scientific meaning of the random-effects structure.

Common pitfall: “The larger model has a higher REML log likelihood, so it is better, even though it also changed the fixed-effects predictors.” This reasoning compares likelihoods based on different contrast spaces. For exact Gaussian REML, compare random-effects structures only when the fixed-effects column space is held fixed. If fixed effects differ, use comparable ML likelihoods instead; for a non-Gaussian GLMM, verify that any claimed REML criterion is a defined, consistently computed approximation.

The most important limitation is that likelihood comparability is not the same as inferential validity. A valid difference in ML or REML values does not alone determine the test’s null distribution, establish that the selected structure is scientifically adequate, or remove sensitivity to sparse data and weakly identified covariance parameters. Those issues require separate assessment.

Check Your Understanding

Answer each question, then compare with the short solutions.

  1. Two GLMMs use the same response data, fixed-effects design, and integration method. The larger random-effects structure contains the smaller one. If their ML log likelihoods are \(-96.2\) and \(-94.7\), respectively, calculate the likelihood-ratio statistic.
  2. Can exact REML values be compared when one Gaussian mixed model has an intercept-only fixed-effects design and the other also includes a treatment indicator? Explain.
  3. A REML determinant formula uses a full-rank design \(X\), but a column of \(X\) is an exact linear combination of other columns. What is wrong, and how can the calculation be reformulated?
  4. Why does a conditional likelihood evaluated at estimated random effects not automatically provide the ML likelihood for comparing GLMM random-effects structures?

Solutions. (1) \(2[(-94.7)-(-96.2)]=2(1.5)=3.0\). The comparison is meaningful under the stated common-data and common-method conditions; the statistic’s reference distribution is not determined by this calculation. (2) No. The fixed-effects column spaces differ, so the REML contrasts differ. Use comparable ML fits for a likelihood comparison of those fixed-effects specifications. (3) The design is rank deficient, so \(X'V^{-1}X\) is singular and the inverse-based formula is not defined. Use a full-rank basis for the column space or construct orthonormal contrasts directly. (4) ML for a GLMM is based on the response likelihood integrated over the random-effects distribution. Evaluating the conditional response density at estimated random effects omits that integration and is a different quantity.

Clinical Biostats