Tutorials › Generalized Linear Mixed Models (GLMM) › Worked Derivation of a Random-Intercept Laplace Likelihood

Laplace Approximation and Adaptive Quadrature · Tutorial 207 of 698

Worked Derivation of a Random-Intercept Laplace Likelihood

Learn to derive and calculate the Laplace-approximated marginal log likelihood for binary random-intercept data, including its mode, curvature, and determinant correction.

Advanced 11 min read

What You'll Learn

  • Write the marginal likelihood integral for a binary random-intercept model.
  • Derive the conditional-mode equation and verify its solution.
  • Calculate the curvature and the scalar determinant correction.
  • Assemble cluster contributions without dropping normalizing constants.
  • Diagnose when the Laplace approximation may be unreliable.
  • Distinguish Laplace approximation from mode substitution and numerical quadrature.

From the Random-Effects Integrand to a Marginal Likelihood

A binary random-intercept model assigns each cluster a latent intercept that shifts the log odds for every observation in that cluster. The marginal likelihood for the observed responses averages their conditional likelihood over the assumed distribution of that intercept. This tutorial derives a Laplace approximation to that integral, keeping track of the mode, curvature, and normal-density normalization that determine the resulting log likelihood.

Suppose there are \(J\) independent clusters. In cluster \(j\), response \(Y_{ij}\) is binary, and, conditional on the cluster random intercept \(b_j\), responses are independent with \(Y_{ij}\mid b_j\sim\operatorname{Bernoulli}(p_{ij})\), where \(\operatorname{logit}(p_{ij})=\mathbf{x}_{ij}^{\mathsf T}\boldsymbol{\beta}+b_j\). Assume \(b_j\sim N(0,\sigma_b^2)\), independently across clusters, with \(\sigma_b^2>0\). The fixed effects \(\boldsymbol{\beta}\) and variance \(\sigma_b^2\) are held fixed when deriving each integral.

Definition: For one cluster, let \(\ell_j(b)\) be its conditional Bernoulli log likelihood given random intercept \(b\), and define \(q_j(b)=\ell_j(b)-b^2/(2\sigma_b^2)\). The cluster’s marginal likelihood contribution is \(L_j=(\sqrt{2\pi}\sigma_b)^{-1}\int_{-\infty}^{\infty}\exp\{q_j(b)\}\,db\). The Laplace approximation evaluates the exponent at its mode and adjusts by its local curvature.

For observed responses \(y_{ij}\), the conditional log likelihood is \(\ell_j(b)=\sum_i\{y_{ij}\eta_{ij}(b)-\log[1+\exp\{\eta_{ij}(b)\}]\}\), where \(\eta_{ij}(b)=\mathbf{x}_{ij}^{\mathsf T}\boldsymbol{\beta}+b\). This expression uses the individual Bernoulli observations; there is no binomial coefficient to add. If the data are instead recorded as a binomial count, the corresponding count likelihood includes its binomial coefficient, which must be retained when calculating the marginal likelihood of that count.

Mode, Curvature, and the Laplace Formula

Write \(p_{ij}(b)=\{1+\exp[-\eta_{ij}(b)]\}^{-1}\). Differentiating the conditional log likelihood and the normal-kernel term gives

$$ q_j'(b)=\sum_i\{y_{ij}-p_{ij}(b)\}-\frac{b}{\sigma_b^2}, \qquad q_j''(b)=-\sum_i p_{ij}(b)\{1-p_{ij}(b)\}-\frac{1}{\sigma_b^2}. $$

