Tutorials › Pharmacokinetic-Pharmacodynamic (PK/PD) Modeling › Predictive Stacking for PK/PD Model Ensembles

Model Selection and Averaging · Tutorial 485 of 598

Predictive Stacking for PK/PD Model Ensembles

Learn how to estimate stacking weights from subject-level predictive densities and use them to combine PK/PD model predictions without treating the weights as probabilities that models are true.

Advanced 12 min read

What You'll Learn

  • Define the subject-level leave-one-out predictive density used to fit stacking weights.
  • Derive the stacking objective and its concavity for two competing models.
  • Distinguish predictive stacking weights from posterior model probabilities.
  • Calculate mixture predictions and their variance from model-specific predictions.
  • Recognize scoring choices, numerical problems, and limitations of stacking.

Why Stack PK/PD Predictions?

Competing PK/PD models can make different predictions for the same subject, dose, and time point. One model may describe an exposure-response curve well, while another captures a delayed effect or a different residual structure. Selecting one model discards the others; averaging can retain predictive contributions from several. Predictive stacking chooses the weights in that average to optimize out-of-sample predictive density, rather than to represent the probability that each candidate model is true.

The prediction target matters. In repeated-measures PK/PD data, a useful target is often the response trajectory of a new subject, conditional on that subject’s known design information, such as dose and sampling times. For that target, validation must hold out whole subjects: holding out one record while using the same subject’s other records to fit the model would answer a different question.

Definition: Let \(D\) denote data from \(n\) subjects, and let \(D_{-i}\) be the data with all observations from subject \(i\) removed. For candidate model \(M_m\), the leave-one-subject-out predictive density \(q_{mi}\) is the density assigned to subject \(i\)’s complete response data \(y_i\), conditional on the subject’s known design information \(x_i\), using a model fitted to \(D_{-i}\): $$ q_{mi}=p_m(y_i\mid x_i,D_{-i}). $$ The density integrates over parameter uncertainty and, for a new-subject prediction, the distribution of that subject’s random effects. Stacking chooses weights \(w_m\geq 0\), with \(\sum_{m=1}^{M}w_m=1\), to maximize $$ L(\mathbf w)=\sum_{i=1}^{n}\log\left(\sum_{m=1}^{M}w_mq_{mi}\right). $$

Each weighted sum inside the logarithm is the ensemble’s predictive density for one held-out subject. Thus the objective is the sum of subject-level log predictive densities. The density must refer to the same response data, units, and prediction target across candidate models. If a response transformation is used, densities must be put on a common scale, including the appropriate transformation adjustment.

Why the Stacking Objective Is Concave

For two models, write \(w\) for the weight on model 1 and \(1-w\) for the weight on model 2, where \(0\leq w\leq1\). The objective is $$ L(w)=\sum_{i=1}^{n}\log\left(wq_{1i}+(1-w)q_{2i}\right). $$ Assume the predictive densities are positive and finite. Differentiating gives $$ L'(w)=\sum_{i=1}^{n}\frac{q_{1i}-q_{2i}}{wq_{1i}+(1-w)q_{2i}}, $$ and a second differentiation gives $$ L''(w)=-\sum_{i=1}^{n}\frac{(q_{1i}-q_{2i})^2}{\left(wq_{1i}+(1-w)q_{2i}\right)^2}\leq 0. $$

This establishes concavity: a maximum can be found reliably on the feasible interval. If at least one subject has different predictive densities under the two models, the second derivative is strictly negative throughout the interval. The objective is then strictly concave and has a unique maximum on \([0,1]\). That maximum may be at a boundary, in which case there need not be an interior stationary point. With more than two models, the objective is concave in the weight vector on the simplex; numerical constrained optimization is commonly used.

Worked Example: Finding a Two-Model Stacking Weight

Suppose three hypothetical subjects have the following leave-one-subject-out predictive densities under two competing PK/PD models. The values are in the same density units for both models.

Held-out subject\(q_{1i}\)\(q_{2i}\)
10.80.2
20.20.8
30.50.5

