Tutorials › Generalized Linear Mixed Models (GLMM) › Laplace Approximation from a Quadratic Taylor Expansion

Laplace Approximation and Adaptive Quadrature · Tutorial 169 of 698

Laplace Approximation from a Quadratic Taylor Expansion

Learn how local curvature at an integrand’s mode determines the Laplace approximation, and how to check whether that approximation is being used appropriately.

Advanced 12 min read

What You'll Learn

  • Define the mode and negative Hessian used in a local Laplace approximation.
  • Derive the approximation by integrating a quadratic Taylor expansion.
  • Calculate the approximation in one and multiple dimensions.
  • Apply the calculation to a hypothetical binary random-intercept integrand.
  • Check mode, curvature, and integrability conditions before relying on the result.
  • Recognize when a local Gaussian approximation may be unreliable.

Why Approximate an Integral Locally?

In a GLMM, integrating over random effects can produce an integral that is difficult to evaluate directly. The Laplace approximation replaces the log integrand near its dominant mode with a quadratic function. Exponentiating that quadratic gives a Gaussian-shaped function whose integral is available analytically. The approximation therefore uses two local features: the height of the integrand at the mode and its curvature there.

This tutorial derives that calculation for a general integral over a vector \(b\) of dimension \(q\). Here \(b\) can represent a vector of random effects, but the derivation itself only requires a suitable integrand. The result is a local approximation, not an identity for an arbitrary integrand.

Definition: Let \(g(b)>0\) be an integrable function on \(\mathbb{R}^q\), and write \(h(b)=\log g(b)\). An interior mode \(b^*\) is a point where \(h\) attains a local maximum. If \(h\) is twice differentiable there, define the negative Hessian at the mode by \(H=-\nabla^2 h(b^*)\). The Laplace approximation replaces \(h\) near \(b^*\) by its second-order Taylor expansion and integrates the exponential of that quadratic approximation.

From a Taylor Expansion to a Gaussian Integral

For an interior mode at which \(h\) is differentiable, the gradient satisfies \(\nabla h(b^*)=0\). Let \(\delta=b-b^*\). The second-order Taylor expansion around the mode is

$$ h(b^*+\delta) = h(b^*)+\nabla h(b^*)^\mathsf{T}\delta +\frac{1}{2}\delta^\mathsf{T}\nabla^2h(b^*)\delta +r(\delta), $$

where \(r(\delta)\) is the Taylor remainder, which is small relative to \(\|\delta\|^2\) as \(\delta\) approaches zero when \(h\) is twice differentiable at the mode. The gradient term vanishes, and \(\nabla^2 h(b^*)=-H\). Neglecting the remainder gives the local approximation

$$ h(b^*+\delta)\approx h(b^*)-\frac{1}{2}\delta^\mathsf{T}H\delta. $$

If \(H\) is positive definite, this quadratic decreases in every direction away from the mode. Exponentiating the approximation gives a peak of height \(\exp\{h(b^*)\}\), multiplied by a Gaussian-shaped term. Integrating that term over all \(q\) dimensions yields the Laplace approximation.

1
Expand at the mode.
Use \(\nabla h(b^*)=0\) to remove the linear term in the Taylor expansion.
2
Keep the local curvature.
Write the quadratic term using the negative Hessian \(H=-\nabla^2 h(b^*)\).
3
Integrate the quadratic approximation.
Use the multivariate Gaussian integral, which contributes a factor determined by the determinant of \(H\).

For completeness, diagonalize the symmetric positive-definite matrix \(H\) as \(H=Q\Lambda Q^\mathsf{T}\), where \(Q\) is orthogonal and \(\Lambda\) has positive eigenvalues. Under the change of variables \(z=\Lambda^{1/2}Q^\mathsf{T}\delta\), the quadratic form becomes \(z^\mathsf{T}z\), and the volume element changes by the factor \((\det H)^{-1/2}\). The integral of \(\exp(-z^\mathsf{T}z/2)\) over \(\mathbb{R}^q\) is \((2\pi)^{q/2}\), since it factors into \(q\) one-dimensional standard Gaussian integrals. Thus the local approximation to \(I=\int_{\mathbb{R}^q}\exp\{h(b)\}\,db\) is

