
The mathematics of aggregate data modelling
H. van de Beek
2026-05-29
Source:vignettes/articles/introducing-admixr2.Rmd
introducing-admixr2.RmdWhy aggregate data?
Meta-analysis in pharmacometrics means combining evidence across studies for estimates no single study could support alone. The classical approach pools individual patient data (IPD) into one dataset — scientifically ideal, and rare: data sharing agreements, proprietary restrictions and the fact that most published work reports only summary statistics make IPD pooling the exception.
Model-based meta-analysis (MBMA) fits pharmacometric models directly to aggregate summaries instead. Those summaries come from two sources. Directly published: many studies report a mean concentration-time profile with the variance at each time point, sometimes the full covariance matrix. Model-derived: a published model and its estimates (fixed effects, random-effects variance, residual error) generate the expected mean vector and covariance by simulation, without the original data. The covariance carries information about the shape of individual profiles that a variance-only summary discards — two studies can share every variance and differ entirely in correlation structure, reflecting different sources of variability. Both types analyse within the same framework, which makes the full literature — competitor compounds, historical datasets, regulatory submissions — available for dose selection, trial design and disease-progression modelling.
The aggregate data likelihood, first systematically described by Välitalo (2021), provides the statistical foundation for MBMA: given a nonlinear mixed-effects model, what is the probability of observing the reported mean and covariance? The first R implementation was admr, described in van de Beek et al. (2025). admixr2 re-implements the same approach within the nlmixr2/rxode2 ecosystem, extending it with new algorithmic ideas that are the focus of this post.
The aggregate likelihood
Observed data
For a single study with subjects, each measured at observation times , the observed data are two sufficient statistics:
where is the observed mean vector and is the observed covariance matrix (ML denominator , not ).
The model
A nonlinear mixed-effects model specifies that subject ’s observations arise from
where is an ODE system (or closed-form prediction function) with structural parameters and individual random effects . is the between-subject covariance, is the residual error covariance (typically a diagonal function of the structural prediction, e.g. proportional error).
Population moments
Under this model the population-level distribution of has mean and covariance
This is the law of total variance, and the second term is written out
rather than abbreviated to
for a reason. Only for additive error is the residual
variance free of the prediction, giving
.
With prop(), pow() or lnorm() it
is a function of
,
and averaging it over subjects is not evaluating it at the population
mean — for proportional error the two differ by exactly
.
admixr2 averages. Writing
throughout is the “no
–
interaction” convention of individual-level fitting, and it understates
here; see Choosing a residual error
model. The sections below write
for brevity, with that averaging understood.
The aggregate log-likelihood
If the subjects are independent and drawn from the same population, the sample mean follows approximately , and the sample covariance concentrates around . Under a multivariate normal approximation to the joint density of , the log-likelihood reduces to
This is the central formula in admixr2. Every estimator minimises it; they differ only in how and are computed.
The trace and quadratic terms go through a Cholesky factorisation of , avoiding explicit inversion and staying stable even for near-singular covariances. The log-determinant falls out as twice the sum of the factor’s log-diagonal.
The integration problem
For a nonlinear ODE model,
and
are integrals over
.
There is no closed form. The four estimators differ in how they handle
this intractability: adfo linearises the integrand,
admc samples it randomly, adgh integrates it
on a deterministic quadrature grid, and adirmc reuses a
fixed sample, iteratively reweighting it as the parameters move.
First-Order linearisation (adfo)
The simplest approach approximates by its first-order Taylor expansion around :
Substituting into the population moment definitions gives closed-form expressions:
The Jacobian is the sensitivity matrix of the ODE output with respect to the random effects, evaluated at . In admixr2 it is obtained by augmenting the ODE system with sensitivity equations
where is the ODE right-hand side. One solver call delivers and every column of together, with no extra solve per random-effect dimension. Its predecessor admr computed this Jacobian by finite differences on , one extra solve per dimension.
Gradient of the FO NLL. Because is explicit in and , the gradient with respect to these parameters is available analytically via the matrix derivative identities and . Structural parameter gradients need the second derivative , which admixr2 takes from an order-2 sensitivity model, so they too are analytical; central finite differences are the fallback for when that model cannot be built.
Accuracy. Exact when is linear in . For nonlinear models at large IIV it underestimates , so comes out too small and negatively biased. In practice the bias is negligible below a CV of 20–30 % on each PK parameter, on a model weakly nonlinear in .
Monte Carlo simulation (admc)
The MC estimator makes no approximation to . It draws random-effect samples and computes sample moments:
It converges to the true population moments as , and its AIC is directly interpretable.
Quasi-random sampling. admixr2 draws from Sobol sequences (also in admr) rather than pseudo-random normal deviates. Sobol points are low-discrepancy, placed to fill gaps in the sample space rather than clustering at random. On the smooth integrands of pharmacometric MC integration that uniform coverage cuts the integration error at a given , for no extra model evaluations.
Numerical stability. The sample covariance accumulates centred products in a single pass through fused C++ kernels, avoiding an intermediate allocation, and the resulting is positive semi-definite by construction.
Gauss-Hermite quadrature (adgh)
MC replaces the population integral with a random average; GH replaces it with a deterministic one, a tensor-product Gauss-Hermite rule evaluating the same expectation over at a small set of fixed nodes. It is new in admixr2, with no counterpart in admr.
For a single random effect, the probabilists’ Gauss-Hermite rule approximates an expectation under the standard normal by a weighted sum over nodes,
with nodes and weights (normalised so and ) obtained from the Golub-Welsch algorithm — the eigendecomposition of the symmetric tridiagonal Jacobi matrix of the Hermite recurrence, requiring no external tables. For random effects the rule is applied as a tensor product, giving a grid of nodes with product weights. The Cholesky factor () maps the standard-normal nodes into the correlated random-effect space, , so the population moments become
Structurally this is the MC estimator with a fixed deterministic node grid in place of random draws and quadrature weights in place of uniform ones, so it plugs into exactly the same aggregate MVN .
Noise-free objective. Fixed nodes and weights make
the objective a smooth deterministic function of
— no Monte Carlo noise to average away, no n_sim to tune.
The analytical gradient (closed-form contractions through the same ODE
sensitivity outputs the MC estimator uses) is therefore exact, and the
numerical Hessian behind the standard errors is well-conditioned. Like
admc it approximates nothing about
,
so it is unbiased at any IIV, on the same likelihood scale, and its AIC
compares directly to admc and adirmc.
Cost.
grows exponentially in the number of random effects. Up to ~4 etas it
stays small
()
and adgh is substantially faster than MC at equal accuracy;
beyond that the node count becomes prohibitive and admc or
adirmc are preferable. n_nodes = 5 gives
near-exact covariance moments to IIV SD ~0.5, and 7 extends that to
~0.7.
Iterative Reweighting MC (adirmc)
MC’s central bottleneck is that every NLL evaluation takes ODE solves, one per sample — expensive on a complex model, over the hundreds of evaluations an L-BFGS optimisation may need. IRMC decouples sample generation from optimisation.
Proposal distribution
At each outer phase, proposals are drawn once from an inflated prior:
where is the current Omega estimate and the expansion factor. The predictions are computed once, stored, and reused for the rest of the inner optimisation without further ODE solves.
Importance weights
A move to a candidate leaves the stored predictions inexact. For the random-effects covariance, the proposals are reweighted by the ratio of target to proposal density:
Weights are normalised by softmax, and the weighted mean and covariance of the predictions are the IRMC estimates of and :
With fixed proposals the inner objective is a smooth deterministic function of , optimisable to high precision. Proposals refresh between phases, whose box constraints tighten progressively to guide global convergence, so the number of ODE solves scales with phases rather than inner steps.
Gradient computation: from finite differences to sensitivity equations
The gradient is the single most important ingredient in efficient nonlinear optimisation, and it is where admr and admixr2 differ most consequentially.
Gradient in admr
admr stores a fixed Sobol base matrix biseq for the
lifetime of an optimisation run. Random-effect samples are formed as
, so the NLL is a smooth
deterministic function of the parameter vector for fixed
biseq. The gradient for the MC estimator is computed by
forward finite differences of this deterministic NLL:
On a model with
parameters each gradient call therefore costs
extra NLL evaluations,
additional ODE solves. That being expensive, admr defaults to
gradient-free BOBYQA, with L-BFGS and an FD gradient available but off
(use_grad = FALSE).
Under IRMC, proposals are fixed inside a closure before the inner optimisation, so each inner NLL evaluation is matrix operations only. admr’s optional FD inner gradient costs extra importance-weighted recomputations per step and no ODE solves — but the inner optimizer still defaults to BOBYQA, and the FD approximation carries truncation error of order .
CRN analytical gradient in admixr2
admixr2 fixes the sample set and computes the gradient of the frozen deterministic MC NLL analytically — an application of the Common Random Numbers (CRN) identity.
For a mu-referenced parameterisation , the chain rule gives
i.e. the sample average of the ODE sensitivity output — which is already available from the NLL evaluation via the augmented ODE system. No additional ODE solves are needed.
The gradient of with respect to follows similarly: the Cholesky factor () enters through the sample covariance, and differentiating through the MVN chain rule gives closed-form expressions in the stored sensitivity outputs.
So the full MC gradient costs the same as a single NLL evaluation — no extra ODE solves, and exact rather than a finite-difference approximation. On a model with parameters and samples, admr’s FD gradient needs additional solves per optimizer step; admixr2’s CRN gradient needs none.
Analytical IRMC inner gradient
The importance-weighted inner objective has a tractable analytical gradient with respect to both and . The gradient passes through the softmax normalisation via the identity
where . Differentiating the MVN log-likelihood of the weighted mean and covariance through this identity gives closed-form expressions in the pre-computed ODE solutions and sensitivity outputs. Fixed proposals mean no inner gradient evaluation needs an ODE solve under any implementation, so the gain over admr’s FD approach is exactness and a reduction in inner-level matrix operations.
The inner optimizer therefore runs L-BFGS on an exact gradient, converging in far fewer iterations than BOBYQA.
Kappa correction for non-mu-referenced parameters
Both packages handle structural parameters entering with no paired random effect (, but has no ). Changing one during the inner IRMC optimisation leaves the stored predictions inexact even in the mean, so both apply a kappa correction:
shifting by the predicted change at .
admixr2 adds a linearized kappa
(kappa_method = "linearized") that computes
once per outer iteration from one batched FD solve, then takes the
correction as
through the inner loop — matrix work only, no solver calls. That matters
most on complex ODE systems: exact kappa costs one extra rxSolve per
inner NLL step for the single-beta parameters, while linearized kappa
leaves the inner loop entirely free of them.
Parameter space geometry
Cholesky parameterisation of
must be positive definite, and unconstrained optimisation over symmetric matrices can step outside that.
Both packages parameterise it through a Cholesky factor (), and differ in how the entries are encoded. admr uses a log transform on the diagonal and a covlogit off it, mapping each ’s corresponding correlation through a logit after normalisation. admixr2 uses:
The raw form simplifies the gradient substantially — is a rank-1 matrix with no logit derivative to chain through — and avoids the instability of logit transforms as correlations approach ±1.
Encoding rather than equalises gradient sensitivity across parameter types: a unit optimizer step changes by , matching structural parameters on the log scale.
Parameter preconditioning
The unconstrained parameter vector is pre-scaled by a diagonal before reaching L-BFGS, each entry estimating the curvature in that direction: unity for exponential transforms, a derivative-based magnitude for logit/probit, and off the Cholesky diagonal. This lowers the condition number and speeds convergence wherever structural parameters and variance components differ by orders of magnitude.
Summary of improvements over admr
admr (van de Beek et al., 2025) established the core aggregate data workflow in R. admixr2 keeps its three estimators (FO, MC, IRMC) and the same aggregate MVN likelihood, adds a fourth deterministic Gauss-Hermite estimator, and replaces the surrounding architecture and several algorithmic components.
| Aspect | admr | admixr2 |
|---|---|---|
| Ecosystem | Standalone R package | nlmixr2/rxode2 integration |
| Model syntax | Custom genopts() + prediction function |
nlmixr2 ini() / model() blocks |
| Fit object | Plain list | nlmixr2 fit object (AIC, logLik, plot, print) |
| Estimators | FO, MC, IRMC | FO, MC, GH, IRMC |
| Gauss-Hermite quadrature estimator | Not available | New deterministic, noise-free estimator |
| FO Jacobian () | C++ finite differences | ODE sensitivity equations |
| MC gradient | FD of frozen MC NLL ( extra solves) | CRN analytical (0 extra ODE solves) |
| IRMC inner optimizer | BOBYQA (default) or FD gradient | L-BFGS with analytical gradient |
| Linearized kappa | Not available | Optional; eliminates ODE calls in inner loop |
| off-diagonal encoding | covlogit (correlation logit) | Raw Cholesky entry |
| Parameter preconditioning | No | Yes (diagonal scaling) |
| Parallel restarts | Sequential chains |
mirai workers |
The gradient improvements are the most consequential. Going from extra ODE solves per step (admr FD) to none (admixr2 CRN) cuts wall-clock fitting time by one to two orders of magnitude for gradient-based algorithms on complex models. The analytical IRMC inner gradient compounds it: the inner optimisation converges in fewer iterations, each iteration is faster, and linearized kappa lets the whole inner loop run without touching the ODE solver.
Further reading
The papers linked at the top give the mathematical foundations in
full. Estimator comparison works
all four estimators through the included examplomycin
dataset, and Advanced usage covers gradient
modes, multi-restart fitting and model comparison via AIC.