Tutorials › Nonlinear Mixed-Effects Models (NLME) › Nested Simulation With Parameter and Subject Draws

Simulation From Fitted Models · Tutorial 690 of 797

Nested Simulation With Parameter and Subject Draws

Use an outer loop for uncertainty in fitted parameters and an inner loop for subject variability, then interpret the resulting variation and dependence correctly.

Intermediate 10 min read

What You'll Learn

  • Distinguish uncertainty in fitted parameters from between-subject variability.
  • Define an outer parameter draw and the conditional inner subject draws.
  • Derive the total-variance decomposition for nested simulation.
  • Identify why one parameter draw should be shared across an inner simulated cohort.
  • Diagnose simulations that mix uncertainty sources or use the wrong nesting.
  • Compare nested simulation with plug-in and single-layer simulation.

Why Nest the Simulation?

A simulated outcome from a fitted nonlinear mixed-effects model can vary for more than one reason. The fitted parameters are uncertain, and subjects in the modeled population differ through their random effects. If simulated observations include residual error, that adds another source of variation. A useful simulation design keeps these sources distinct rather than blending them into a single unexplained cloud of outcomes.

Nested simulation does this with two loops. In the outer loop, draw a plausible fitted parameter set. In the inner loop, use that same parameter set to simulate multiple subjects from the population model. Thus, variation between outer draws reflects parameter uncertainty, while variation within an outer draw reflects subject-level variability, and any residual error included in the outcome model.

Definition: Let \(\theta\) denote the fitted model parameters, and let \(Y\) be a simulated outcome. An outer parameter draw is a draw \(\theta^{(m)}\) from a specified representation of uncertainty in the fitted parameters. An inner subject draw is a simulated subject-level random effect, and, if the target is an observed outcome, any residual error, generated conditionally on \(\theta^{(m)}\). For each outer draw, the inner draws share that parameter set.

The source of the outer draws matters. They might be obtained from a parameter covariance approximation, a bootstrap, or Bayesian posterior draws. Each source represents uncertainty in a particular way; nesting does not make those interpretations interchangeable. The key is that a parameter set is selected at the outer level, then used consistently for the inner population simulation.

The Nested Structure and Its Variance

Write the simulated outcome for outer draw \(m\) and inner subject \(j\) as \(Y_{mj}\). A general representation is \(Y_{mj}=g(\theta^{(m)},\eta_{mj},\epsilon_{mj})\), where \(g\) is the model prediction, \(\eta_{mj}\) is a subject-level random effect, and \(\epsilon_{mj}\) is residual error when simulating observations rather than the latent model prediction. The conditional distributions of the random effects and residuals are those specified by the fitted model at \(\theta^{(m)}\).

Define \(a(\theta)=E(Y\mid\theta)\), the conditional mean outcome, and \(v(\theta)=\operatorname{Var}(Y\mid\theta)\), the conditional variance across simulated subjects and any included residual errors. The law of total variance gives:

$$ \operatorname{Var}(Y) = \operatorname{Var}_{\theta}\{a(\theta)\} + E_{\theta}\{v(\theta)\}. $$

The first term measures how the conditional mean changes across plausible parameter sets. The second averages the conditional population variance over those parameter sets. This identity follows by writing \(Y-E(Y)=[Y-E(Y\mid\theta)]+[E(Y\mid\theta)-E(Y)]\), squaring, and taking expectations. The cross-product has expectation zero because \(E[Y-E(Y\mid\theta)\mid\theta]=0\). The two remaining squared terms have expectations \(E\{\operatorname{Var}(Y\mid\theta)\}\) and \(\operatorname{Var}\{E(Y\mid\theta)\}\), respectively.

This decomposition is a useful guide to what the simulation estimates, not a claim that the two contributions can always be cleanly identified from a small finite simulation. In practice, the inner draws estimate conditional means and variances, while the outer draws show how those conditional summaries change with the parameter set.

Worked Example: Separating Two Variance Sources

