Tutorials › Generalized Linear Mixed Models (GLMM) › Curvature Derivatives and the Laplace Score

Laplace Approximation and Adaptive Quadrature · Tutorial 199 of 698

Curvature Derivatives and the Laplace Score

Learn to differentiate the Laplace curvature adjustment correctly, including the contribution from the parameter-dependent conditional mode.

Advanced 12 min read

What You'll Learn

  • State the regularity and curvature conditions needed to differentiate a Laplace likelihood.
  • Derive the matrix trace identity for differentiating a log determinant.
  • Obtain the total derivative of the negative Hessian evaluated at a moving conditional mode.
  • Compute the curvature contribution to a Laplace score in scalar and multivariate examples.
  • Diagnose errors caused by omitting mode movement or assuming curvature is positive definite without checking it.
  • Distinguish the score of the Laplace approximation from the score of the exact integrated likelihood.

Why Curvature Appears in the Laplace Score

A Laplace approximation to a GLMM likelihood depends on more than the value of the integrand at its conditional mode. It also depends on the local curvature there: a sharply peaked integrand and a broadly peaked integrand have different approximate integrals even if their peak heights agree. When a model parameter changes, this curvature changes too, and the derivative of that adjustment is part of the Laplace score.

The focus here is the derivative of the log-determinant term. The earlier material on differentiating the Laplace approximation and the envelope theorem supplies useful context: the derivative of the log integrand evaluated at its mode has a simplified form, but that simplification does not remove the derivative of the curvature adjustment.

Definition: For a cluster with observed data fixed, write its random-effects integral as \(I(\theta)=\int_{\mathbb R^q}\exp\{h(b;\theta)\}\,db\), where \(b\) is a \(q\)-dimensional random-effects vector and \(\theta\) is a scalar model parameter. Let \(\hat b(\theta)\) be an interior conditional mode of \(h\), and define \(J(\theta)=-h_{bb}(\hat b(\theta);\theta)\), the negative Hessian with respect to \(b\) at that mode. When \(J\) is positive definite, the first-order Laplace approximation to the log integral is \(\ell_{\mathrm{Lap}}(\theta)=h(\hat b(\theta);\theta)+\frac q2\log(2\pi)-\frac12\log|J(\theta)|\).

The notation \(h_b\) and \(h_{bb}\) denotes the gradient and Hessian with respect to \(b\). A subscript \(\theta\) denotes a partial derivative holding \(b\) fixed. A derivative of \(J(\theta)\), by contrast, is a total derivative: it accounts for both the explicit dependence on \(\theta\) and the fact that \(\hat b\) moves as \(\theta\) changes.

For this calculation, assume \(h\) has continuous derivatives sufficient for the displayed derivatives, the mode is interior, and \(h_b(\hat b;\theta)=0\). Assume also that \(h_{bb}(\hat b;\theta)\) is nonsingular. Since a Hessian at a local maximum is negative semidefinite, nonsingularity makes it negative definite; thus \(J\) is positive definite. A strict local maximum alone does not ensure this: a strict maximum can have zero curvature in some direction. The nonsingularity condition is what permits the implicit differentiation below and ensures the ordinary Laplace determinant is well-defined and positive.

The Matrix Identity Behind the Derivative

For a differentiable, nonsingular matrix \(J(t)\) with positive determinant, the derivative of its log determinant is

$$ \frac{d}{dt}\log|J(t)|=\operatorname{tr}\left(J(t)^{-1}\frac{dJ(t)}{dt}\right). $$

Here \(\operatorname{tr}(A)\) is the sum of the diagonal entries of a square matrix \(A\). To justify the identity, take a small increment \(\varepsilon\) and factor the determinant:

$$ |J+\varepsilon K| =|J|\,|I+\varepsilon J^{-1}K| =|J|\{1+\varepsilon\operatorname{tr}(J^{-1}K)+o(\varepsilon)\}, $$

where \(K=dJ/dt\), and the last equality is the first-order expansion of the determinant about the identity matrix. Taking logarithms and dividing by \(\varepsilon\) gives the stated derivative. This identity applies to the total derivative of \(J(\theta)\), not merely its partial derivative at a fixed \(b\).

Worked Example: Evaluating the Trace Identity

Consider a hypothetical two-dimensional random-effects curvature matrix at one parameter value, \(J=\begin{pmatrix}2&0.5\\0.5&1.5\end{pmatrix}\), whose derivative with respect to a scalar parameter is \(K=\begin{pmatrix}0.3&-0.1\\-0.1&0.2\end{pmatrix}\). The determinant of \(J\) is \(2(1.5)-0.5^2=2.75>0\), and its leading diagonal entry is positive, so \(J\) is positive definite.

