Documentation

A.11 Importance sampling and the size of Monte Carlo error

An importance-sampling estimate of one subject's integral

What you will learn

  • Write the importance-sampling estimator of the marginal likelihood and the multivariate-\(t\) proposal that nlmx uses, with antithetic pairs.
  • Compute log-weights stably, and derive the effective sample size and the conditional mean and covariance of the ETAs.
  • See how the Monte Carlo error of an objective value scales with the number of draws, for one subject and for a data set, and why common random numbers matter in the covariance step.

Prerequisites: A.5, A.6, A.8 and A.10.

The estimator

The integral that defines a subject's marginal likelihood can be written as an expectation under any density \(q\) that is positive wherever the integrand is:

\[ \int e^{-J_i(\eta)/2}\,d\eta=\int\frac{e^{-J_i(\eta)/2}}{q(\eta)}\,q(\eta)\,d\eta=\mathbb E_q\!\Bigl[\frac{e^{-J_i(\eta)/2}}{q(\eta)}\Bigr]\approx\frac1M\sum_{m=1}^{M}\frac{e^{-J_i(\eta_m)/2}}{q(\eta_m)},\quad\eta_m\sim q . \]

The estimate is unbiased for the integral and consistent as \(M\to\infty\). Its variance is small when \(q\) resembles the integrand, and infinite if \(q\) has lighter tails than the integrand, which is why the proposal is a heavy-tailed one.

On the objective scale,

\[ \mathrm{OFV}_i\approx\log\lvert\Omega\rvert+p\log2\pi-2\log\frac1M\sum_{m=1}^{M}\frac{e^{-J_i(\eta_m)/2}}{q(\eta_m)} . \]

This is the objective that nlmx reports after SAEM (the printed SAEM trace is not an OFV; page A.10), computed at the final estimates, and the one used for the covariance step after SAEM.

The proposal

The proposal for subject \(i\) is a multivariate \(t\) with \(\nu=4\) degrees of freedom, centred at the conditional mode and scaled by the Laplace curvature (page A.8):

\[ \eta_m=\hat\eta_i\pm\frac{L_iz_m}{\sqrt{w_m}},\qquad z_m\sim N(0,I_p),\quad w_m\sim\chi^2_\nu/\nu,\quad L_iL_i^{\mathsf T}=\Sigma_i=\bigl(\tfrac12H_i\bigr)^{-1}. \]

If the curvature is unusable, the prior covariance \(\Omega\) replaces \(\Sigma_i\). The \(\pm\) is an antithetic pair: each draw \((z_m,w_m)\) is used twice, once added and once subtracted, so the draws are balanced around the centre and the variance of the estimate is reduced for a smooth integrand. The log-density of the proposal is

\[ \log q(\eta_m)=\log\Gamma\!\bigl(\tfrac{\nu+p}2\bigr)-\log\Gamma\!\bigl(\tfrac\nu2\bigr)-\tfrac p2\log(\nu\pi)-\tfrac12\log\lvert\Sigma_i\rvert-\tfrac{\nu+p}2\log\!\Bigl(1+\frac{z_m^{\mathsf T}z_m}{w_m\nu}\Bigr). \]

Stable computation

The weights \(e^{-J/2}/q\) can span many orders of magnitude, and \(J\) can be large. The average is therefore computed with the log-sum-exp device: with \(\ell_m=-J_i(\eta_m)/2-\log q(\eta_m)\) and \(\ell^\ast=\max_m\ell_m\),

\[ \log\frac1M\sum_me^{\ell_m}=\ell^\ast+\log\frac1M\sum_me^{\ell_m-\ell^\ast}, \]

in which the largest term is exactly 1 and no exponential overflows.

Weights, conditional moments and the effective sample size

The normalised weights \(w_{im}\propto e^{\ell_m}\) turn the same draws into a posterior sample for the subject:

\[ \bar\eta_i=\frac{\sum_mw_{im}\eta_m}{\sum_mw_{im}},\qquad \widehat{\operatorname{Cov}}(\eta_i)=\text{the weighted covariance},\qquad \mathrm{ESS}=\frac{\bigl(\sum_mw_{im}\bigr)^2}{\sum_mw_{im}^2}. \]

The effective sample size says how many equally weighted draws the weighted sample is worth. It equals \(M\) when the weights are all equal (a perfect proposal) and approaches 1 when one weight dominates. nlmx warns when it falls below 10 % of the draws for a subject; then the estimate for that subject rests on very few draws, and the proposal is a poor match.

A worked illustration

The appendix subject. Proposal: \(t_4\) at \(\hat\eta=-0.33425\) with \(\Sigma=(\tfrac12H)^{-1}=1/125.50=0.00797\) (SD 0.0893). The exact \(\mathrm{OFV}_i\) is \(-0.8150\) (page A.6). The estimator was repeated 200 times at each \(M\), with antithetic pairs and an independent generator (not the program's own streams):

\(M\) mean of \(\mathrm{OFV}_i\) estimates SD across repeats effective sample fraction
30 −0.8070 0.0774 0.91
300 −0.8163 0.0274 0.92
3000 −0.8151 0.0073 0.91

Three observations.

  1. Unbiased, with an error that shrinks like \(1/\sqrt M\): the SD falls by a factor of about 2.8 for a tenfold increase in \(M\) (ideal: 3.16), then by 3.8 for the next. The means are all within a standard error of the exact \(-0.8150\).
  2. The proposal fits well: roughly 91 % of the draws are "effective", because the subject is well determined and the posterior is nearly Gaussian, so the Laplace-based proposal covers it closely.
  3. A single subject's error is small, but errors add. The Monte Carlo errors of independent subjects are independent, so the SD of a data set's total OFV is about \(\sqrt N\) times a typical subject's. For \(N=200\) subjects like this one and \(M=300\), that is \(0.027\sqrt{200}\approx0.39\) objective units. The program documents an error of about \(\pm1\) unit at 300 draws and \(\pm0.2\) at 3000 draws for 200 subjects; real subjects, with more ETAs and less informative data, are harder to cover than this one, and the same \(1/\sqrt M\) rule applies. Differences in OFV between models smaller than the Monte Carlo error cannot be interpreted.

Common random numbers and the covariance step

The covariance step after SAEM differentiates the objective numerically (page A.12), by comparing OFV values at slightly perturbed parameters. If each evaluation used its own random draws, the difference between two OFV values would be dominated by Monte Carlo noise (of order 0.4 in the illustration above) rather than by the change in \(\psi\) (which may be of order \(10^{-2}\)), and the second differences — divided by a tiny step squared — would be meaningless.

nlmx therefore uses common random numbers: the standardised draws \((z_m,w_m)\) are fixed once and reused for every perturbed \(\psi\), while the proposal is re-centred at each perturbed point's own mode and curvature. The noise is then largely the same in the two objectives and cancels in the difference. This is the reason that the covariance step after SAEM can be both Monte Carlo-based and smooth.

Review checklist

  • Can you state the importance-sampling identity and the condition on the proposal?
  • Can you explain the antithetic pairs and the log-sum-exp computation?
  • Can you compute an ESS from a set of weights, and say what a low one means?
  • Do you know how the error of a total OFV relates to the error of one subject and to \(M\)?
  • Can you say why the covariance step fixes the random draws?

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