The conditional mode \(\hat b_j\) solves \(q'_j(\hat b_j)=0\). Define the negative second derivative at that mode as the scalar curvature \(H_j=-q_j''(\hat b_j)\). Thus \(H_j=\sum_i p_{ij}(\hat b_j)\{1-p_{ij}(\hat b_j)\}+1/\sigma_b^2\), which is strictly positive. In this one-dimensional setting, the Hessian determinant is simply \(H_j\).

These derivatives also establish that there is exactly one finite mode for each cluster at fixed finite \(\boldsymbol{\beta}\) and positive \(\sigma_b^2\): \(q_j''(b)<0\) everywhere, so \(q'_j(b)\) is strictly decreasing. Moreover, the normal penalty makes \(q_j(b)\) tend to negative infinity as \(|b|\) grows. The unique maximum can therefore be found by solving the score equation.

Derivation: A second-order Taylor expansion about the mode gives \(q_j(b)\approx q_j(\hat b_j)-\tfrac12 H_j(b-\hat b_j)^2\), because \(q'_j(\hat b_j)=0\). Substituting this quadratic into the integral gives \(\int \exp\{q_j(b)\}\,db\approx \exp\{q_j(\hat b_j)\}\sqrt{2\pi/H_j}\), using the Gaussian integral. Dividing by the normal density’s factor \(\sqrt{2\pi}\sigma_b\) cancels \(\sqrt{2\pi}\). Therefore \(\log L_j\approx q_j(\hat b_j)-\log(\sigma_b)-\tfrac12\log(H_j)\), equivalently \(\ell_j(\hat b_j)-\hat b_j^2/(2\sigma_b^2)-\tfrac12\log(\sigma_b^2H_j)\).

The factor \(\sigma_b^2H_j\) in the final expression is dimensionless: \(H_j\) has inverse-variance units on the random-intercept scale. The normalization is consequential. Keeping the unnormalized kernel but omitting the normal-density constant would add \(\log(\sqrt{2\pi}\sigma_b)\) to the cluster result and would not be the likelihood under the stated normal random-effects distribution.

Worked Example: Three Successes Among Four Bernoulli Responses

Consider one hypothetical cluster with four binary responses, three successes and one failure. Let the fixed linear predictor be zero apart from the random intercept, and set \(\sigma_b^2=1\). Then \(p(b)=\operatorname{logit}^{-1}(b)\), \(\ell(b)=3b-4\log(1+e^b)\), and \(q(b)=3b-4\log(1+e^b)-b^2/2\).

The score equation is \(3-4p(b)-b=0\). Solving it numerically gives \(\hat b\approx0.50524\) and \(p(\hat b)\approx0.62369\). Substitution in the score gives \(3-4(0.62369)-0.50524\approx0\), with the displayed discrepancy attributable to rounding.

At the mode, the conditional log likelihood is \(\ell(\hat b)=3(0.50524)-4\log(1+e^{0.50524})\approx1.51572-3.9094=-2.3937\). The normal-kernel penalty is \(-\hat b^2/(2\sigma_b^2)=-(0.50524)^2/2\approx-0.1276\).

The curvature is \(H=4(0.62369)(1-0.62369)+1\approx1.9388\). Consequently, the determinant correction is \(-\tfrac12\log(\sigma_b^2H)=-\tfrac12\log(1.9388)\approx-0.3310\). The approximate marginal log likelihood contribution is therefore \(-2.3937-0.1276-0.3310\approx-2.8523\).

Each displayed term has a distinct role: conditional fit at the mode, shrinkage from the normal density, and adjustment for the width of the integrand near that mode. Substituting the mode into the conditional likelihood alone would omit the last two terms and would not approximate the marginal likelihood.

Worked Example: One Success and the Normalizing Correction

For a second hypothetical cluster, observe one success, set the fixed linear predictor to zero, and take \(\sigma_b^2=1\). Here \(q(b)=b-\log(1+e^b)-b^2/2\), so the score equation is \(1-p(b)-b=0\). Its solution is \(\hat b\approx0.40106\), with \(p(\hat b)\approx0.59894\); indeed \(1-0.59894-0.40106\approx0\).

The conditional log likelihood is \(\ell(\hat b)=\log\{p(\hat b)\}=\log(0.59894)\approx-0.5126\). The prior penalty is \(-\hat b^2/2=-(0.40106)^2/2\approx-0.0804\). The curvature is \(H=p(\hat b)\{1-p(\hat b)\}+1\approx1.2402\), giving \(-\tfrac12\log(1.2402)\approx-0.1076\).

Thus the Laplace contribution is approximately \(-0.5126-0.0804-0.1076=-0.7006\). The normalizing term is not an optional small-sample adjustment: it follows directly from integrating against the specified \(N(0,1)\) density.

Combining Clusters and Checking the Calculation

Because clusters are independent and their random intercepts are independent, the joint marginal likelihood factors into cluster integrals: \(L=\prod_{j=1}^J L_j\). Taking logarithms turns that product into a sum. The approximation is applied separately to each cluster integral, using its own mode and curvature, and the resulting log contributions are then added.

Worked Example: Assemble a Two-Cluster Approximation

Suppose a hypothetical data set has two independent clusters under the same fixed parameters \(\boldsymbol{\beta}=0\) and \(\sigma_b^2=1\). Cluster A has three successes and one failure; cluster B has one success. The calculations above give approximate log contributions \(-2.8523\) and \(-0.7006\), respectively.

The joint marginal log likelihood is approximated by \(\log L\approx\log L_A+\log L_B=-2.8523-0.7006=-3.5529\), or about \(-3.553\). Equivalently, the approximate joint likelihood is \(\exp(-3.5529)\approx0.0286\). This product is the probability of the particular observed response sequence under the specified model, approximated by Laplace integration. It is not obtained by pooling the five observations into a single cluster: doing so would impose one shared random intercept where the model specifies two.

A useful calculation check is to verify the score and curvature with the same unrounded mode and probabilities, then round reported results. The score should be close to zero; \(H_j\) must be positive; and the determinant correction must use the product \(\sigma_b^2H_j\). Small rounding differences in intermediate displayed values are expected, but they should not materially alter the final reported precision.

Assumptions, Diagnostics, and Alternatives

The derivation assumes conditionally independent Bernoulli responses given the random intercept, a normal random-intercept distribution with positive variance, independent clusters, and finite fixed predictors. The Laplace step additionally assumes that a local quadratic approximation around the mode adequately represents the integrand’s important mass. A unique mode and positive curvature are guaranteed here by strict concavity, but these facts alone do not ensure that the quadratic approximation is accurate.

Check numerical and modeling warning signs before relying on the approximation:

  • Mode check: evaluate \(q'_j(\hat b_j)\) numerically. A visibly nonzero score can indicate failed optimization, inadequate convergence tolerance, or a coding error.
  • Curvature check: confirm \(H_j>0\), compute it from the same mode used in the score, and inspect whether the integrand is sharply or weakly concentrated. A broad or strongly non-quadratic integrand can make the local approximation less dependable.
  • Scaling check: use the normalizing constant and determinant in the same parameterization as the integral. A change of integration variable requires its Jacobian; dropping it changes the integral.
  • Approximation check: compare Laplace results with numerical quadrature where feasible, and examine changes under increased quadrature accuracy. Material disagreement indicates that Laplace error may matter for the likelihood or subsequent estimates.
  • Model check: integration accuracy cannot repair a misspecified conditional response model, an unsuitable random-effects distribution, or dependence left unmodeled within clusters.

Numerical quadrature approximates the integral by weighted evaluations across the random-effects distribution and can be more accurate when the integrand is not well represented by one quadratic neighborhood, at additional computational cost. Laplace is a local, mode-and-curvature approximation and is often computationally efficient. Simply substituting the conditional mode is not a competing marginal-likelihood calculation: it ignores both the random-effects penalty and the integral-width correction. The approximation can be limited when cluster information is weak or the integrand is asymmetric; a positive curvature alone does not rule out those cases.

Common pitfall: Using only \(\ell_j(\hat b_j)\) treats the estimated cluster intercept as if it were known and observed. The correction is not merely the normal penalty: the marginal log likelihood also includes \(-\tfrac12\log(\sigma_b^2H_j)\), which accounts for integration around the mode. Conversely, using \(H_j\) but forgetting the normal density’s scale factor \(\sigma_b\) leaves the likelihood on the wrong scale.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. For one cluster, write \(q_j(b)\) and its score when the conditional probabilities are logistic and \(b\sim N(0,\sigma_b^2)\).
  2. Why is the mode unique for a binary random-intercept cluster with finite predictors and \(\sigma_b^2>0\)?
  3. State the Laplace-approximated log contribution using \(\ell_j(\hat b_j)\), \(\hat b_j\), and \(H_j\).
  4. Two clusters have approximate log contributions \(-1.20\) and \(-0.70\). What is the approximate joint marginal log likelihood, and why are the contributions added?
  5. What is wrong with reporting \(\ell_j(\hat b_j)\) alone as the marginal log likelihood?

Solutions. (1) \(q_j(b)=\ell_j(b)-b^2/(2\sigma_b^2)\), and \(q'_j(b)=\sum_i(y_{ij}-p_{ij}(b))-b/\sigma_b^2\). (2) Its second derivative is \(-\sum_i p_{ij}(b)\{1-p_{ij}(b)\}-1/\sigma_b^2<0\), so the function is strictly concave; the normal penalty also makes it tend to negative infinity in both tails. (3) The contribution is \(\ell_j(\hat b_j)-\hat b_j^2/(2\sigma_b^2)-\tfrac12\log(\sigma_b^2H_j)\). (4) The answer is \(-1.20-0.70=-1.90\), because independent cluster likelihood contributions multiply and logarithms convert that product to a sum. (5) It omits the normal random-effects penalty and the curvature correction, so it is a conditional likelihood evaluated at a fitted intercept, not an approximation to the marginal likelihood.

Clinical Biostats