Its inverse is \(J^{-1}=\frac{1}{2.75}\begin{pmatrix}1.5&-0.5\\-0.5&2\end{pmatrix}\). Therefore

$$ \frac{d}{d\theta}\log|J| =\operatorname{tr}(J^{-1}K) =\frac{1}{2.75}\{(1.5)(0.3)+(-0.5)(-0.1)+(-0.5)(-0.1)+(2)(0.2)\} =\frac{0.95}{2.75}=0.3455. $$

The curvature contribution to the Laplace score is minus one half of this quantity, or \(-0.1727\). The negative sign comes from the \(-\frac12\log|J|\) in the Laplace log integral.

Differentiating Curvature at the Moving Mode

Differentiate the mode equation \(h_b(\hat b(\theta);\theta)=0\) with respect to \(\theta\). The chain rule gives \(h_{bb}\,d\hat b/d\theta+h_{b\theta}=0\), with derivatives evaluated at the mode. Since \(h_{bb}=-J\), the mode sensitivity is

$$ \frac{d\hat b}{d\theta}=J^{-1}h_{b\theta}. $$

This step uses the nonsingularity of \(h_{bb}\); the implicit function theorem then gives a locally differentiable mode branch. Now differentiate \(J(\theta)=-h_{bb}(\hat b(\theta);\theta)\). In component notation, with \(j,k\in\{1,\ldots,q\}\),

$$ \frac{dJ_{jk}}{d\theta} =-h_{b_jb_k\theta} -\sum_{a=1}^q h_{b_jb_kb_a}\frac{d\hat b_a}{d\theta}. $$

Thus the total derivative contains an explicit parameter term and a mode-movement term. Substituting the mode sensitivity into the derivative of the Laplace log integral yields the score.

Result: Under the stated smoothness, interior-mode, and nonsingular-Hessian conditions, the derivative of the Laplace log integral is
$$ \frac{d\ell_{\mathrm{Lap}}}{d\theta} =h_\theta(\hat b;\theta) -\frac12\operatorname{tr}\left(J^{-1}\frac{dJ}{d\theta}\right), \qquad \frac{dJ}{d\theta}=-h_{bb\theta}-h_{bbb}\left[\frac{d\hat b}{d\theta}\right], \qquad \frac{d\hat b}{d\theta}=J^{-1}h_{b\theta}. $$

The notation \(h_{bbb}[v]\) means contraction of the third-derivative array with vector \(v\): its \((j,k)\) entry is \(\sum_a h_{b_jb_kb_a}v_a\). The first term is the envelope contribution. The determinant term is separate and generally cannot be dropped. For a vector parameter, apply these formulas component by component.

Worked Example: A Scalar Curvature Term

For a hypothetical one-dimensional cluster contribution, suppose \(h(b;\theta)=2\theta-\frac12(2+\theta)(b-\theta^2)^2\), evaluated at \(\theta=0.4\). This is a Gaussian-shaped log integrand with a unique interior mode \(\hat b=\theta^2\). Its negative second derivative is \(J=2+\theta=2.4>0\), so the curvature condition holds.

At the mode, \(h_\theta=2\), because the derivative of the squared term is zero when \(b=\theta^2\). Also, \(dJ/d\theta=1\); here \(J\) has no dependence on \(b\), so mode movement adds nothing to its derivative. The score is

$$ \frac{d\ell_{\mathrm{Lap}}}{d\theta} =h_\theta-\frac12J^{-1}\frac{dJ}{d\theta} =2-\frac12\left(\frac{1}{2.4}\right)(1) =1.7917. $$

In this example the integral is exactly Gaussian, so the log integral is \(2\theta+\frac12\log(2\pi)-\frac12\log(2+\theta)\), whose direct derivative is also \(2-\frac{1}{2(2+\theta)}=1.7917\). This agreement checks both the sign and the factor of one half.

Worked Example: Including Movement of the Conditional Mode

Consider the hypothetical scalar log integrand \(h(b;\theta)=-\frac12b^2-0.05b^4+\theta b\), at \(\theta=0.5\). Its mode solves \(h_b=-b-0.2b^3+\theta=0\). The second derivative is \(h_{bb}=-1-0.6b^2<0\) for every \(b\), so the integrand is strictly concave and the mode is unique and nondegenerate.

