Tutorials › Pharmacometric Workflows and Reproducible Modeling › Replicate Fits to Detect Numerical Instability

Debugging Model Failures · Tutorial 166 of 399

Replicate Fits to Detect Numerical Instability

Use controlled replicate fits to test whether an estimated solution is reproducible, sensitive to starting values, or affected by numerical error.

Advanced 11 min read

What You'll Learn

  • Separate same-start reproducibility checks from small-perturbation basin searches.
  • Compare fitted parameters on meaningful scales, alongside objective values and gradients.
  • Use local curvature to understand why numerical error can cause large parameter shifts.
  • Check whether conclusions persist when numerical accuracy settings are tightened.
  • Recognize when similar objective values do not imply similar parameter estimates.
  • Report replicate-fit evidence without claiming it proves a global optimum.

Why Replicate Fits Are a Debugging Tool

An optimizer can report convergence even when its result is sensitive to numerical details. In a pharmacometric model, small changes in starting values, numerical integration accuracy, or gradient calculations may lead to noticeably different estimates. Comparing replicate fits is a practical way to detect that sensitivity before treating a fitted parameter vector as a reliable solution.

The purpose is diagnostic, not to estimate sampling variability. Replicates here are repeated optimization runs using the same data and model, with selected inputs held fixed or deliberately varied. A useful comparison asks whether the runs reach similar parameter values, objective values, gradients, and model predictions. Agreement is evidence of reproducibility under the conditions tested; it is not proof that the global optimum has been found.

Definition: A same-start replicate reruns the same optimization problem from the same initial parameter values, with the same model, data, numerical settings, and stopping rules. A perturbed-start replicate changes the initial values slightly while keeping the other conditions fixed. A replicate comparison is a numerical diagnostic that summarizes how the fitted results vary across such runs.

Design the Comparison Before Running It

First choose the quantity being minimized. Write it as \(L(\theta)\), where \(\theta\) is the vector of estimated model parameters. It may be a negative log-likelihood or another stated objective. Keep the model, data, parameterization, constraints, and objective definition fixed when testing starting-value sensitivity. Record each run's initial and final values, objective, convergence status, and available gradient diagnostic.

Exact same-start runs answer a narrow but useful question: does the computational procedure reproduce itself under identical inputs? If they differ, check whether the software is deterministic and whether any unrecorded settings or random elements vary. If identical runs agree, that alone does not rule out dependence on the starting point. Small perturbations address that separate question.

Parameter differences need a scale. A raw difference of 0.1 may be negligible for a parameter near 100 but substantial for one near 0.2. Before comparing runs, set a meaningful scale \(q_j\) for each parameter \(\theta_j\), such as a scientifically interpretable change or a representative fitted magnitude. One summary is the maximum scaled difference between two runs:

$$ d(\theta^{(a)},\theta^{(b)}) = \max_j \frac{|\theta_j^{(a)}-\theta_j^{(b)}|}{q_j}. $$

The scales should be reported and chosen before interpreting the differences. They are diagnostic yardsticks, not universal acceptance thresholds. Compare objective differences as well, and inspect predictions at clinically relevant times or covariate values. Similar objective values can coexist with materially different parameter estimates, particularly when the objective is relatively flat in some directions.

1
Establish a baseline.
Run the intended fit and save its starting values, fitted values, objective, and convergence diagnostics.
2
Repeat from the identical start.
Keep the model, data, numerical settings, and stopping rules unchanged. Investigate any material disagreement before varying starts.
3
Try small, controlled perturbations.
Change starting values modestly, including more than one direction when feasible. Keep all non-starting inputs fixed.
4
Compare more than the optimizer message.
Assess scaled parameter differences, objective values, gradients, convergence status, and relevant predictions.
5
Vary numerical accuracy separately.
If results suggest sensitivity, tighten relevant numerical settings in a controlled follow-up and compare results on a common basis.

Why Small Numerical Errors Can Move an Estimate

A local argument explains why replicate fits can be sensitive even when the objective values look stable. Suppose \(L(\theta)\) is twice differentiable near a fitted point \(\hat{\theta}\), the point is interior, and its gradient is approximately zero. Let \(H\) be the Hessian matrix of second derivatives there. For a small parameter change \(\delta\), a second-order expansion is