For weight \(w\) on model 1, the three ensemble densities are \(0.2+0.6w\), \(0.8-0.6w\), and \(0.5\). Therefore $$ L(w)=\log(0.2+0.6w)+\log(0.8-0.6w)+\log(0.5). $$ The derivative is $$ L'(w)=\frac{0.6}{0.2+0.6w}-\frac{0.6}{0.8-0.6w}. $$ Setting this equal to zero gives \(0.2+0.6w=0.8-0.6w\), so \(w=0.5\). The second derivative is strictly negative because the first two subjects have different densities under the models; hence this stationary point is the unique maximum. At \(w=0.5\), each ensemble density is \(0.5\), and the maximized score is \(3\log(0.5)\approx-2.079\). At either endpoint the score is \(\log(0.2)+\log(0.8)+\log(0.5)\approx-2.526\). Equal weights are optimal for these hypothetical data, not because the models are equally probable, but because this choice maximizes the specified cross-validated predictive score.

Stacking Weights and Posterior Model Probabilities

Posterior model probabilities and stacking weights both form nonnegative weights summing to one, but they answer different questions. A posterior model probability is \(P(M_m\mid D)\), calculated from a prior probability on each model and its marginal likelihood. Under Bayesian model averaging, those probabilities weight model-specific predictive distributions. Stacking instead selects weights to maximize the sum of leave-one-subject-out log predictive densities. Its weights are not posterior probabilities and do not state the probability that a candidate model is true.

This distinction is useful when no candidate model is expected to represent every feature of the data. A model with a relatively low posterior probability may still contribute useful predictions for some held-out subjects. Conversely, a model with high posterior probability under a particular set of priors need not receive the largest stacking weight. The posterior model probabilities are sensitive to prior model odds and marginal likelihoods; stacking directly targets the chosen predictive score. Neither approach is automatically superior: the choice depends on whether the scientific target is model uncertainty under a specified Bayesian model set or predictive performance for a specified validation target.

Worked Example: Comparing Weights and Predictive Means

Suppose two hypothetical PK/PD models predict a future response for a specified subject and time: model A has predictive mean \(8\) response units, and model B has predictive mean \(12\) response units. Assume posterior model probabilities are \(0.90\) and \(0.10\), while stacking assigns weights \(0.45\) and \(0.55\).

The Bayesian model-averaged predictive mean is $$ 0.90(8)+0.10(12)=7.2+1.2=8.4\text{ response units}. $$ The stacked predictive mean is $$ 0.45(8)+0.55(12)=3.6+6.6=10.2\text{ response units}. $$ The difference reflects different weight-selection rules; it does not show that stacking has found a 55% probability that model B is true. If the ensemble is used to predict the response, its predictive distribution is the weighted mixture of the candidate predictive distributions, not merely a weighted average of their means.

For example, suppose the ensemble’s predictive densities for three held-out subject records are \(0.74\), \(0.26\), and \(0.58\), in common density units. Their summed log score is $$ \log(0.74)+\log(0.26)+\log(0.58)=\log(0.111592)\approx-2.193. $$ A larger summed log score (less negative here) is better, provided the same subjects and scoring definition are used. The score evaluates predictive density at the held-out outcomes; it is not a probability that the ensemble is correct.

Calculating an Ensemble Prediction and Its Uncertainty

For a future response \(Y\), let model \(m\) have predictive mean \(\mu_m\) and predictive variance \(\sigma_m^2\), conditional on the same covariates and prediction target. The stacked predictive distribution is the mixture \(\sum_m w_m p_m(Y)\). Its mean is \(\sum_m w_m\mu_m\), and its variance includes both within-model predictive variance and between-model variation in predictive means: $$ \operatorname{Var}(Y)=\sum_{m=1}^{M}w_m\left[\sigma_m^2+(\mu_m-\mu_{\mathrm{ens}})^2\right], \qquad \mu_{\mathrm{ens}}=\sum_{m=1}^{M}w_m\mu_m. $$ This follows by taking the weighted average of each component’s second moment, \(\sigma_m^2+\mu_m^2\), and subtracting \(\mu_{\mathrm{ens}}^2\). The resulting mixture need not itself be normal, even when every component predictive distribution is normal.

Worked Example: Combining Predictive Means and Variances