$$ I\approx \exp\{h(b^*)\}\frac{(2\pi)^{q/2}}{\sqrt{\det H}}. $$

The determinant term is not an arbitrary correction: it measures the volume of the local Gaussian-shaped peak. A sharply curved peak has a larger determinant and a smaller integral for a fixed peak height. A flatter peak has a smaller determinant and a larger integral.

Worked Example: A One-Dimensional Nonquadratic Log Integrand

Consider the hypothetical log integrand \(h(b)=-1-2b^2-0.2b^4\) on the real line. Its derivative is \(h'(b)=-4b-0.8b^3\), which is zero at \(b^*=0\). Since \(h(b)\) decreases as \(|b|\) increases, this is its unique mode. Its second derivative is \(h''(b)=-4-2.4b^2\), so the negative Hessian at the mode is \(H=4\), which is positive.

The one-dimensional approximation uses \(q=1\) and \(\det H=4\):

$$ I\approx \exp\{h(0)\}\sqrt{\frac{2\pi}{4}} =e^{-1}\sqrt{\frac{2\pi}{4}} \approx (0.3679)(1.2533) \approx 0.4611. $$

The quartic term makes the log integrand nonquadratic, but it does not change its value or second derivative at the mode. The calculation therefore illustrates precisely which local information the approximation uses; it does not establish how close the approximation is to the full integral.

Worked Example: Curvature in Two Dimensions

Let \(x=b-b^*\), where the hypothetical mode is \(b^*=(1,-1)^\mathsf{T}\), and consider

$$ h(b)=-0.7-\frac{1}{2}x^\mathsf{T} \begin{pmatrix}4&1\\1&3\end{pmatrix}x -0.03(x_1^4+x_2^4). $$

At \(x=0\), the gradient is zero and \(h(b^*)=-0.7\). The quartic terms have zero second derivative at \(x=0\), so the negative Hessian there is

$$ H=\begin{pmatrix}4&1\\1&3\end{pmatrix}, \qquad \det H=(4)(3)-(1)(1)=11. $$

The matrix is positive definite: its leading diagonal entry is positive and its determinant is positive. Therefore the local quadratic has downward curvature in both dimensions. Substituting \(q=2\), \(h(b^*)=-0.7\), and \(\det H=11\) gives

$$ I\approx e^{-0.7}\frac{2\pi}{\sqrt{11}} \approx (0.4966)\left(\frac{6.2832}{3.3166}\right) \approx 0.9408. $$

The off-diagonal entries matter: they encode curvature involving both coordinates. Replacing \(H\) by its diagonal entries would give a different determinant and would discard that local dependence.

Example in a Binary Random-Intercept Setting

The same steps apply when the integration variable is a random effect. Consider hypothetical binary responses from four observations in one cluster, with two successes and two failures. Suppose the fixed intercept is zero and the cluster random intercept \(u\) has a \(N(0,1)\) density. For this example, define \(h(u)\) as the log of the product of the four conditional Bernoulli probabilities and the random-effect density. The conditional success probability is \(p(u)=e^u/(1+e^u)\), so

$$ h(u)=2\log p(u)+2\log\{1-p(u)\} -\frac{u^2}{2}-\frac{1}{2}\log(2\pi). $$

This integrand is positive after exponentiation and integrable: the normal density factor decays in the tails, while the conditional probabilities are at most one. To locate its mode, use \(\log p(u)=u-\log(1+e^u)\) and \(\log\{1-p(u)\}=-\log(1+e^u)\). Then

$$ h'(u)=2-4p(u)-u. $$

At \(u=0\), \(p(0)=1/2\), so \(h'(0)=2-4(1/2)-0=0\). Also \(h''(u)=-4p(u)\{1-p(u)\}-1<0\) for every finite \(u\). Thus \(h\) is strictly concave, and \(u^*=0\) is its unique mode. At the mode, \(H=-h''(0)=4(1/2)(1/2)+1=2\), and \(h(0)=-4\log 2-\tfrac12\log(2\pi)\approx-3.6915\). The one-dimensional Laplace calculation is

$$ I\approx e^{-3.6915}\sqrt{\frac{2\pi}{2}} \approx (0.02493)(1.7725) \approx 0.04419. $$

The numerical value is an approximation to the integral of the specified integrand over \(u\). The example checks the relevant conditions directly: the mode is interior and unique, the curvature is positive after changing the Hessian’s sign, and the integrand is integrable.

Conditions, Diagnostics, and Alternatives

The calculation is most defensible when the integral is finite, the relevant mode is interior, the log integrand is sufficiently smooth near it, and \(H\) is positive definite. The mode should also capture the region that contributes most of the integral. These are conditions for interpreting a local approximation sensibly; positive curvature at one point alone does not guarantee accuracy over the entire integration domain.

In computation, check the mode and curvature rather than treating the output as self-validating. A materially nonzero gradient suggests that the proposed point is not a well-located mode. A negative or near-zero eigenvalue of \(H\) indicates that the quadratic does not define a well-behaved local Gaussian peak; it may signal a saddle point, an inadequately located mode, or weak curvature. A very small determinant can make the approximation extremely sensitive to numerical error in the Hessian. In multiple dimensions, the determinant must be calculated from the full Hessian, including off-diagonal entries.

Direct numerical integration can be preferable when the integral is low-dimensional and can be evaluated accurately over the important region. Quadrature methods approximate an integral using weighted evaluations of the integrand rather than relying only on its local second-order shape. The Laplace approximation is attractive when a compact local calculation is useful, particularly in higher-dimensional settings, but neither method should be selected without considering the integrand’s shape and the required accuracy.

A single local quadratic may be unreliable if substantial mass lies far from the mode, the integrand is strongly asymmetric near the mode, or there are multiple important modes. A boundary mode also requires care, because the derivation above integrates a full Gaussian over \(\mathbb{R}^q\), whereas a constrained domain may contain only part of that local Gaussian. These cases call for further investigation or a method that represents more of the integrand than its value and curvature at one point.

Common Mistakes

  • Using the Hessian with the wrong sign. At a twice-differentiable local maximum, \(\nabla^2h(b^*)\) is negative semidefinite; for the standard nondegenerate Laplace approximation, it is assumed negative definite, so \(H=-\nabla^2h(b^*)\) is positive definite.
  • Forgetting the square root. The denominator is \(\sqrt{\det H}\), not \(\det H\).
  • Using only the peak height. The approximation also depends on curvature. Two peaks with equal height but different widths generally have different approximate integrals.
  • Assuming a valid local calculation proves global accuracy. The formula describes the integrand near a mode. It does not, by itself, rule out important contributions elsewhere.
Key takeaway: The Laplace approximation is the peak height \(\exp\{h(b^*)\}\) multiplied by the volume factor \((2\pi)^{q/2}/\sqrt{\det H}\). Its use depends on a correctly located, locally well-curved mode and on the local quadratic capturing the important part of the integral.

Check Your Understanding

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

  1. For a one-dimensional log integrand with mode value \(h(b^*)=-2\) and negative second derivative \(H=9\), what is the Laplace approximation?
  2. In two dimensions, why is a positive determinant alone not enough to establish that a symmetric negative Hessian is negative definite?
  3. For the binary random-intercept example, what are \(p(0)\), \(h'(0)\), and \(H\)?
  4. Name two diagnostic signs that the local approximation may be unreliable, and state what each suggests.

Solutions. (1) Substitute \(q=1\), \(h(b^*)=-2\), and \(H=9\): \(I\approx e^{-2}\sqrt{2\pi/9}\approx(0.1353)(0.8355)=0.1131\). (2) A symmetric two-dimensional matrix can have two negative eigenvalues, whose product is positive, or two positive eigenvalues, whose product is also positive. To establish positive definiteness of \(H\), check both leading principal minors: its first diagonal entry and its determinant must be positive. Equivalently, check that both eigenvalues are positive. (3) \(p(0)=1/2\); \(h'(0)=2-4(1/2)-0=0\); and \(H=4(1/2)(1/2)+1=2\). (4) A materially nonzero gradient suggests that the proposed point is not the mode. A nonpositive eigenvalue of \(H\) means the local quadratic does not give a proper Gaussian-shaped peak; a nearly zero eigenvalue signals weak curvature and potential numerical sensitivity.

Clinical Biostats