Suppose a hypothetical model has the simple prediction \(Y=\theta+\eta\), where \(\theta\) represents an uncertain fitted mean and \(\eta\sim N(0,4)\) is a subject random effect. Treat two equally weighted parameter values, \(\theta=8\) and \(\theta=10\), as an illustrative discrete uncertainty distribution. Ignore residual error.

For either parameter value, \(E(Y\mid\theta)=\theta\) and \(\operatorname{Var}(Y\mid\theta)=4\). The mean of the two conditional means is \((8+10)/2=9\), so the between-parameter variance is:

$$ \operatorname{Var}_{\theta}\{E(Y\mid\theta)\} = \frac{(8-9)^2+(10-9)^2}{2} =1. $$

The average within-parameter variance is \((4+4)/2=4\). Therefore the marginal variance is \(1+4=5\), and the marginal standard deviation is \(\sqrt{5}=2.236\) outcome units. The value 1 represents variation in the conditional mean due to the parameter draw; the value 4 represents subject variability at a fixed parameter value.

For a finite simulation, the inner subject draws will not produce exactly the conditional mean or variance. Increasing the number of inner draws improves the estimates of those conditional summaries, while increasing the number of outer draws improves coverage of the parameter uncertainty distribution.

Nonlinear Models Can Change Both Components

In an NLME model, \(a(\theta)\) and \(v(\theta)\) need not have simple forms. A parameter can affect the mean response, the spread of subject effects, or both; nonlinear transformations can also make the conditional mean differ from the response evaluated at an average random effect. The nested design accommodates this by evaluating the model separately at each outer parameter draw and simulating subjects conditionally under that draw.

Worked Example: A Lognormal Subject Effect

Consider a hypothetical positive outcome \(Y=\theta\exp(\eta)\), where \(\eta\sim N(0,0.04)\). Two equally weighted illustrative parameter values are \(\theta=10\) and \(\theta=12\), in outcome units. The random-effect distribution is held fixed for this calculation. For a normal variable with mean zero and variance \(s^2\), \(E\{\exp(\eta)\}=\exp(s^2/2)\) and \(\operatorname{Var}\{\exp(\eta)\}=(\exp(s^2)-1)\exp(s^2)\).

Here \(E\{\exp(\eta)\}=\exp(0.02)=1.0202\), and \(\operatorname{Var}\{\exp(\eta)\}=(\exp(0.04)-1)\exp(0.04)=0.04248\). Thus the two conditional means are \(10(1.0202)=10.202\) and \(12(1.0202)=12.242\) outcome units. Their equally weighted mean is \(11.222\), giving a between-parameter variance of approximately:

$$ \frac{(10.202-11.222)^2+(12.242-11.222)^2}{2} =1.041\ \text{outcome units}^2. $$

At a fixed \(\theta\), the conditional variance is \(\theta^2(0.04248)\). Averaging across the two parameter values gives \(\{10^2(0.04248)+12^2(0.04248)\}/2=5.183\) outcome units squared. The total variance, calculated from unrounded component values, is approximately 6.223 outcome units squared. This example shows that both the conditional mean and the conditional variance can depend on the fitted parameter.

Why the Outer Draw Is Shared Within an Inner Cohort

The outer parameter draw represents uncertainty about the fitted model, not an independently redrawn model for each subject in the same simulated cohort. Holding \(\theta^{(m)}\) fixed across the inner subjects allows the simulation to represent a population generated under one plausible parameter set. If a new independent parameter draw is made for every subject, parameter uncertainty is inadvertently mixed into individual variation. That may leave the marginal spread of a single outcome similar, but it changes the joint behavior of outcomes in a cohort.

Worked Example: Dependence Across Subjects

Suppose a hypothetical outcome is \(Y_j=\theta+\eta_j\). The parameter draw is equally likely to be 8 or 12, and two subjects have independent random effects with mean zero and variance 1, conditional on \(\theta\). Each outcome has marginal mean 10. The variance of the conditional mean is \(\{(8-10)^2+(12-10)^2\}/2=4\), so each subject's marginal variance is \(4+1=5\).

