Marginal likelihood of mixed-effects models
Source:vignettes/articles/methods-nlme.Rmd
methods-nlme.Rmdem() maximizes the marginal likelihood of nonlinear
mixed-effects models. Guide: Nonlinear
mixed-effects models.
Marginal likelihood
Group \(i\) of \(G\) has random effects \(\eta_i \in \mathbb{R}^K\), inner parameters \(\phi_i = h(\theta, \eta_i)\) and the observation model
\[\begin{aligned} y_{ij} &= g\bigl(x(t_{ij};\, \phi_i)\bigr) + \varepsilon_{ij}, \\ \varepsilon_{ij} &\sim \mathcal{N}\bigl(0, \sigma^2(\phi_i, t_{ij})\bigr), \qquad \eta_i \sim \mathcal{N}(0, \Omega), \end{aligned} \tag{1}\]
with population parameters \(\psi = (\theta, \Omega, \sigma)\), and
\[\ell(\psi) = \sum_{i=1}^G \log L_i(\psi), \qquad L_i(\psi) = \int p(y_i \mid \eta_i, \psi)\, p(\eta_i \mid \Omega)\, \mathrm{d}\eta_i . \tag{2}\]
The integrand is normL2(data, g * x * p, errmodel = e),
with sensitivities in \(\eta_i\) by the
chain rule, plus the prior \(\sum_i
\eta_i^\top \Omega^{-1} \eta_i + G \log \lvert \Omega \rvert\)
from randomEffects(p). Conditions without a group add their
\(-2 \log L\) unchanged.
normT(..., df = 4) gives Student-t residuals.
EM algorithm
With the posterior \(q_i(\eta_i) = p(\eta_i \mid y_i, \psi^{(t)})\), Jensen’s inequality gives [1]
\[\log L_i(\psi) \ge \underbrace{\mathbb{E}_{q_i}\bigl[\log p(y_i, \eta_i \mid \psi)\bigr]}_{Q_i(\psi \mid \psi^{(t)})} - \mathbb{E}_{q_i}\bigl[\log q_i(\eta_i)\bigr], \tag{3}\]
with equality at \(\psi = \psi^{(t)}\). EM alternates forming \(Q = \sum_i Q_i\) and maximizing it, so \(\ell\) never decreases; near the optimum it converges linearly at the fraction of missing information. ECM [2] splits the M-step into conditional steps, ECME [3] takes some of them on the likelihood itself: \(\Omega\) in closed form, structural parameters by optimization. Sparsity priors minimizes \(-2Q\) instead. The methods replace the posterior, which has no closed form, by:
| method | posterior and expectation | M-step | reported \(-2 \log L\) |
|---|---|---|---|
"focei" |
Gaussian at the mode | trust region, Laplace | Laplace |
"quadrature" |
adaptive sparse grid at the mode | trust region, frozen nodes | quadrature |
"laplaceEM" |
Laplace moments, nodes of degree 3 | ECME | quadrature, level \(K + 2\) |
"saem" |
Metropolis draws, averaged | closed form, averaged Newton | quadrature, level \(K + 2\) |
FOCEI
Laplace approximation
With \(\Phi_i(\eta) = -2 \log p(y_i \mid \eta, \psi) - 2 \log p(\eta \mid \Omega) - K \log(2\pi)\), the prior without the constant of the normal density, mode \(\hat\eta_i\) and the Gauss-Newton curvature \(H_i\) of \(\Phi_i\) at \(\hat\eta_i\), Laplace’s approximation of (2) is \(-2 \log L_i \approx \Phi_i(\hat\eta_i) + \log \lvert H_i/2 \rvert\), the constant canceling against that of the Gaussian integral. FOCEI minimizes
\[F(\psi) = \sum_i \Bigl[ \Phi_i(\hat\eta_i) + \log \lvert H_i/2 \rvert \Bigr] \tag{4}\]
plus the full \(-2 \log L\) of the conditions without a group. \(\log \lvert H_i/2 \rvert\) is the volume term. \(H_i\) includes the derivatives of \(\sigma\) in \(\eta\), the interaction of FOCEI [4], [5]. Conditional standard errors of the modes are the square roots of the diagonal of \(2 H_i^{-1}\). The error has either sign and order \(1 / n_i\) for \(n_i\) data points in the group, with a factor that grows with \(K\).
Bilevel optimization
Each evaluation, in C++:
-
Modes. One trust region per group, Gauss-Newton
with SR1 correction, started from the last modes moved to first order
along the outer step, stopped at
innerControl$steptol; eigenvalue floor \(10^{-10} \operatorname{tr}(H_i)/K\); trial points of all groups in one batched prediction. - Gradient. By the envelope theorem the mode shift drops out: \(\nabla_\psi F = \sum_i \nabla_\psi \Phi_i \big|_{\hat\eta_i} + \sum_i \mathrm{d} \log \lvert H_i \rvert / \mathrm{d}\psi\), with a Newton correction for the gradient left by the inner search.
- Model Hessian. Gauss-Newton Schur complement \(\sum_i [\Phi_i^{\psi\psi} - \Phi_i^{\psi\eta} (\Phi_i^{\eta\eta})^{-1} \Phi_i^{\eta\psi}]\), plus the volume-term Hessian with second-order sensitivities, plus SR1 from the last three accepted gradients.
-
Stop. Model gain below
trustControl$mtolin the regionrmax, or five rejected trials flat withinftol. -
Hessian source. With several groupings the outer
loop is
trust(), andtrustControltakes the arguments oftrust(),phasesamong them. A handover from Gauss-Newton to BFGS, after 20 iterations or at a stalled radius (Methods > Trust region), reaches the optima of Gauss-Newton on the theophylline, warfarin and mavoglurant fits ofbench/nlme/with more iterations and time: the evaluation builds the Gauss-Newton Hessian for the modes and the volume term anyway, so a BFGS step costs as much as a Gauss-Newton step. -
Sparsity.
sparse = TRUE: the same outer loop on sparse outer Hessians, Schur complement and volume term of a group local to the parameters of the group, or, where the \(n_g\) entries of \(\psi\) a group couples satisfy \(n_g^2 > k\, n_\psi\) with \(n_\psi\) the number of entries of \(\psi\), as a low-rank part of rank \(k\): \(k = K\) for the Schur complement, \(k = 2K + K^2\) for the volume term.
Group kernel
One C++ kernel evaluates all groups at once: the modes, the local model of each group and the integral on it. At the mode, \(\Phi_i(\hat\eta_i + \delta) \approx \Phi_i(\hat\eta_i) + g_i^\top \delta + \tfrac12 \delta^\top H_i \delta\), \(g_i\) the gradient the inner search leaves. The block \(H_{NN}\) of the normal random effects is factored once; eliminating it gives the outer model, \(\Phi_i^{\psi\psi} - \Phi_i^{\psi N} H_{NN}^{-1} \Phi_i^{N\psi}\), and the curvature \(H_{LL} - H_{LN} H_{NN}^{-1} H_{NL}\) left on the other coordinates \(L\). An integrator maps the local model to the term \(-2 \log L_i - \Phi_i(\hat\eta_i)\) and to the derivative \(W_i\) of the term in \(H_i\), which the volume derivative (5) contracts with \(\mathrm{d} H_i / \mathrm{d}\psi\). FOCEI is Laplace on the normal block: the term \(\log \lvert H_{NN}/2 \rvert\) and \(W_i = H_{NN}^{-1}\).
Volume term
For Gauss-Newton \(H_i\), from second-order sensitivities,
\[\frac{\mathrm{d} \log \lvert H_i \rvert}{\mathrm{d} \psi_k} = \operatorname{tr}\Bigl(H_i^{-1} \frac{\partial H_i}{\partial \psi_k}\Big|_\eta\Bigr) + \sum_l \operatorname{tr}\Bigl(H_i^{-1} \frac{\partial H_i}{\partial \eta_l}\Bigr) \frac{\mathrm{d} \hat\eta_l}{\mathrm{d} \psi_k}, \qquad \frac{\mathrm{d}\hat\eta}{\mathrm{d}\psi} = -(\Phi_i^{\eta\eta})^{-1} \Phi_i^{\eta\psi}, \tag{5}\]
control |
volume term |
|---|---|
derivMode = "forward-reverse" (default) |
traces from one forward pass and a backward sweep (Sensitivities); exact gradient, curvature by SR1 |
derivMode = "forward-forward" |
second-order sensitivities; exact gradient, curvature without third-order terms |
secondOrderCorrection = FALSE |
derivative dropped; biased estimates |
Where the model is built with "forward-forward", the
reported Hessian has the exact Schur complement and the curvature of the
volume term without third-order sensitivities, as summary()
states. For \(\sigma\) depending on
\(\eta\), quadrature gives better
standard errors of \(\Omega\).
Adaptive sparse-grid quadrature
Laplace biases \(\Omega\) for skewed posteriors, as for oral doses sampled near absorption. The cubature \(\int e^{-\Phi_i/2}\, \mathrm{d}\eta \approx \sum_b W_b\, e^{-\Phi_i(\eta_b)/2}\) removes that error level by level. It combines the nested Genz-Keister rules [6], 1, 3, 9, 19 and 35 points exact to degree 1, 5, 15, 29 and 51, by Smolyak’s sparse grid [7], [8],
\[A(L, K) = \sum_{\lvert \mathbf{i} \rvert \le L} \Delta^{i_1} \otimes \cdots \otimes \Delta^{i_K}, \tag{6}\]
\(\Delta^l\) the difference of the
one-dimensional rules of levels \(l\)
and \(l - 1\). Level \(L\) is exact for total degree \(2(L - K) + 1\) against the Gaussian, with
nodes polynomial in \(K\) (for \(K = 3\), levels 3 to 7 have 1, 7, 19, 45,
117); level \(K\) is the single Laplace
node. The grid sits on the FOCEI Gaussian \(\mathcal{N}(\hat\eta_i, 2 H_i^{-1})\) and
moves with \(\psi\) [9].
Negative weights make \(\log L_i\) a
signed log-sum-exp; a nonpositive sum, an unresolved posterior, fails
the evaluation, naming the group. The gradient is the quadrature of the
exact gradient of \(\log L_i\) on the
current nodes (Fisher’s identity), the Hessian follows by Louis’
identity from data Hessians per node that are exact where the model is
built with "forward-forward" and Gauss-Newton otherwise;
the move of the grid with \(\psi\) is
not differentiated.
method = "quadrature" starts from the converged FOCEI
fit and alternates:
-
Rebuild. Grids at the current \(\psi\), at the lowest level (never falling)
whose error is at most
tolover the number of groups. The error of level \(l\) is estimated by \(2\lvert \log L_i^{(l+1)} - \log L_i^{(l)} \rvert\). A level of more thanmaxNodesnodes per group (default 1000) is never evaluated; there the estimate is the change from level \(l - 1\), and a group above the tolerance is capped at \(l\). For \(K = 20\) levels \(K + 1\) to \(K + 3\) have 41, 801 and 10041 nodes, so the default budget ends at \(K + 2\). - Step. Trust region over all parameters on frozen nodes. For mu-referenced fixed effects, \(\phi_i = D_i \beta + \eta_i\), nodes are frozen in \(\phi\), need no sensitivities and hold over larger steps.
-
Stop. A Newton step on the rebuilt nodes would gain
less than
tolDecrement, or \(-2 \log L\) rose after a step on unchanged levels, so the step lies below what the levels resolve. Either way the fit is stationary at the levels reached, capped ones included; it returns the iterate of lowest \(-2 \log L\) on the highest levels, and the stage trace records the levels, errors and caps per group.
At the estimate, importance sampling (\(t_5\) proposal at the mode, shifted lattice points) flags groups whose two estimates differ by more than three standard errors plus the level error, or with Pareto shape [10] above 0.7.
Laplace EM
method = "laplaceEM" runs ECME: a trust-region run of at
most maxCm1Iter (30) iterations of the structural
parameters on the likelihood over frozen nodes of level \(K + 1\), then every block of \(\Omega\) from \(S
= G^{-1} \sum_i M_i\) with the posterior second moments \(M_i = \hat\eta_i \hat\eta_i^\top + 2
H_i^{-1}\) (modes alone would shrink \(\Omega\)). It stops when parameter change
and extrapolated remaining distance are below epsEcm
(default 1e-5), or after maxEcm (200)
iterations. Settings come from control$quadrature.
SAEM
method = "saem" uses posterior draws, with no Gaussian
assumption and equal cost for any \(K\). Stochastic-approximation EM [11]
averages the sufficient statistics by a Robbins-Monro recursion [12],
\[s_k = s_{k-1} + \gamma_k \bigl( S(y, \eta^{(k)}) - s_{k-1} \bigr), \qquad \eta^{(k)} \sim q(\cdot \mid \psi^{(k-1)}), \qquad \psi^{(k)} = \hat\psi(s_k), \tag{7}\]
converging to a stationary point of \(\ell\) [11], [13]. \(\Omega\) follows from \(\sum_i \eta_i \eta_i^\top\), mu-referenced fixed effects by generalized least squares, other structural parameters from an average of quadratic models at the draws, whose Newton step has the marginal score as fixed point.
| phase | rule |
|---|---|
| draws | few random-walk Metropolis steps and independence proposals from
\(\mathcal{N}(\hat\eta_i, 1.5 \cdot 2
H_i^{-1})\) [13]; set.seed()
reproduces |
| burn-in |
\(\gamma_k = 1\), variances shrink
at most 5 % per iteration; ends when no parameter drifts over
window
|
| averaging |
\(\gamma_k = k^{-0.7}\), \(k\) counted from the end of burn-in, mean
of iterates [14]; ends when the
expected Monte Carlo rise of \(-2 \log
L\) is below mcTol
|
SAEM neither forms \(\ell\) nor
raises it in every iteration; em() reports the quadrature
of level \(K + 2\) with standard errors
from the quadrature Hessian. SAEM suits many random effects and skewed,
heavy-tailed or multimodal posteriors [13].
Spike-and-slab random effects
A spike-and-slab random effect \(\eta_{ij} = z_{ij} v_{ij}\) has an indicator \(z_{ij}\) with \(\Pr(z_{ij} = 1) = p\) and a slab value \(v_{ij} \sim \mathcal{N}(0, \tau^2)\) [15], [16]. Per iteration, after the normal random effects:
Local model. Per group the quadratic model of the data term in the slab values, with the curvature clipped to be positive semidefinite, refreshed at the mean of the slab-only Gaussian.
-
Collapsed indicator moves. Each indicator of a group once per sweep, in random order, all groups at once. The other slab values of the group move with \(v_{ij}\) along the regression of the local model, \(v_o = b_o + x\,u_o\), so the state \(b\) with \(z_{ij} = 0\) and the line stay fixed. On this line the slab mass \(I = \int f(x)\,dx\), \(f\) the joint density of data and prior, is a Gauss-Hermite sum on the local Gaussian \(\mathcal{N}(m, s^2)\) with the exact data term at
nodes(3) points, which gives the conditional inclusion probability with the slab value integrated out [17],\[\hat\pi_{ij} = \frac{I}{I + f_0}, \qquad f_0 = f \text{ at } z_{ij} = 0 . \tag{8}\]
The proposal draws \(z_{ij}\) with probability \(0.01 + 0.98\,\hat\pi_{ij}\) and \(x\) from \(\mathcal{N}(m, 1.5\,s^2)\), independently of the current state; an independence Metropolis-Hastings step [18] on \((z_{ij}, x)\) against the model leaves the exact posterior invariant, whatever the error of the sum.
Slab values.
nMcmcjoint random-walk Metropolis steps of the slab values of every group in the slab, scaled by the conditional standard deviations of the local model.A-step and M-steps. \(p\) and \(\tau\) follow from Robbins-Monro averages of \(\sum \hat\pi_{ij}\) and \(\sum \hat\pi_{ij}\,\mathbb{E}(x^2 \mid z_{ij} = 1)\), the Rao-Blackwellized statistics [19] of the sweep, in place of the drawn indicators. An effect the data do not inform has \(\hat\pi_{ij} = p\) and second moment \(\tau^2\) and leaves both unchanged; counts of drawn indicators would instead let \(p\) wander to 1 in burn-in, where \(\gamma_k = 1\). In burn-in the odds \(p / (1 - p)\) and \(\tau\) change by a factor in \([0.95, 1.25]\) per iteration.
\(p_0\) is one minus the mean of
\(\hat\pi_{ij}\) over the late sweeps,
an effect selected where it is below 1/2. An em fit as
init starts the chain at the selected values of that fit,
the indicators set where they are not 0, which checks a FOCEI optimum by
SAEM. \(-2 \log L\) at the estimate is
that of method = "focei"; with Dirichlet-process random
effects beside on more than 14 groups, or with
integral = "importance", it comes from sequential
importance sampling over the partitions (Sparsity
priors), each group summing over the subsets of the spike-and-slab
effects that reach the group data.
Zero variance components
An unsupported variance runs to 0, minus infinity on the log scale.
With one grouping and several blocks, a normal random effect alone in a
block whose estimated standard deviation ends below 0.1 is therefore
refitted at 0. If \(-2 \log L\) rises
by at most control$boundary, the refit is returned, the
variance named in boundary.