Tutorials › Generalized Linear Mixed Models (GLMM) › Random-Walk Metropolis Proposal Tuning for Scale Parameters

Bayesian GLMM and Prior Specification for Variance Components · Tutorial 278 of 698

Random-Walk Metropolis Proposal Tuning for Scale Parameters

You will learn to propose positive variance components on a log scale, calculate the correct Metropolis–Hastings acceptance probability, and tune proposal size without treating acceptance rate as the sole measure of performance.

Advanced 12 min read

What You'll Learn

  • Transform a positive variance component to an unconstrained log scale.
  • Include the change-of-variables Jacobian in the transformed posterior target.
  • Calculate random-walk Metropolis acceptance probabilities and example chain steps.
  • Use observed acceptance behavior to adjust a scalar proposal scale.
  • Recognize why additive proposals can perform poorly near zero.
  • Compare log-scale random walks with truncated proposals and other samplers.

Why proposal scale matters

A random-walk Metropolis update proposes a nearby value for a parameter and then accepts or rejects it according to the target posterior density. For a variance component, proposal design has an additional constraint: the parameter must remain positive. A proposal that is too small may be accepted often but explore the posterior slowly; one that is too large may be rejected frequently. Tuning is therefore a balance between making useful moves and retaining a reasonable chance of acceptance.

This tutorial focuses on a scalar positive variance component, such as a random-intercept variance \(v\). At a given update, all other model parameters are held fixed. Write \(z\) for those parameters and \(y\) for the observed data. The target for this update is the conditional posterior density \(\pi(v\mid z,y)\), known up to a normalizing constant. The same method applies to a positive scale parameter, but the transformation and interpretation should match the parameter being updated.