When both subjects share the same outer draw, their conditional random effects are independent, but their conditional means are the same \(\theta\). Their covariance is therefore:

$$ \operatorname{Cov}(Y_1,Y_2) = \operatorname{Var}_{\theta}\{E(Y_j\mid\theta)\} =4. $$

If instead an independent parameter draw were made for each subject, the shared parameter component would disappear and the covariance would be zero, under the stated independence assumptions. The two constructions do not represent the same simulated cohort: the first includes shared uncertainty about the fitted model, while the second assigns a different uncertain model to each subject.

Practical Checks, Alternatives, and Limitations

Before interpreting a nested simulation, check that the loop structure matches the intended question. A useful conceptual flow is:

1
Choose the outer uncertainty distribution.
Use the intended parameter draws and retain their meaning, whether they come from a covariance approximation, bootstrap, or posterior distribution.
2
Hold each parameter set fixed for its inner cohort.
Generate subject effects conditionally on that parameter set, using the fitted population model.
3
Match the outcome to the target.
Use the latent model prediction when that is the target; include residual error when simulating observed outcomes.
4
Compare within- and between-draw summaries.
Check that the conditional subject variation and the variation of conditional summaries across parameter draws are both represented.

Several patterns can reveal a problem. If outcomes vary across inner subjects but are identical across all outer draws, the parameter draws may not be reaching the prediction calculation. If inner subjects are identical within an outer draw despite a model with nonzero random-effect variance, subject-level effects may not have been sampled or applied. If different subjects appear to have independently changing fixed-effect parameter sets, the nesting has likely been lost. Also check that simulated parameters remain valid for the model and that the simulated outcome units and scale match the intended quantity.

Nested simulation differs from plug-in simulation, which fixes parameters at their estimates and therefore omits variation across plausible fitted parameter sets. It also differs from a single-layer simulation that produces outcomes from just one parameter set: such a simulation can describe subject variability conditional on that set, but cannot show the impact of parameter uncertainty. A nested design represents both components and their shared-parameter structure. Its limitations remain important: the result depends on the quality of the fitted model and the chosen uncertainty distribution; too few outer or inner draws give unstable summaries; and uncertainty sources not included in the outer draws or the subject model are not automatically accounted for.

A common mistake is to say, “Every subject should get a fresh parameter draw because every subject is different.” That reasoning confuses uncertainty about the fitted population model with variability among subjects under a given model. The correction is to draw the uncertain model parameters at the outer level, then draw subject effects at the inner level. Subject differences are generated by the random-effects distribution, not by assigning each subject a new fitted model.

Key takeaway: In nested NLME simulation, an outer draw represents one plausible fitted parameter set and an inner cohort represents subjects simulated under that set. The resulting variation can be understood through \(\operatorname{Var}(Y)=\operatorname{Var}_{\theta}\{E(Y\mid\theta)\}+E_{\theta}\{\operatorname{Var}(Y\mid\theta)\}\), provided the simulation includes the relevant sources of uncertainty and variability.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. In one sentence, distinguish an outer parameter draw from an inner subject draw.
  2. A simulated outcome has conditional mean \(a(\theta)\) and conditional variance \(v(\theta)\). State its marginal variance decomposition.
  3. In a cohort simulation, why should subjects within an outer replicate share the same parameter draw?
  4. A simulation includes subject random effects but no outer parameter draws. Which source of variation is represented, and which is omitted?

Solutions. (1) The outer draw selects a plausible fitted parameter set; the inner draw generates subject-level variability conditional on that set. (2) \(\operatorname{Var}(Y)=\operatorname{Var}_{\theta}\{a(\theta)\}+E_{\theta}\{v(\theta)\}\). (3) A cohort is simulated under one plausible model parameter set, and sharing that set preserves the dependence induced by common uncertainty about the fitted model. (4) The simulation represents conditional population variability from subject effects, but it omits variation across uncertain fitted parameter sets.