Tutorials › Pharmacometric Workflows and Reproducible Modeling › Simulating Residual Error For Different Endpoints

Simulation Pipelines · Tutorial 256 of 399

Simulating Residual Error For Different Endpoints

Choose and apply endpoint-appropriate residual models while preserving the distinction between a model prediction and a simulated observation.

Advanced 12 min read

What You'll Learn

  • Distinguish an underlying prediction from an observation simulated around it.
  • Apply additive, proportional, and combined residual models for continuous endpoints.
  • Simulate count outcomes with Poisson or overdispersed count distributions.
  • Generate binary and categorical outcomes from predicted probabilities.
  • Check distributional assumptions and diagnose inappropriate residual simulation.
  • Identify when a residual model needs to represent dependence or constraints.

Predictions Are Not Simulated Observations

A pharmacometric model may predict a concentration, an event count, or a probability of response for a particular individual at a particular observation time. That prediction describes the model’s expected outcome, or the parameters of an outcome distribution. A simulated observation is a random draw from that distribution. These are different quantities: adding observation-level variability changes a prediction into a possible observed outcome, not into a new model prediction.

Let \(i\) index individuals and \(j\) index observations. Write \(\mu_{ij}\) for a continuous outcome’s model prediction, \(\lambda_{ij}\) for a count outcome’s predicted mean, and \(\boldsymbol{\pi}_{ij}\) for a categorical outcome’s vector of predicted category probabilities. These predictions can depend on the model parameters, covariates, and the individual effects used for the simulation. Conditional on those inputs, residual simulation adds variability at the observation level.

Definition: Residual simulation draws an observation from a specified outcome distribution conditional on the model prediction and other inputs for that observation. The prediction remains the distribution’s parameter or expectation; the simulated outcome is one random realization. Residual variability is not a substitute for parameter uncertainty or between-individual variability.

The choice of distribution depends on the endpoint’s support and measurement process. A continuous measurement can often take a range of real values; a count is a nonnegative integer; and a categorical outcome must be one of a defined set of categories. Using the same additive normal error model for all three kinds of endpoint can produce impossible or misleading values.

Continuous Endpoints: Additive, Proportional, and Combined Error

For a continuous endpoint, an additive normal error model is \(Y_{ij}=\mu_{ij}+\epsilon_{ij}\), where \(\epsilon_{ij}\) has mean zero and standard deviation \(\sigma_{\text{add}}\). Thus, conditional on the prediction, the observation has mean \(\mu_{ij}\) and variance \(\sigma_{\text{add}}^2\). This is useful when measurement variability is approximately constant across the prediction range.

$$ Y_{ij}\mid\mu_{ij}\sim N(\mu_{ij},\sigma_{\text{add}}^2) $$

If variability increases with the magnitude of the prediction, a proportional model can be more appropriate: \(Y_{ij}=\mu_{ij}(1+\epsilon_{ij})\), with \(\epsilon_{ij}\sim N(0,\sigma_{\text{prop}}^2)\). Its conditional standard deviation is \(|\mu_{ij}|\sigma_{\text{prop}}\). This model can generate negative values, so it is unsuitable when negative outcomes are impossible and the chance of such draws is not negligible.

A combined model allows both a constant and prediction-dependent component. One form is \(Y_{ij}=\mu_{ij}+\mu_{ij}\epsilon_{\text{prop},ij}+\epsilon_{\text{add},ij}\), where the two errors are independent, have mean zero, and have standard deviations \(\sigma_{\text{prop}}\) and \(\sigma_{\text{add}}\), respectively. Conditional on \(\mu_{ij}\), its variance is the sum of the component variances:

$$ \operatorname{Var}(Y_{ij}\mid\mu_{ij}) =\mu_{ij}^2\sigma_{\text{prop}}^2+\sigma_{\text{add}}^2 $$

The equality follows because the variance of a sum is the sum of variances when the terms are independent, and multiplying a random variable by \(\mu_{ij}\) multiplies its variance by \(\mu_{ij}^2\). If the errors are not independent, a covariance term is also needed; simply adding the two variances would then be incorrect. For positive outcomes with right-skewed variability, a lognormal model may be preferable. Its parameterization should be chosen deliberately: \(Y=\mu\exp(\eta)\), with \(\eta\sim N(0,\omega^2)\), has conditional mean \(\mu\exp(\omega^2/2)\), not \(\mu\). A mean-preserving form is \(Y=\mu\exp(\eta-\omega^2/2)\).

