Tutorials › Nonlinear Mixed-Effects Models (NLME) › Metropolis-Hastings Proposals for SAEM

The EM and SAEM Algorithms · Tutorial 206 of 797

Metropolis-Hastings Proposals for SAEM

Learn to build and verify Metropolis–Hastings updates for subject random effects using the current nonlinear mixed-effects model.

Advanced 12 min read

What You'll Learn

  • Write the conditional target density for a subject’s random effects.
  • Derive the Metropolis–Hastings acceptance probability, including the proposal correction.
  • Work through symmetric random-walk, asymmetric independence, and prior-based proposals.
  • Check proposal support, prior contributions, and calculations on the log scale.
  • Distinguish a valid MH transition from an exact independent draw from the conditional distribution.

Why SAEM Needs a Conditional Random-Effect Proposal

In a nonlinear mixed-effects model, the distribution of a subject’s random effects conditional on that subject’s observations is usually not available in a form that can be sampled from directly. SAEM can use a Markov chain to generate these latent effects: at each transition, it proposes a new value and accepts or rejects it according to a probability that preserves the required conditional distribution. The proposal can be convenient even when it is not itself a good approximation to that distribution, provided the acceptance probability accounts for the proposal correctly.

Consider subject \(i\), with observations \(y_i\), random effects \(b_i\), population parameters \(\theta\), and random-effect covariance matrix \(\Omega\). During a single SAEM simulation update, treat the observed data and current parameter values as fixed. Assume the subject’s random effects have density \(\phi(b_i;0,\Omega)\), and that the observation density conditional on the random effects is \(p(y_i\mid b_i;\theta)\). The subject-specific conditional distribution of interest is proportional to the product of these two densities.

Definition: The conditional random-effect target for subject \(i\), at fixed \(\theta\) and \(\Omega\), is $$ \pi_i(b_i\mid y_i;\theta,\Omega) = \frac{p(y_i\mid b_i;\theta)\,\phi(b_i;0,\Omega)} {\displaystyle \int p(y_i\mid u;\theta)\,\phi(u;0,\Omega)\,du}. $$ The denominator normalizes the density but is not needed in the Metropolis–Hastings ratio. A proposal density \(q_i(b_i^\star\mid b_i,y_i;\theta,\Omega)\) describes how a candidate \(b_i^\star\) is generated from the current value \(b_i\). All quantities in this update are evaluated at the current model parameters.

The target combines the likelihood contribution from the subject’s observations with the random-effects density. Using the likelihood alone would generally target the wrong distribution; using the random-effects density alone would ignore the information in the observations. The proposal need not equal the target, but it must have positive density wherever the target can require movement and the reverse move has positive probability.

Acceptance Probability and Its Justification

From current state \(b_i\), first draw a candidate \(b_i^\star\) from \(q_i(b_i^\star\mid b_i,y_i;\theta,\Omega)\). Then accept that candidate with probability \(\alpha_i(b_i,b_i^\star)\); otherwise retain the current state. The acceptance probability is

$$ \alpha_i(b_i,b_i^\star) = \min\left\{ 1,\, \frac{\pi_i(b_i^\star\mid y_i;\theta,\Omega)} {\pi_i(b_i\mid y_i;\theta,\Omega)} \frac{q_i(b_i\mid b_i^\star,y_i;\theta,\Omega)} {q_i(b_i^\star\mid b_i,y_i;\theta,\Omega)} \right\}. $$

The proposal-density ratio is essential when the proposal is not symmetric. Substituting the target density shows that its normalizing constant cancels:

$$ \alpha_i(b_i,b_i^\star) = \min\left\{ 1,\, \frac{p(y_i\mid b_i^\star;\theta)\,\phi(b_i^\star;0,\Omega)} {p(y_i\mid b_i;\theta)\,\phi(b_i;0,\Omega)} \frac{q_i(b_i\mid b_i^\star,y_i;\theta,\Omega)} {q_i(b_i^\star\mid b_i,y_i;\theta,\Omega)} \right\}. $$

A short balance argument explains why this rule preserves the conditional target. For two distinct states \(b_i\) and \(b_i^\star\), the probability flow under the target density from the first state to the second is proportional to

$$ \pi_i(b_i\mid y_i)\, q_i(b_i^\star\mid b_i,y_i)\, \alpha_i(b_i,b_i^\star) = \min\left\{ \pi_i(b_i\mid y_i)q_i(b_i^\star\mid b_i,y_i),\, \pi_i(b_i^\star\mid y_i)q_i(b_i\mid b_i^\star,y_i) \right\}. $$