Solving \(b+0.2b^3=0.5\) gives \(\hat b\approx0.47814\). Hence \(J=1+0.6\hat b^2\approx1.1372\). The mode sensitivity is \(d\hat b/d\theta=1/J\approx0.8794\), since \(h_{b\theta}=1\). There is no explicit \(\theta\) dependence in \(J\) at fixed \(b\), but there is mode dependence:

$$ \frac{dJ}{d\theta} =1.2\hat b\frac{d\hat b}{d\theta} \approx1.2(0.47814)(0.8794)=0.5046. $$

Here \(h_\theta=b\), so \(h_\theta(\hat b;\theta)\approx0.47814\). The Laplace score is therefore

$$ \frac{d\ell_{\mathrm{Lap}}}{d\theta} \approx0.47814-\frac12\frac{0.5046}{1.1372} \approx0.2563. $$

If the mode-movement contribution were incorrectly omitted, one would set \(dJ/d\theta=0\) and report \(0.47814\). That is not the derivative of the Laplace approximation: the curvature changes because the mode shifts as \(\theta\) changes.

Checking the Calculation and Understanding Its Limits

A practical implementation should check both the conditional mode and its curvature. At a proposed mode, verify that the gradient \(h_b\) is close to zero and that the eigenvalues of \(J\) are positive and not so small that \(J^{-1}\) is numerically unstable. Then compare the analytic or automatic-differentiation score with a centered finite difference of the Laplace log likelihood over several step sizes. The finite-difference check should recompute the mode and curvature at each perturbed parameter value; holding the mode fixed checks a different derivative.

There are important failure modes. A nearly singular Hessian can make the mode sensitivity and trace term very large, while an exactly singular Hessian invalidates the displayed inverse and ordinary nondegenerate Laplace formula. If competing modes exchange which one is selected as the global mode, the selected approximation may fail to be differentiable at the switch. Numerical instability in the mode or Hessian can also create an apparent score discrepancy. These are reasons to inspect gradients, eigenvalues, mode solutions, and sensitivity to numerical tolerances rather than trusting a score value in isolation.

The score derived here is the derivative of the Laplace-approximated log integral. It is not generally the exact score of the integrated likelihood, because the Laplace approximation itself can have error. Exact integration or adaptive quadrature provides an alternative when feasible; numerical finite differences can serve as a check, but can be sensitive to step size and mode-solving error. Omitting the determinant derivative is not a valid alternative score: it differentiates only the mode-height part of the approximation.

A frequent mistake is to argue that any strict local maximum guarantees positive-definite \(J\). That inference is false: for \(h(b)=-b^4\), \(b=0\) is a strict local maximum but \(h_{bb}(0)=0\). The correction is to require a nonsingular Hessian at the local maximum (or explicitly assume a nondegenerate maximum); then negative semidefiniteness plus nonsingularity implies negative definiteness and \(J\) is positive definite. This distinction matters both for the validity of the determinant and for differentiability of the mode.

Key takeaway: The curvature part of a Laplace score is \(-\frac12\operatorname{tr}(J^{-1}dJ/d\theta)\). Its derivative \(dJ/d\theta\) is total: include explicit parameter dependence and the change in curvature induced by movement of the conditional mode.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. If \(J(\theta)=3+2\theta\) in a one-dimensional example and \(dJ/d\theta=2\), what is the log-determinant contribution to the Laplace score at \(\theta=1\)?
  2. For a scalar mode, what equation gives \(d\hat b/d\theta\), and which condition allows the equation to be solved using \(J^{-1}\)?
  3. Why can a strict local maximum fail to give a positive-definite \(J\)? State the additional condition needed here.
  4. In the formula for \(dJ/d\theta\), identify the explicit parameter term and the mode-movement term.

Solutions. (1) At \(\theta=1\), \(J=5\), so the contribution is \(-\frac12J^{-1}(dJ/d\theta)=-\frac12(1/5)(2)=-0.2\). (2) Differentiating \(h_b(\hat b;\theta)=0\) gives \(d\hat b/d\theta=J^{-1}h_{b\theta}\); \(J\) must be nonsingular, and for the ordinary Laplace formula it is positive definite. (3) A strict maximum can have zero second derivative, as \(h(b)=-b^4\) at zero demonstrates. Nonsingularity of the Hessian at the local maximum makes its negative semidefinite Hessian negative definite. (4) The explicit term is \(-h_{bb\theta}\); the mode-movement term is \(-h_{bbb}[d\hat b/d\theta]\).

Clinical Biostats