$$ L(\hat{\theta}+\delta) \approx L(\hat{\theta})+ \nabla L(\hat{\theta})^\mathsf{T}\delta+ \frac{1}{2}\delta^\mathsf{T}H\delta \approx L(\hat{\theta})+\frac{1}{2}\delta^\mathsf{T}H\delta. $$

When curvature is weak in some direction, a substantial movement in that direction may change \(L\) very little. Thus, near-equal objective values do not ensure close parameter estimates. Conversely, if the computed gradient has a small numerical error \(\eta\), the apparent stationarity condition near the true stationary point is approximately \(H\delta+\eta=0\). If \(H\) is invertible, this gives

$$ \delta\approx -H^{-1}\eta. $$

This relation follows by linearizing the gradient: \(\nabla L(\hat{\theta}+\delta)\approx H\delta\), then setting the computed gradient \(H\delta+\eta\) to zero. It shows why a small gradient error can produce a large parameter shift when curvature is weak. The argument is local and assumes a smooth objective and a suitable interior stationary point. It does not diagnose every failure: constraints, nonsmoothness, poor integration, or a different basin can invalidate this approximation.

Worked Example: Same-Start Replicates Agree

Hypothetical data: Three runs fit the same PK model to the same dataset, using identical starts and numerical settings. The fitted values are clearance \(CL\) in L/h, volume \(V\) in L, and an absorption rate \(k_a\) in h\(^{-1}\). Their objective values are dimensionless.

Run\(k_a\) (h\(^{-1}\))\(CL\) (L/h)\(V\) (L)\(L(\theta)\)
10.84214.31732.08128.440
20.84224.31632.09128.441
30.84214.31732.08128.440

Use the prespecified comparison scales \(q_{k_a}=1\) h\(^{-1}\), \(q_{CL}=1\) L/h, and \(q_V=10\) L. Between runs 1 and 2, the scaled differences are \(0.0001/1=0.0001\), \(0.001/1=0.001\), and \(0.01/10=0.001\). Therefore \(d=0.001\). The largest objective difference is \(128.441-128.440=0.001\).

These results show close same-start reproducibility on the chosen scales. They do not show that other starting values would reach the same fit. Before calling the fit adequate, also check each run's convergence diagnostics, relevant predictions, and whether the numerical settings are sufficiently accurate for the model.

Reading Patterns Across Runs

A useful interpretation separates three patterns. First, same-start runs that disagree point to a reproducibility problem: check nondeterministic components, numerical solver behavior, gradient calculations, stopping rules, and whether the inputs were truly identical. Second, same-start runs that agree but perturbed starts reach different endpoints suggest starting-value sensitivity. Third, changes that track numerical accuracy settings suggest the fit may depend on approximation error. These patterns can overlap, so change one factor at a time where possible.

Different endpoints do not automatically establish multiple genuine local minima. Some runs may have stopped prematurely, failed to satisfy constraints, or terminated at a point with a poor gradient. Check the termination reason and, when available, the gradient norm and curvature diagnostics. If two endpoints have similar objective values but different predictions, investigate whether the fit is weakly determined or whether the objective is being evaluated inconsistently. If objective values differ, the lower computed value is preferable only when both runs evaluate the same objective reliably and have converged adequately.

Worked Example: Perturbations Reach Different Endpoints

Hypothetical data: Six fits use small perturbations around the same initial PK parameter vector. All use identical data, model, and numerical settings. Three fits end near \((k_a, CL, V)=(0.72\ \text{h}^{-1}, 5.4\ \text{L/h}, 28\ \text{L})\) with \(L=92.63\); three end near \((1.05\ \text{h}^{-1}, 5.1\ \text{L/h}, 31\ \text{L})\) with \(L=92.71\). Each endpoint has a reported small gradient norm and successful termination.

Using scales \(q_{k_a}=0.1\) h\(^{-1}\), \(q_{CL}=1\) L/h, and \(q_V=10\) L, the scaled endpoint differences are \(0.33/0.1=3.3\), \(0.3/1=0.3\), and \(3/10=0.3\). Thus \(d=3.3\), indicating a large discrepancy on the chosen scales. The objective difference is \(92.71-92.63=0.08\), with the first endpoint lower.

