Documentation

A.10 Stochastic approximation: SAEM, Metropolis–Hastings and the M-step

One SAEM iteration

What you will learn

  • State the EM idea for a mixed-effects model and why SAEM replaces its expectation with simulation and averaging.
  • Write the three Metropolis–Hastings kernels of SAEM and derive their acceptance probabilities.
  • Derive the closed-form update of \(\Omega\) from the sufficient statistics, and the Robbins–Monro step-size rule.
  • Explain why the SAEM objective that is printed is not a likelihood.

Prerequisites: A.4, A.6 and A.8.

The EM idea

If the random effects \(\eta_i\) were observed, estimation would be easy: the complete-data objective \(J_i(\eta;\psi)\) (page A.6) would be minimised over \(\psi\) directly. They are not. The expectation–maximisation (EM) algorithm alternates:

Step Action
E compute the expected complete-data objective \(Q(\psi)=\sum_i\mathbb E\bigl[J_i(\eta;\psi)\mid y_i,\psi_{\text{old}}\bigr]\)
M minimise \(Q\) over \(\psi\)

For a nonlinear model the expectation has no closed form. SAEM (stochastic approximation EM, Kuhn and Lavielle) approximates it in two ways: it simulates \(\eta_i\) from its conditional distribution \(p(\eta\mid y_i,\psi)\propto e^{-J_i(\eta)/2}\) with a Markov chain, and it averages the result over iterations with a decreasing step size, so that the Monte Carlo noise averages out instead of having to be driven to zero by a large sample at each step.

The Metropolis–Hastings kernels