Definition: A log-scale random-walk Metropolis proposal for \(v>0\) sets \(\eta=\log v\), proposes \(\eta'=\eta+\epsilon\) with \(\epsilon\sim N(0,s^2)\), and sets \(v'=\exp(\eta')\). The proposal scale \(s>0\) controls the typical size of changes on the log scale.

The transformed target and acceptance probability

The random walk is symmetric in \(\eta\), not in \(v\). The density to use for the Metropolis–Hastings calculation must therefore be the posterior density of \(\eta\). Since \(v=\exp(\eta)\) and \(dv/d\eta=\exp(\eta)=v\), change of variables gives

$$ \pi_\eta(\eta\mid z,y) = \pi_v(\exp(\eta)\mid z,y)\exp(\eta). $$

The factor \(\exp(\eta)\) is the Jacobian. Omitting it generally changes the target distribution and produces the wrong posterior for \(v\).

Because the proposal density for \(\eta'\) given \(\eta\) is the same as the reverse proposal density, the Metropolis–Hastings acceptance probability is

$$ \alpha(\eta,\eta') = \min\left\{1,\, \frac{\pi_\eta(\eta'\mid z,y)} {\pi_\eta(\eta\mid z,y)} \right\} = \min\left\{1,\, \frac{\pi_v(v'\mid z,y)v'} {\pi_v(v\mid z,y)v} \right\}. $$

In computation, use the log target \(\ell_\eta(\eta)=\log\pi_v(\exp(\eta)\mid z,y)+\eta\), up to an additive constant. The log acceptance ratio is \(\ell_\eta(\eta')-\ell_\eta(\eta)\). Accept if \(\log U\) is no greater than this ratio, where \(U\sim\operatorname{Uniform}(0,1)\); otherwise retain the current value. This log comparison avoids numerical underflow.

Justification: The transformed proposal is symmetric, so the ordinary Metropolis ratio uses \(\pi_\eta\). For a move from \(\eta\) to \(\eta'\), the posterior flow in that direction is proportional to \(\pi_\eta(\eta)q(\eta'\mid\eta)\alpha(\eta,\eta')\), which equals \(q(\eta'\mid\eta)\min\{\pi_\eta(\eta),\pi_\eta(\eta')\}\). Symmetry of \(q\) makes this equal to the reverse flow. Thus the transformed target is invariant under the update, and mapping back by \(v=\exp(\eta)\) gives the intended conditional posterior for \(v\).

This argument assumes that the conditional posterior is proper and has a density on the positive values being explored, and that its density can be evaluated up to a constant. A normal random walk on the whole real line can reach any finite \(\eta\) from any other, which corresponds to reaching any positive \(v\). These facts establish the proposal’s basic validity; they do not ensure that a finite chain explores the target efficiently.

Worked Example: Calculating a Log-Scale Acceptance Probability

Suppose, for illustration, that the conditional posterior of a variance component has a Gamma density with shape 2 and rate 3: \(\pi_v(v)\propto v^{2-1}\exp(-3v)\), for \(v>0\). This is a hypothetical target used to show the calculation. The transformed target is proportional to \(v^2\exp(-3v)\), because the Jacobian contributes one additional factor of \(v\).

Start at \(v=0.5000\), so \(\eta=\log(0.5)=-0.6931\). With proposal scale \(s=0.4\), suppose the proposed increment is \(+0.4\). Then \(\eta'=-0.2931\) and \(v'=\exp(-0.2931)\approx0.7459\).

Ignoring constants common to both states, the transformed log target is \(\ell_\eta(\eta)=2\eta-3\exp(\eta)\). The log acceptance ratio is

$$ \ell_\eta(\eta')-\ell_\eta(\eta) =2(0.4)-3(0.7459-0.5000) =0.0623. $$

Since the ratio is positive, \(\alpha=\min\{1,\exp(0.0623)\}=1\). This proposal is accepted regardless of the uniform draw. The calculation uses the transformed target; using only the Gamma density in \(v\) would omit the Jacobian.

Choosing the proposal scale

The scale \(s\) is measured in units of \(\log(v)\), so it controls multiplicative rather than fixed additive changes in \(v\). For example, an increment of \(0.4\) multiplies \(v\) by \(\exp(0.4)\approx1.492\), while an increment of \(-0.4\) multiplies it by \(\exp(-0.4)\approx0.6703\). The relative size of a proposal is therefore similar whether \(v\) is near 0.1 or near 10.

A practical tuning procedure uses short pilot runs at a fixed conditional update, recording both the acceptance fraction and the actual scale of movement. If nearly every proposal is accepted but values change only slightly, try increasing \(s\). If proposals are rejected very often, try decreasing \(s\). For a scalar random walk, acceptance fractions somewhere around 0.3–0.5 are often a useful starting heuristic, not a universal optimum or a guarantee of good exploration. Posterior shape, dependence on other parameters, and the quantity of interest all matter.

Worked Example: Comparing Pilot Acceptance Rates

In a hypothetical pilot for one positive variance component, three proposal scales are each tried for 600 updates, with the same conditional target and comparable starting conditions. The observed counts are: 570 accepted at \(s=0.05\), 300 at \(s=0.40\), and 126 at \(s=1.20\).

The acceptance fractions are \(570/600=0.950\), \(300/600=0.500\), and \(126/600=0.210\), respectively. The very high rate at \(s=0.05\) indicates that most proposals are accepted, but each changes \(\eta\) by little. The \(s=1.20\) proposals are much larger and are rejected more often. The intermediate scale has a 0.500 acceptance fraction, which is a reasonable candidate for a further pilot.

This comparison does not prove that \(s=0.40\) gives the best posterior summaries. Acceptance counts alone do not measure how far accepted moves travel or how efficiently the chain explores the target. The appropriate conclusion is narrower: among these three tested values, \(s=0.40\) is a sensible scale to investigate further, rather than assuming that either the highest or the lowest acceptance fraction is best.

A single transition sequence makes the role of acceptance concrete. Under the Gamma target above, from \(\eta=-0.6931\), the proposed increment \(+0.4\) has acceptance probability 1 and moves to \(-0.2931\). From there, suppose the next increment is \(+0.8\), giving \(\eta'=0.5069\), or \(v'\approx1.660\). Its log acceptance ratio is approximately \(2(0.8)-3(1.660-0.7459)=-1.142\), so its acceptance probability is \(\exp(-1.142)\approx0.319\). If the generated uniform value is \(U=0.50\), the proposal is rejected and the chain remains at \(\eta=-0.2931\). The next proposal is made from that retained state, not from the rejected value.

Behavior near zero and alternatives

An additive random walk on the original scale, \(v'=v+\epsilon\), can propose negative values. Treating such values as outside the support and rejecting them preserves validity if the target is defined as zero there, but it can waste proposals, especially when the current variance is close to zero. A log-scale proposal always produces a positive value and represents changes proportionally. It is not automatically ideal: an extremely large \(s\) can still send proposals to regions of negligible posterior density, and a posterior concentrated near zero can require careful tuning.

Worked Example: Positive Proposals Near a Boundary

Suppose the current variance is \(v=0.0400\), and an original-scale proposal is \(v'=v+\epsilon\) with \(\epsilon\sim N(0,0.10^2)\). The probability of proposing a negative value is \(P(\epsilon<-0.0400)=\Phi(-0.4)\approx0.3446\). Those proposals cannot be accepted for a parameter restricted to \(v>0\).

With a log-scale increment of \(+0.5\), the proposal is instead \(v'=0.0400\exp(0.5)\approx0.06595\), which is positive. For the illustrative Gamma target, the transformed log target is \(2\log(v)-3v\). Its change from 0.0400 to 0.06595 is approximately \[ 2\log(0.06595/0.0400)-3(0.06595-0.0400) =0.922. \] The acceptance probability is therefore 1 for this proposed move. This example illustrates how the log scale avoids invalid proposals; it does not establish that every such proposal will be accepted or that the same target describes every GLMM.

A truncated or reflected proposal on the positive scale can also respect the parameter constraint, but its proposal density may be asymmetric. Its Metropolis–Hastings ratio must include the reverse-to-forward proposal-density ratio; simply comparing posterior densities is not generally correct. Slice sampling is another option for a positive scalar target, while Hamiltonian Monte Carlo uses a different mechanism for proposing moves. These alternatives have different computational requirements and tuning considerations. The log-scale random walk is attractive when a simple, easily evaluated proposal is desired and multiplicative changes are appropriate.

Failure modes and practical limits

Several warning signs can point to poor proposal tuning. An acceptance fraction close to one combined with tiny changes suggests an overly conservative scale. A very low fraction suggests proposals are often landing in low-density regions. A scale that behaves well for one variance component may behave poorly for another because their conditional posterior shapes and dependence on other parameters can differ. Tune each update with its own behavior in mind.

The acceptance fraction is not a complete diagnostic of chain quality. A chain may accept many tiny moves and still cover the posterior inefficiently; a lower fraction may accompany larger accepted moves. Nor does a plausible acceptance fraction confirm that the conditional posterior, prior, likelihood, or model is correctly specified. After selecting a scale, assess the resulting chains and posterior summaries with appropriate diagnostics; tuning is one part of a larger MCMC workflow.

Common mistake: “The largest acceptance rate is best, so I should make \(s\) as small as possible.” A tiny proposal can be accepted almost every time yet move so little that exploration is slow. Instead, balance acceptance with the size of accepted moves, and treat any target acceptance range as a heuristic rather than a theorem.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. For a positive variance \(v\), write the transformed posterior density for \(\eta=\log v\) in terms of \(\pi_v(v)\).
  2. A symmetric log-scale proposal has current transformed log target \(-4.2\) and proposed transformed log target \(-5.0\). Find the acceptance probability.
  3. Why can an additive normal proposal be inefficient when the current variance is close to zero?
  4. A scalar pilot has acceptance fraction 0.98 with very small accepted changes. What is a reasonable tuning adjustment, and why?

Solutions. (1) \(\pi_\eta(\eta)=\pi_v(\exp(\eta))\exp(\eta)\). (2) The log ratio is \(-5.0-(-4.2)=-0.8\), so \(\alpha=\exp(-0.8)\approx0.4493\). (3) It can propose negative values, which must be rejected because the variance is positive. (4) Increase \(s\) modestly and reassess: the high acceptance with tiny moves suggests proposals may be too small, but the new scale should be evaluated rather than presumed optimal.

Clinical Biostats