The repeated endpoints suggest that the perturbations reached two distinct regions of parameter space. The lower-objective endpoint is better among these two computed fits, but the small objective difference does not establish that either is the global optimum. Check predictions, confirm comparable convergence quality, and test numerical accuracy. The evidence supports sensitivity to starts; it is not, by itself, proof of two valid local minima.

Worked Example: Separating Starting-Value and Accuracy Sensitivity

Hypothetical data: A model is fitted from one fixed start at two integration accuracy settings. At the looser setting the result is \(CL=6.80\) L/h, \(V=41.2\) L, and reported \(L=76.214\). At the tighter setting it is \(CL=6.82\) L/h, \(V=41.0\) L, and reported \(L=76.209\). To compare the parameter shifts, use \(q_{CL}=1\) L/h and \(q_V=10\) L.

The scaled differences are \(|6.82-6.80|/1=0.020\) and \(|41.0-41.2|/10=0.020\). The objective difference is \(76.214-76.209=0.005\), lower at the tighter setting. These numbers indicate modest setting sensitivity, but a single fit per setting does not tell whether starting values also matter.

As a controlled follow-up, repeat the small-start perturbation check at the tighter setting. If those runs cluster closely around the tighter-setting result, while the looser-setting fit remains shifted, evidence points toward sensitivity to numerical accuracy. If they still form separated endpoint groups, starting-value sensitivity remains. The comparison is meaningful only if the objective is evaluated consistently; where available, reevaluate candidate fits with a common, more accurate setting before ranking them.

Alternatives, Limitations, and Common Mistakes

Replicate fits are one debugging approach, not a replacement for other checks. Same-start repeats test computational reproducibility; perturbed starts explore local sensitivity; tighter tolerances test dependence on numerical accuracy. A simpler model or staged parameter release can help localize a failure, as in the earlier material on staged parameter release, but that changes the fitting problem and should not be mistaken for a replicate of the original model. Each approach answers a different question.

The number and size of perturbations affect what can be detected. A small search may miss a distant basin, while large perturbations may explore scientifically implausible regions or cross constraints. A failed run is informative but is not evidence of a competing solution. Likewise, matching parameter estimates and objectives across tested starts does not prove global optimality, identifiability, or good model adequacy. Check predictions and diagnostics alongside estimates.

Common mistake: “The objectives are almost identical, so the estimates are interchangeable.” This is not justified. Flat curvature can permit large parameter changes with little objective change. The correction is to compare scaled parameter differences and relevant predictions as well as objective values, then describe the result as weakly or strongly sensitive under the tested conditions. Do not claim the runs establish equivalent scientific conclusions unless the parameter and prediction comparisons support that claim.

A further practical failure is changing several things at once—for example, the starting values, integration tolerance, and optimizer settings. If the result changes, the cause is then unclear. Hold all but one factor fixed during a diagnostic comparison, and record the conditions and outcomes sufficiently to reproduce the comparison.

Check Your Understanding

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

  1. Same-start fits agree closely, but small perturbations lead to two different parameter vectors with similar objectives. What does this suggest, and what does it not prove?
  2. For two runs, a parameter differs by 0.04 and its prespecified comparison scale is 0.2. What is its scaled difference?
  3. Why can a small numerical gradient error create a large parameter shift in a weak-curvature direction?
  4. Why should integration accuracy and starting values usually be varied separately during diagnosis?

Solutions. (1) The result suggests starting-value sensitivity and possibly different basins, but it does not prove that both endpoints are valid local minima or that either is globally optimal. Check convergence, gradients, predictions, and numerical accuracy. (2) The scaled difference is \(0.04/0.2=0.20\). (3) Locally, \(\delta\approx-H^{-1}\eta\); when curvature is weak, the corresponding component of \(H^{-1}\) can be large, amplifying the gradient error. (4) Changing one factor at a time makes the source of a changed result interpretable; changing both leaves starting-value and accuracy effects confounded.

Clinical Biostats