The expression on the right is unchanged when \(b_i\) and \(b_i^\star\) are exchanged. Thus the flow in either direction is equal. Rejected proposals stay at the current state, supplying the probability of remaining there; together, these moves define a transition that leaves the conditional target invariant. This argument requires the proposal and target densities in the acceptance ratio to be well-defined on the states involved.

For computation, it is usually safer to work with the log of the ratio before applying the minimum. Define

$$ r_i = \log p(y_i\mid b_i^\star;\theta)-\log p(y_i\mid b_i;\theta) +\log\phi(b_i^\star;0,\Omega)-\log\phi(b_i;0,\Omega) +\log q_i(b_i\mid b_i^\star,y_i;\theta,\Omega) -\log q_i(b_i^\star\mid b_i,y_i;\theta,\Omega). $$

Then \(\alpha_i=\min\{1,\exp(r_i)\}\). If \(r_i\geq 0\), accept with probability one; if \(r_i<0\), accept with probability \(\exp(r_i)\). Drawing \(U\sim\mathrm{Uniform}(0,1)\), accept exactly when \(\log U<r_i\), with automatic acceptance when \(r_i\geq0\).

Worked Proposals in a Nonlinear Observation Model

The examples use a simple hypothetical model to make the likelihood calculations explicit. For one observation \(y\), suppose \(y\mid b\sim N(\exp(b),\sigma^2)\) and \(b\sim N(0,1)\). The observation mean depends nonlinearly on the scalar random effect. The conditional target is proportional to the normal observation density times the standard normal prior density. These examples illustrate proposal arithmetic, not results from a real study.

Worked Example: Symmetric Random-Walk Proposal

Suppose \(y=2.000\), \(\sigma=0.500\), and the current random effect is \(b=0.400\). Use a random-walk proposal \(b^\star=b+\varepsilon\), where \(\varepsilon\sim N(0,\tau^2)\), and consider the proposed value \(b^\star=0.600\). The proposal is symmetric because its density depends only on \(b^\star-b\), so \(q(b\mid b^\star)=q(b^\star\mid b)\) and the proposal correction is one.

The fitted means and residuals are \(\exp(0.400)=1.4918\), \(2.000-1.4918=0.5082\), \(\exp(0.600)=1.8221\), and \(2.000-1.8221=0.1779\). For a normal observation with fixed variance, the log-likelihood difference is

$$ \log\frac{p(y\mid b^\star)}{p(y\mid b)} = -\frac{(0.1779)^2-(0.5082)^2}{2(0.500)^2} \approx 0.4532. $$

The log-prior difference is \(-\{(0.600)^2-(0.400)^2\}/2=-0.1000\). Therefore \(r=0.4532-0.1000=0.3532\), and \(\alpha=\min\{1,\exp(0.3532)\}=1\). This proposal is accepted with probability one. The likelihood improves enough to outweigh the modest decrease in prior density.

Worked Example: Asymmetric Independence Proposal

Keep the same model, but take \(y=1.500\) and \(\sigma=0.500\). Let the current value be \(b=0.200\), and propose \(b^\star=0.400\) from an independence proposal \(q(x)=N(0.400,0.300^2)\). An independence proposal does not depend on the current state, but it is not symmetric: the density of proposing the current point from the candidate differs from the density of proposing the candidate from the current point.

Here \(\exp(0.200)=1.2214\) and \(\exp(0.400)=1.4918\), giving residuals \(0.2786\) and \(0.0082\). Thus the log-likelihood difference is

$$ -\frac{(0.0082)^2-(0.2786)^2}{2(0.500)^2} \approx 0.1551. $$

The log-prior difference is \(-\{(0.400)^2-(0.200)^2\}/2=-0.0600\). For the proposal correction, the proposal density at \(0.200\) is compared with its density at \(0.400\), the proposal mean. Their log-density difference is

$$ \log\frac{q(0.200)}{q(0.400)} = -\frac{(0.200-0.400)^2}{2(0.300)^2} \approx -0.2222. $$

The full log ratio is \(r=0.1551-0.0600-0.2222=-0.1271\), so \(\alpha=\exp(-0.1271)\approx0.8806\). If the uniform draw is \(U=0.9000\), the proposal is rejected because \(0.9000>0.8806\), and the chain remains at \(b=0.200\). Omitting the proposal correction would give a different, incorrect transition probability.

Worked Example: Proposing From the Random-Effects Prior

Suppose \(y=1.200\), \(\sigma=0.400\), the current value is \(b=0.000\), and a candidate \(b^\star=0.200\) is drawn from the prior \(q(b^\star)=N(0,1)\), independently of the current state. For this proposal, \(q(b)=\phi(b;0,1)\). The proposal-density ratio is therefore the prior-density ratio in reverse order, and it cancels the prior ratio in the target:

$$ \frac{\phi(b^\star;0,1)}{\phi(b;0,1)} \frac{q(b)}{q(b^\star)} = \frac{\phi(b^\star;0,1)}{\phi(b;0,1)} \frac{\phi(b;0,1)}{\phi(b^\star;0,1)} =1. $$

Only the likelihood ratio remains. The current fitted mean is \(\exp(0)=1.0000\), with residual \(0.2000\). The proposed fitted mean is \(\exp(0.200)=1.2214\), with residual approximately \(-0.0214\). Hence

$$ r = -\frac{(-0.0214)^2-(0.2000)^2}{2(0.400)^2} \approx 0.1236, \qquad \alpha=\min\{1,\exp(0.1236)\}=1. $$

The candidate is accepted with probability one. Drawing from the prior does not, by itself, produce a draw from the conditional distribution given the observation. The likelihood-based acceptance step is what adjusts for that difference.

Choosing and Checking a Proposal

Several proposals are useful, but they make different trade-offs. A symmetric random walk is straightforward because its proposal terms cancel. An independence proposal can aim at a region of high conditional density, but its potentially asymmetric density must be included in the ratio. A prior proposal also has a simple cancellation, leaving the likelihood ratio, but it may propose values poorly suited to the observations. Whenever a suitable conditional sampler is available, drawing directly from the conditional distribution avoids an MH accept-or-reject step; in nonlinear models such a sampler is often unavailable or computationally inconvenient.

ProposalProposal correctionPractical consideration
Symmetric random walkCancelsSimple ratio; proposal scale affects the size of candidate moves.
Independence proposalUsually does not cancelCan use a data-informed distribution; include both proposal densities.
Random-effects priorCancels the prior ratioEasy to generate; observations affect acceptance through the likelihood.
Direct conditional drawNo MH correctionRequires a method for sampling exactly from the conditional target.

Before using an MH update in SAEM, check that the likelihood is evaluated at both the current and proposed random effects, the prior contribution is included, and the proposal densities are in the correct order: reverse move in the numerator, proposed move in the denominator. Verify that any proposal density is positive for moves needed to explore the target’s support. For a multivariate random effect, ensure that likelihoods, prior densities, and proposal densities are evaluated for the full vector, with compatible covariance matrices and dimensions.

Calculate in log space when densities are very small, and check computations using simple limiting cases. For example, a symmetric proposal must have a zero log proposal correction, and a proposal equal to the prior must cancel the prior contribution. A common error is to accept a candidate whenever its likelihood is higher. That rule ignores both the prior and, for an asymmetric proposal, the proposal correction. A candidate with a lower likelihood can still be accepted; conversely, a higher likelihood does not guarantee acceptance when the prior or proposal correction offsets the gain.

An MH transition preserves the conditional target when its acceptance ratio is correct, but a single transition is not generally an independent draw from that target. Repeated proposals may be rejected, and the resulting chain can move slowly if the chosen proposal is poorly suited to the conditional distribution. The acceptance formula ensures the intended invariant distribution; it does not by itself guarantee that a finite run has adequately represented it.

Key takeaway: For each subject, form the target as likelihood times random-effects density, then multiply its proposed-to-current ratio by the reverse-to-forward proposal-density ratio. Symmetry is a special case, not an assumption to make without checking.

Check Your Understanding

For each question, identify the relevant ratio or calculation before reading the solution.

  1. Write the acceptance probability for a subject-specific random-effect proposal, naming the target and both proposal terms.
  2. For a symmetric random-walk proposal, which part of the acceptance ratio cancels, and what remains?
  3. If proposals are drawn independently from the random-effects prior, what happens to the prior-density contribution in the MH ratio?
  4. For a proposed move, suppose the log-likelihood difference is \(0.10\), the log-prior difference is \(-0.15\), and the log proposal correction is \(-0.20\). Find the acceptance probability.

Solutions. (1) Use \(\alpha=\min\{1,[\pi_i(b_i^\star\mid y_i)/\pi_i(b_i\mid y_i)] [q_i(b_i\mid b_i^\star,y_i)/q_i(b_i^\star\mid b_i,y_i)]\}\), where \(\pi_i\) is proportional to the subject likelihood times the random-effects density. (2) The forward and reverse proposal densities are equal, so their ratio is one; the likelihood and prior ratios remain. (3) The prior proposal ratio cancels the prior-density ratio in the target, leaving the likelihood ratio. (4) The full log ratio is \(r=0.10-0.15-0.20=-0.25\), so \(\alpha=\exp(-0.25)\approx0.7788\). The proposal is accepted with probability about \(0.779\), not with certainty.