Each subject keeps ISAMPLE chains (2 by default) of \(\eta\). For a chain at \(\eta\) a kernel proposes \(\eta'\) and accepts with probability \(\alpha\). The target is \(\pi(\eta)\propto e^{-J(\eta)/2}\) with \(J=J^y+\eta^{\mathsf T}\Omega^{-1}\eta\), where \(J^y=\sum_jc_{ij}\) is the data part. Let \(L_\Omega\) be the Cholesky factor of \(\Omega\).

Kernel Proposal Acceptance probability
Prior (ISAMPLE_M1, default 2 draws) \(\eta'=L_\Omega z\), \(z\sim N(0,I)\) \(\min\bigl\{1,\ e^{-(J^y(\eta')-J^y(\eta))/2}\bigr\}\)
Random walk (ISAMPLE_M2, 2) \(\eta'=\eta+s_2L_\Omega z\) \(\min\bigl\{1,\ e^{-(J(\eta')-J(\eta))/2}\bigr\}\)
Component-wise (ISAMPLE_M3, 2 sweeps) \(\eta'_a=\eta_a+s_{3,a}\sqrt{\omega_{aa}}\,z\), one component at a time as for the random walk

Why the prior kernel's ratio contains only \(J^y\). The Metropolis–Hastings ratio is \(\dfrac{\pi(\eta')\,q(\eta\mid\eta')}{\pi(\eta)\,q(\eta'\mid\eta)}\). The proposal \(q(\eta'\mid\eta)=N(\eta';0,\Omega)\) does not depend on \(\eta\) and is proportional to \(e^{-\eta'^{\mathsf T}\Omega^{-1}\eta'/2}\), which is exactly the prior factor in \(\pi(\eta')\). The two cancel, and what remains is the ratio of the data factors, \(e^{-(J^y(\eta')-J^y(\eta))/2}\). For the random walk and component-wise kernels the proposal is symmetric, \(q(\eta'\mid\eta)=q(\eta\mid\eta')\), so it cancels and the full ratio \(e^{-(J(\eta')-J(\eta))/2}\) remains.

The prior kernel explores the whole population distribution (good for finding the right region), the random walk makes local moves (good for refining), and the component-wise kernel moves one ETA at a time (good when the ETAs are poorly scaled together). The scales \(s_2,s_{3,a}\) adapt to a target acceptance rate IACCEPT (0.4):

\[ s\leftarrow s\,\bigl(1+0.4\,(\text{acc}-\mathrm{IACCEPT})\bigr),\qquad s\in[0.01,\ 10]. \]

With an observed acceptance of 0.25, \(s\leftarrow s\times0.94\) (smaller steps); with 0.55, \(s\leftarrow s\times1.06\).

A worked illustration

One Metropolis–Hastings move for the appendix subject. The current state is \(\eta=-0.2\), with \(J^y(-0.2)=-0.4962\) and \(J(-0.2)=-0.0517\) (page A.3); the prior SD is \(L_\Omega=\sqrt{0.09}=0.3\).

Kernel Proposal draw \(\eta'\) Objective at \(\eta'\) Acceptance probability
prior, \(z=-1\) \(0.3\times(-1)\) −0.30 \(J^y=-4.023\) \(\min(1,e^{+1.76})=1\)
prior, \(z=-0.5\) \(0.3\times(-0.5)\) −0.15 \(J^y=3.318\) \(e^{-1.907}=0.149\)
random walk, \(s_2=0.5\), \(z=-0.8\) \(-0.2+0.5\times0.3\times(-0.8)\) −0.32 \(J=-3.156\) \(1\)
random walk, \(s_2=0.5\), \(z=+0.8\) \(-0.2+0.5\times0.3\times0.8\) −0.08 \(J=12.574\) \(e^{-6.31}=0.0018\)

The target is sharply peaked (its SD is about 0.09, page A.8), so a proposal that moves \(\eta\) upward by 0.12 — a little more than one posterior SD, away from the data — is nearly always rejected, and one that moves toward the mode is accepted. The acceptance rate over many proposals is what the scale adaptation steers toward 0.4.

Sufficient statistics and the step size

For the complete-data model, the information about \(\Omega\) in the simulated \(\eta\) is carried by the sufficient statistics: the average of the (centred) random effects \(S_1\) and the average of their outer products \(S_2\). With \(x_i=\eta_i+c\), where \(c_a=\mu_a\) for an effect whose THETA is linked to its ETA through a mu-reference and \(0\) otherwise,

\[ S_1\leftarrow S_1+\gamma_k\bigl(\bar x-S_1\bigr),\qquad S_2\leftarrow S_2+\gamma_k\bigl(\overline{xx^{\mathsf T}}-S_2\bigr), \]

with \(\bar x\) and \(\overline{xx^{\mathsf T}}\) the averages over the current draws (all subjects and chains). This is a Robbins–Monro update, and the step size \(\gamma_k\) is the key to SAEM:

Phase \(\gamma_k\) Effect
Burn-in 1 the statistics are replaced by the current draws: fast movement toward the right region, noisy
Accumulation \(1/k'\), \(k'=1,2,\dots\) the statistics become the running average of all draws since accumulation began: the noise averages out

Worked illustration. Suppose the draw averages over four accumulation iterations are \(0.10,\ -0.04,\ 0.07,\ 0.01\). With \(\gamma=1,\ \tfrac12,\ \tfrac13,\ \tfrac14\) the statistic goes \(0.100\to0.030\to0.0433\to0.0350\), which is exactly the arithmetic mean of the four, \((0.10-0.04+0.07+0.01)/4=0.0350\). A schedule \(\gamma_k=1/k'\) is the one for which the running average is the plain mean; it satisfies the Robbins–Monro conditions \(\sum\gamma_k=\infty\) and \(\sum\gamma_k^2<\infty\) that make the iteration converge.

The M-step

\(\Omega\) in closed form. The complete-data objective for \(\Omega\) is \(N\log\lvert\Omega\rvert+\operatorname{tr}\bigl(\Omega^{-1}\sum_i\eta_i\eta_i^{\mathsf T}\bigr)\) (page A.3). Setting its gradient \(N\Omega^{-1}-\Omega^{-1}\bigl(\sum\eta\eta^{\mathsf T}\bigr)\Omega^{-1}\) to zero gives \(\Omega=\tfrac1N\sum\eta\eta^{\mathsf T}\). In terms of the statistics,

\[ \Omega=S_2-cS_1^{\mathsf T}-S_1c^{\mathsf T}+cc^{\mathsf T}\quad\text{(for the estimated elements)}, \]

with SAME blocks pooled by the mean over the tied blocks. Illustration: four subjects with simulated \(\eta=(-0.35,\ 0.10,\ 0.42,\ -0.12)\) and \(c=0\) have \(S_1=0.0125\) and \(S_2=0.0808\), so \(\Omega=0.0808\) (an SD of 0.284).

Annealing. In the first half of burn-in a variance may shrink by at most 5 % per iteration (\(\omega_{kk}\ge0.95\,\omega_{kk}^{\text{prev}}\)); this prevents an early collapse of a variance onto a handful of noisy draws. If the updated \(\Omega\) is not positive definite, its off-diagonal elements are shrunk until it is (page A.4).

MU-linked THETAs. When \(\varphi=g(\theta)+\eta\) with \(g=\log\) or the identity, the best \(\theta\) given the draws is \(g^{-1}\) of the mean of \(\varphi\): \(\mu_k=S_{1,k}\) and \(\theta=g^{-1}(\mu_k)\), within its bounds. Then the chains are shifted by \(\mu_{\text{old}}-\mu_{\text{new}}\) so that \(\theta+\eta\) is unchanged. This is why mu-referencing speeds SAEM up: a whole class of parameters is updated by averaging, with no optimisation.

The other THETAs and SIGMA. One Newton step on the sampled objective

\[ Q(\psi)=\sum_i\frac1C\sum_{c}\sum_jc_{ij}(\eta_{ic};\psi) \]

(the average over \(C\) chains) gives \(\psi^\ast\), and the Robbins–Monro update \(\psi_{k+1}=\psi_k+\gamma_k(\psi^\ast-\psi_k)\) moves toward it with the same step size.

Burn-in, accumulation and the stationarity test

Burn-in runs for at most NBURN iterations (1000), accumulation for NITER (300). A fixed burn-in is wasteful when the chain settles early and unsafe when it does not, so nlmx tests for stationarity: every 25 iterations after the first 100, over a window of the last \(w=\min(\max(k/3,50),200)\) iterations, each estimated parameter (transformed scale) and the SAEM objective is tested for a trend. The window is cut into 10 batch means; the least-squares slope of the batch means gets a \(t\) statistic, compared with the \(t_8\) critical value at the level \(0.05/m\) (a Bonferroni adjustment over the \(m\) series). Burn-in ends when no series trends.

The printed objective is not a likelihood

The SAEM objective that is printed during a run is

\[ \sum_i\frac1C\sum_c\bigl[J_i^y(\eta_{ic})+\eta_{ic}^{\mathsf T}\Omega^{-1}\eta_{ic}\bigr]+N\log\lvert\Omega\rvert, \]

the average complete-data objective at the sampled \(\eta\). It lacks the term \(-2\log\int\) that integrates over \(\eta\), so it cannot be compared across models and is not an OFV. It is a trace: it should fall during burn-in and fluctuate around a level afterwards. The OFV that is reported is the importance-sampling objective computed afterwards at the final estimates (page A.11).

Common mistakes

  • Comparing the printed SAEM trace across models, or treating it as an OFV.
  • Reading a flat trace as proof of convergence without looking at several chains or seeds: a seed makes a path reproducible, it does not make a poorly mixing chain mix.
  • Setting the burn-in by hand to a number that is too small for the model. The stationarity test is there for that case.

Review checklist

  • Can you derive the prior kernel's acceptance ratio?
  • Can you state the step-size rule and say what changes between burn-in and accumulation?
  • Can you derive \(\Omega=\tfrac1N\sum\eta\eta^{\mathsf T}\) from the objective?
  • Do you know why the printed SAEM objective is not comparable between models?

See the previous page, the next page and the mathematical reference.