Suppose a stacking fit gives weights \(0.6289\) and \(0.3711\) for two hypothetical models. For a specified future response, model 1 predicts a normal distribution with mean \(10\) response units and variance \(4\) response-units squared; model 2 predicts a normal distribution with mean \(14\) response units and variance \(9\) response-units squared.

The weights sum to one. The ensemble mean is $$ \mu_{\mathrm{ens}}=0.6289(10)+0.3711(14)=6.289+5.1954=11.4844\text{ response units}. $$ Using the mixture-variance formula, $$ \begin{aligned} \operatorname{Var}(Y) &=0.6289\left[4+(10-11.4844)^2\right] +0.3711\left[9+(14-11.4844)^2\right]\\ &=0.6289(6.20344336)+0.3711(15.32824336)\\ &\approx3.90135+5.68831\\ &\approx9.590\text{ response-units squared}. \end{aligned} $$ The corresponding predictive standard deviation is \(\sqrt{9.590}\approx3.097\), or about \(3.10\) response units. This variance exceeds a simple weighted average of the within-model variances because it also includes disagreement between the models’ predictive means. The mean and variance summarize the mixture, but they do not make it a normal distribution.

Practical Conditions, Diagnostics, and Limitations

A stacking analysis is interpretable only when its validation design matches the intended prediction. For a new-subject target, every record from a held-out subject must be excluded from fitting, including information used to estimate that subject’s random effect. The predictive density should then integrate over the random-effect distribution for a new subject. If the actual target is a future observation from a subject whose earlier observations are available, a conditional prediction may be appropriate instead; that is a different target and should use a matching validation design.

Before trusting the fitted weights, check that each fold converged, the predictive densities are finite and computed on a common scale, and the weights are nonnegative and sum to one. Inspect the subject-level log-score contributions and the fitted weights. A boundary solution can be a valid optimum, but it can also indicate that one candidate dominates under this scoring target or that the candidate set lacks useful diversity. Large changes in weights after small changes to the candidate set or held-out subjects signal instability. These checks diagnose fragility; they do not by themselves establish good calibration or reliable extrapolation.

The scoring unit also matters. Giving each subject one joint trajectory density gives each subject one log-score contribution, but a long, densely sampled trajectory can still have a very different joint density scale from a short trajectory. Decide whether the target is the full trajectory, particular time points, or another defined prediction unit before constructing the score. The log score is sensitive to assigning very small density to an observed outcome, so a single poorly predicted subject can have substantial influence.

Stacking depends on the candidate set and on the observed validation cases. It cannot rescue an ensemble if all candidate models fail in the same way, and optimized weights do not guarantee performance outside the covariate, dose, or time ranges represented by the validation data. A posterior model probability offers a coherent Bayesian summary conditional on its models and priors; stacking offers a data-driven predictive combination for a specified scoring target. A single selected model is simpler to interpret and deploy, but may discard predictive information. These are alternatives with different aims, not interchangeable estimates of one quantity.

Common pitfall: Treating a stacking weight of \(0.7\) as evidence that the corresponding model has a 70% probability of being true. The correction is that the weight is the coefficient that helps maximize the chosen cross-validated log predictive score, subject to the weights summing to one. Interpret it as a predictive combination weight, and report the validation target and scoring unit alongside it.

Check Your Understanding

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

  1. For two models, what does a boundary optimum \(w=1\) mean, and does it necessarily mean the optimization failed?
  2. Why must all observations from a subject be excluded when the prediction target is a new subject’s trajectory?
  3. Two models predict means \(5\) and \(9\) units with stacking weights \(0.25\) and \(0.75\). What is the ensemble predictive mean?
  4. Why can a stacked mixture of normal predictive distributions fail to be normal?

Solutions. (1) It means the objective is maximized at weight one for model 1 and zero for model 2 over the feasible interval. This can be a valid optimum; strict concavity implies uniqueness when the model-specific densities differ for at least one subject, even if the maximum is at the boundary. (2) Retaining any of that subject’s outcomes during fitting would allow information from the held-out trajectory to influence the prediction, so the validation would not mimic prediction for a genuinely new subject. (3) The mean is \(0.25(5)+0.75(9)=1.25+6.75=8.00\) units. (4) A weighted mixture can retain distinct component means or variances and can therefore have a shape that is not normal, even though each component is normal.

Clinical Biostats