Why Differentiating the Approximation Requires Care
In a GLMM, the Laplace approximation replaces an integral over random effects with a quantity evaluated at the conditional mode and its local curvature. When a model parameter changes, the mode generally moves. The curvature used in the approximation can therefore change both directly with the parameter and indirectly because it is evaluated at a different mode. A derivative that holds either quantity fixed can give the wrong gradient for likelihood optimization.
Write \(u\in\mathbb{R}^q\) for the random-effects vector and \(\theta\) for one scalar model parameter, such as a fixed effect or a covariance parameter. Let \(h(u;\theta)\) be the log of the integrand, including the conditional response log likelihood and the random-effects log density. Constants in \(h\) must be retained if they depend on \(\theta\). The integral and its Laplace approximation are
where \(\hat{u}=\hat{u}(\theta)\) is the conditional mode and \(H(u;\theta)=-\partial^2 h(u;\theta)/\partial u\partial u'\) is the negative Hessian with respect to \(u\). The determinant term uses the Hessian at the mode.
Conditions and the General Derivative
For the formulas below, assume that near the parameter value of interest, \(h\) has continuous derivatives sufficient to differentiate its score and Hessian; the mode is an interior stationary point; and \(H(\hat{u};\theta)\) is positive definite. Assume also that this mode is the relevant isolated maximum for the Laplace approximation and that the integral is finite. These conditions ensure a locally smooth mode and a well-defined log determinant. A boundary mode, a singular Hessian, or competing modes can invalidate the ordinary derivative formulas.
The mode satisfies the score equation \(h_u(\hat{u};\theta)=0\), where \(h_u\) is the column vector of derivatives with respect to \(u\). Differentiating this equation gives the mode’s sensitivity to \(\theta\). In the next formula, \(h_{u\theta}\) is the vector of mixed derivatives, and all derivatives are evaluated at \((\hat{u};\theta)\).
The sign in the second equality follows from \(h_{uu}=-H\). Thus, the mode moves more sharply in directions where the curvature is weak, since those directions correspond to smaller eigenvalues of \(H\).
To differentiate the log approximation, first apply the chain rule to \(h(\hat{u}(\theta);\theta)\). The term involving the mode derivative is \(h_u' d\hat{u}/d\theta\), which is zero at the mode by its score equation. The determinant term does not have this cancellation: its Hessian is evaluated at the moving mode. For a positive definite matrix \(H\), the differential identity \(d\log|H|=\operatorname{tr}(H^{-1}dH)\) yields
Here \(H_\theta\) is the partial derivative holding \(u\) fixed, while \(H_{u_k}\) is the matrix of derivatives of \(H\) with respect to the \(k\)th coordinate of \(u\). The sum accounts for the change in the Hessian caused by movement of the mode. Equivalently, the matrix in braces is the total derivative \(dH(\hat{u}(\theta);\theta)/d\theta\). For a vector of model parameters, apply the same expression separately to each coordinate.
Worked Example: A Fixed-Effect Derivative in a Gaussian Random-Intercept Model
Consider one hypothetical observation \(y=2\) with conditional model \(Y\mid u\sim N(\beta+u,1)\) and random intercept \(u\sim N(0,4)\). Take \(\beta=0.5\). The log integrand, including both normalizing constants, is
The score is \(h_u=(2-\beta-u)-u/4\). Setting it equal to zero gives \(\hat{u}=\frac{4}{5}(2-\beta)=1.2\). The negative Hessian is \(H=1+1/4=1.25\), which is positive, so this is a strict maximum. Because the Hessian does not depend on \(\beta\) or \(u\), its total derivative with respect to \(\beta\) is zero.
At the mode, the residual is \(2-0.5-1.2=0.3\). The partial derivative \(h_\beta\) is that residual, so the derivative of the log Laplace approximation is \(0.3\). Directly, the marginal distribution is \(Y\sim N(\beta,5)\); its log likelihood derivative is \((y-\beta)/5=1.5/5=0.3\), agreeing with the Laplace calculation. The equality here is exact because the log integrand is quadratic.
Worked Example: A Variance-Parameter Derivative
Use the same hypothetical observation and model, but now vary the random-intercept variance \(v=\tau^2\), evaluating the derivative at \(v=4\) with \(\beta=0.5\). The prior contribution to \(h\) is \(-\frac{1}{2}\log(2\pi v)-u^2/(2v)\). Writing \(r=y-\beta=1.5\), the mode is \(\hat{u}=vr/(1+v)\), and hence \(\hat{u}=1.2\) at \(v=4\). Differentiating this mode gives
The partial derivative of \(h\) with respect to \(v\), holding \(u\) fixed, is \(-1/(2v)+u^2/(2v^2)\). At the mode this is \(-1/8+1.44/32=-0.0800\). The curvature is \(H=1+1/v\), which has no dependence on \(u\). Thus the mode’s movement contributes zero to the total derivative of \(H\), and \(dH/dv=-1/v^2=-0.0625\). The log-determinant contribution is therefore
Adding the two contributions gives \(d\ell_{\mathrm{LA}}/dv=-0.0800+0.0250=-0.0550\). As a check, the marginal variance is \(1+v\), so the exact log likelihood derivative is \(-1/[2(1+v)]+r^2/[2(1+v)^2]=-0.1000+2.25/50=-0.0550\). Omitting the determinant derivative would incorrectly give \(-0.0800\).
When the Mode’s Movement Changes Curvature
In the Gaussian example, \(H\) did not depend on \(u\), so movement of the mode did not change the curvature. For a nonquadratic log integrand, that contribution is generally present. The following smooth scalar example isolates it.
Worked Example: The Indirect Hessian Derivative
Consider the hypothetical log kernel
At \(\theta=0\), the score is \(h_u=-u(1+0.3u+u^2)\). The quadratic factor is positive for every real \(u\), since its discriminant is \(0.3^2-4=-3.91<0\) and its leading coefficient is positive. The score is therefore positive for \(u<0\) and negative for \(u>0\), so the unique mode is \(\hat{u}=0\). The curvature there is \(H=-h_{uu}=1\), which is positive.
The mixed derivative \(h_{u\theta}\) is 1, so \(d\hat{u}/d\theta=H^{-1}h_{u\theta}=1\) at \(\theta=0\). The curvature as a function of \(u\) is \(H=1+0.6u+3u^2\). Its direct partial derivative with respect to \(\theta\) is zero, but its derivative with respect to \(u\) at the mode is 0.6. Consequently, its total derivative along the mode is \(dH/d\theta=0+0.6(1)=0.6\). Since \(h_\theta=u=0\) at the mode, the log-approximation derivative is
The negative derivative comes entirely from the change in curvature as the mode moves. Treating the Hessian as fixed would give zero and miss this contribution.
Practical Checks and Alternatives
In a GLMM, fixed effects usually enter the conditional response model, while covariance parameters enter the random-effects density and its normalizing terms. A covariance parameter may also alter the curvature in random-effects directions. The formula is unchanged: form \(h\) with all parameter-dependent terms included, differentiate the mode equation, and differentiate the Hessian at the resulting mode. If a covariance matrix is parameterized through log standard deviations or a Cholesky factor, apply the chain rule from the chosen unconstrained parameters to the covariance entries.
Useful checks include verifying that the fitted score \(h_u\) is close to zero, that the Hessian at the mode is positive definite, and that the mode sensitivity solves \(H(d\hat{u}/d\theta)=h_{u\theta}\). Compare analytic derivatives with centered finite differences of the same log Laplace approximation, re-optimizing the mode at each perturbed parameter value. A disagreement can indicate an incorrect sign, an omitted density normalizer, a failure to update the mode, or a numerical mode that has not converged. Near-zero Hessian eigenvalues make both \(H^{-1}\) and the derivative sensitive to numerical error; a nearly singular or non-positive-definite Hessian is a warning that the local approximation or mode calculation is unreliable.
Analytic differentiation is efficient and avoids finite-difference step-size choices, but it requires correct mixed and third derivatives when the Hessian depends on the mode. Finite differences are easier to implement but can be noisy and costly because each evaluation may require a new mode search. Repeated adaptive quadrature instead approximates the integrated likelihood directly and can provide a useful comparison when feasible, but requires its own numerical convergence checks. These approaches do not remove the need to check whether the mode and curvature underlying a Laplace approximation are well behaved.
Check Your Understanding
Try each question, then compare your work with the solutions.
- In one dimension, \(H=2\) and \(h_{u\theta}=3\) at the mode. What is \(d\hat{u}/d\theta\)?
- Suppose \(H\) has no direct dependence on \(\theta\), but \(H_u=0.4\) and \(d\hat{u}/d\theta=2\). Find \(dH/d\theta\).
- For the Gaussian random-intercept example, what derivative would result from omitting the log-determinant term when differentiating with respect to \(v\)?
- Name two conditions that make the ordinary derivative formula unreliable near the fitted parameter value.
Solutions. (1) The mode sensitivity is \(H^{-1}h_{u\theta}=3/2=1.5\). (2) The total derivative is \(H_\theta+H_u(d\hat{u}/d\theta)=0+0.4(2)=0.8\). (3) Omitting the determinant term gives only \(h_v=-0.0800\), rather than the correct \(-0.0550\). (4) Examples include a singular or non-positive-definite Hessian, a boundary mode, and a failure of the mode to be isolated and smooth as the parameter changes.