Worked Example: Simulating a Continuous Concentration

Hypothetical setup. At one observation time, the model predicts a concentration of \(12.0\) mg/L. Assume the combined-error model above, with \(\sigma_{\text{prop}}=0.10\) and \(\sigma_{\text{add}}=1.50\) mg/L. Assume the two error components are independent and normally distributed. For this draw, use standardized normal draws \(z_{\text{prop}}=-0.50\) and \(z_{\text{add}}=0.80\).

The simulated observation is \(Y=12.0+(12.0)(0.10)(-0.50)+(1.50)(0.80)\). The proportional component is \(-0.600\) mg/L; the additive component is \(1.20\) mg/L. Therefore \(Y=12.6\) mg/L. The model prediction remains \(12.0\) mg/L; \(12.6\) mg/L is one simulated observation.

The conditional variance is \((12.0)^2(0.10)^2+(1.50)^2=1.44+2.25=3.69\) \((\text{mg/L})^2\), giving a conditional standard deviation of \(\sqrt{3.69}=1.921\) mg/L. The normality and independence assumptions make the calculation valid for this specified model. Whether those assumptions are suitable for an application requires checking observed residual behavior and the endpoint’s possible range.

Count Endpoints: Draw Counts, Not Continuous Errors

A count outcome takes values \(0,1,2,\ldots\). A Poisson model uses the predicted mean \(\lambda_{ij}>0\) as both its mean and variance:

$$ Y_{ij}\mid\lambda_{ij}\sim\operatorname{Poisson}(\lambda_{ij}),\qquad P(Y_{ij}=k\mid\lambda_{ij})= \frac{\exp(-\lambda_{ij})\lambda_{ij}^{k}}{k!} $$

A Poisson draw respects the count’s support; adding a normal error to a predicted count does not. The Poisson assumption requires conditional equality of mean and variance and, for independent observations, conditional independence across observations. If counts are more variable than the Poisson distribution allows, a negative binomial model is one alternative. In a common parameterization, its variance is \(\lambda_{ij}+\lambda_{ij}^2/k\), where the dispersion parameter \(k>0\). Its variance exceeds its mean for finite \(k\), and it approaches the Poisson variance as \(k\) grows.

Worked Example: Drawing a Poisson Count

Hypothetical setup. Suppose a model predicts a mean of \(\lambda=2.40\) events during a specified interval. Assume the count follows a Poisson distribution conditional on this prediction. To show how a draw can be made, take a uniform random number \(U=0.70\) and use the inverse cumulative distribution rule: choose the smallest integer \(k\) for which \(P(Y\leq k)\geq U\).

The probabilities through \(k=2\) are \(P(Y=0)=\exp(-2.40)=0.0907\), \(P(Y=1)=2.40\exp(-2.40)=0.2177\), and \(P(Y=2)=(2.40^2/2)\exp(-2.40)=0.2613\). Their cumulative sum is \(P(Y\leq2)=0.5697\). Next, \(P(Y=3)=(2.40^3/6)\exp(-2.40)=0.2090\), so \(P(Y\leq3)=0.7787\). Since \(0.5697<0.70\leq0.7787\), the simulated count is \(3\).

The predicted mean remains 2.40 events per interval; the draw is 3 events. This is a valid Poisson simulation under the stated assumption, not evidence that the model prediction should be replaced by 3. If the conditional variance in the intended data-generating process exceeds 2.40 events squared, the Poisson assumption may be inadequate and an overdispersed count model should be considered.

Categorical Endpoints: Simulate a Category From Probabilities

For an outcome with \(K\) possible categories, the model supplies probabilities \(\pi_{ij1},\ldots,\pi_{ijK}\), each between zero and one, whose sum is one. A categorical draw produces exactly one category. For a binary outcome this is a Bernoulli draw: if the predicted probability of the event is \(p_{ij}\), then the event occurs with probability \(p_{ij}\), and the non-event occurs with probability \(1-p_{ij}\). The probability is not itself the simulated outcome.

Worked Example: Simulating a Categorical Response

Hypothetical setup. Suppose the predicted probabilities for response categories A, B, and C are \(0.20\), \(0.50\), and \(0.30\). They are valid probabilities because each is between zero and one and \(0.20+0.50+0.30=1.00\). Assume the categories are mutually exclusive, exhaustive, and correctly represented by these conditional probabilities.

Draw \(U=0.63\) from a uniform distribution on \([0,1)\). Assign A if \(U<0.20\), B if \(0.20\leq U<0.70\), and C if \(0.70\leq U<1.00\). Since \(0.20\leq0.63<0.70\), the simulated outcome is category B. The vector \((0.20,0.50,0.30)\) remains the model prediction; B is one possible realization.

This procedure assumes the probability vector is correctly normalized and that the category draw is appropriate for the observation being simulated. If categories are ordered, the categorical draw still generates a valid label but does not by itself model the ordering. An ordinal model may better represent that structure.

Assumptions, Diagnostics, and Choosing an Approach

Residual simulation is conditional on the prediction and the inputs used to obtain it. It commonly assumes that the selected conditional distribution is correct and that residual draws are independent across observations unless dependence is explicitly modeled. These are modeling assumptions, not automatic consequences of drawing random numbers. For example, serial correlation in repeated measurements is not represented by independently drawing a fresh residual at each time.

Check the simulated observations against the endpoint and the intended observation process. For continuous outcomes, inspect residual spread across prediction levels, skewness, extreme values, and whether simulated values cross impossible boundaries. For counts, compare variability and the frequency of zeros with what the selected count distribution implies. For categorical outcomes, verify that probabilities sum to one and compare simulated category frequencies with their predicted probabilities over sufficiently many draws. A mismatch can reflect model misspecification, a coding error, or Monte Carlo variation; it is not diagnosed solely by looking at one simulated record.

EndpointTypical conditional drawKey limitation to check
ContinuousNormal additive, proportional, or combined error; possibly lognormalSkew, changing variance, or impossible values
CountPoisson or negative binomial drawPoisson variance constraint or excess zeros
CategoricalOne category drawn from a probability vectorProbability calibration, category structure, or dependence

The alternatives are not interchangeable. A normal model is convenient for continuous outcomes but does not enforce nonnegative integer counts. A Poisson model respects count support but forces the conditional variance to equal the mean. A categorical model respects the set of allowed labels but requires an appropriate probability vector. The distribution should reflect both the type of endpoint and the modeled observation process; choosing it merely because it is easy to simulate can produce plausible-looking but incoherent data.

Common Mistakes and a Practical Sequence

  • Calling the prediction an observation. A predicted mean or probability describes a distribution; it is not a simulated outcome.
  • Adding normal noise to every endpoint. This can produce fractional or negative counts and category values that do not exist.
  • Ignoring the scale of residual variability. Constant additive spread and prediction-dependent spread imply different distributions of observations.
  • Using a distribution without checking its support or assumptions. A model can generate values that are mathematically allowed by the distribution but impossible for the actual endpoint.
  • Assuming independent residuals without justification. If observation errors are correlated, independent draws fail to represent that dependence.

A reliable implementation first identifies the endpoint and its allowed values, then specifies the conditional distribution and its parameters, checks the distributional assumptions, and finally draws an outcome while retaining the underlying prediction separately. Store or report both quantities when later summaries need to distinguish model expectations from observation-level variation.

1
Identify the endpoint.
Determine whether the simulated value is continuous, a nonnegative count, or one of a finite set of categories.
2
Specify the conditional distribution.
Use the model prediction as the appropriate distribution parameter, and state the residual assumptions.
3
Draw and validate the outcome.
Generate a value from the chosen distribution and check that it respects the endpoint’s support and the implementation’s probability or parameter constraints.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A continuous prediction is 8.0 mg/L, with additive error standard deviation 1.0 mg/L. If a standard normal draw is \(-1.2\), what observation is simulated, and what remains the prediction?
  2. A Poisson model predicts a mean count of 4.0. What variance does this model imply, and why might a negative binomial model be considered?
  3. A binary model predicts an event probability of 0.35. For a uniform draw \(U=0.60\), what outcome is simulated if the event is assigned when \(U<0.35\)?
  4. Why is a predicted category probability of 0.70 not the same as a simulated categorical outcome?

Solutions. (1) The observation is \(8.0+1.0(-1.2)=6.8\) mg/L; the prediction remains 8.0 mg/L. (2) A Poisson distribution has variance equal to its mean, so the variance is 4.0 counts squared. A negative binomial model may be considered if conditional variability exceeds that Poisson constraint. (3) Since \(0.60\) is not less than \(0.35\), the simulated outcome is no event. (4) The value 0.70 is the model’s probability for a category; a simulated outcome is one category label drawn according to the full probability vector.

Clinical Biostats