Tutorials › Nonlinear Mixed-Effects Models (NLME) › Checking Objective Function Reproducibility

Estimation Failures and Troubleshooting · Tutorial 277 of 797

Checking Objective Function Reproducibility

Learn a practical protocol for testing whether an NLME objective function is reproducible and how to respond when repeated evaluations disagree.

Advanced 11 min read

What You'll Learn

  • Define a fixed-point reproducibility check for an NLME likelihood objective.
  • Separate deterministic repeatability checks from variation across random seeds.
  • Summarize repeated objective values with a range and sample standard deviation.
  • Judge whether evaluation noise is large enough to obscure optimizer progress.
  • Diagnose likely sources of nondeterminism and choose targeted follow-up checks.
  • Explain the limitations of reproducibility checks as evidence about model adequacy or convergence.

Why Repeat an Objective-Function Evaluation?

An optimizer decides where to move by comparing objective-function values. That comparison is only useful if the values are stable enough to distinguish meaningful changes in the parameters from variation in the calculation itself. In a nonlinear mixed-effects model, evaluating the likelihood can involve integrating over random effects. Depending on the implementation, the calculation may use deterministic approximations, simulation, or numerical routines whose results are sensitive to tolerances and computation order. A run can therefore appear to improve, stall, or converge partly because the objective itself varies when nothing in the model or data has changed.

A reproducibility check isolates this issue. Hold the model, data, parameter values, and evaluation settings fixed; evaluate the objective repeatedly; then quantify how much the reported value varies. This is not a test of whether the model fits well, nor does a stable value prove that the optimizer found the best estimate. It asks a narrower but important question: does the calculation return essentially the same objective for the same input?

Definition: Let \(D\) denote the fixed data and \(\theta\) a fixed vector of model parameters. A deterministic objective evaluator returns the same value \(F(\theta;D)\), up to a stated numerical tolerance, on every repeated evaluation under identical conditions. A stochastic evaluator returns values \(\hat F_r(\theta;D)\) that can vary across repetitions \(r\), even though \(D\) and \(\theta\) are unchanged.

Many NLME programs report an objective proportional to the negative log likelihood, often \(F=-2\ell\), where \(\ell\) is the log likelihood. Under that convention, a smaller objective corresponds to a larger likelihood. Software may report a different scaling or add a constant, so use the same definition and settings throughout a check. A constant added to all evaluations does not affect their differences, but mixing objective conventions makes the comparison meaningless.

Conditions for a Valid Check

The purpose is to vary only the evaluation itself. Keep the parameter vector exactly fixed, including any transformations used internally, and use the same data records, model code, likelihood definition, and numerical settings. Do not allow an optimizer step, parameter update, data filtering operation, or change in integration settings between repetitions. Record the random-number seed and whether the program reuses a random stream. If the data or settings change, a difference in objective values cannot be attributed specifically to repeatability.

There are two useful but distinct tests. Repeating with the same seed and same execution conditions checks whether the computation is deterministic given its random stream and whether program state is controlled. Repeating with different seeds estimates variation attributable to stochastic integration or simulation. If the evaluator is intended to be deterministic, same-condition repeats should agree within an appropriate numerical tolerance. If it is intentionally stochastic, different-seed repeats need not agree exactly; the key question is whether their spread is small enough for the intended optimization decisions.

The data should also be the same in the sense relevant to the likelihood: identical observations, covariates, event records, and missing-data handling. In a parallel calculation, thread count and reduction order can affect rounding. These are part of the computation conditions and should be recorded rather than silently changed. Before interpreting a discrepancy, verify that the repeated calls really used the same input and did not inherit a changed state from an earlier call.

How to Summarize Repeated Values

For \(R\) repeated evaluations, calculate their mean, sample standard deviation, and range. The mean describes the average reported objective in these repetitions; the standard deviation and range describe observed variation. They are diagnostics, not a universal pass/fail test. The acceptable difference depends on the objective scale, the optimizer's stopping rules, and the size of objective changes that matter in the fit.

$$ \bar F=\frac{1}{R}\sum_{r=1}^{R}\hat F_r,\qquad s_F=\sqrt{\frac{\sum_{r=1}^{R}(\hat F_r-\bar F)^2}{R-1}},\qquad \text{range}=\max_r(\hat F_r)-\min_r(\hat F_r). $$

A short set of repetitions can reveal substantial instability, but a small observed range does not guarantee that all possible evaluations will agree. For stochastic methods, more repetitions provide a more informative estimate of variability. For deterministic methods, repeat the exact call first; if values differ, then change one computational condition at a time to help locate the source.

Worked Example: Detecting Simulation Noise at One Parameter Vector

Suppose a hypothetical NLME model is evaluated five times at the same parameter vector and fixed data, using different simulation seeds. The reported \(-2\) log-likelihood values are 1240.8, 1241.4, 1240.9, 1241.7, and 1241.2. The optimizer's recent candidate steps have changed the objective by about 0.2 units.

The mean is \( \bar F=(1240.8+1241.4+1240.9+1241.7+1241.2)/5=6206.0/5=1241.2 \). The deviations from the mean are \(-0.4,\ 0.2,\ -0.3,\ 0.5,\ 0\). Therefore, \(s_F=\sqrt{(0.16+0.04+0.09+0.25+0)/4}=\sqrt{0.135}=0.3674\). The range is \(1241.7-1240.8=0.9\).

The observed spread is larger than the approximately 0.2-unit changes being used to judge recent progress. This is evidence that, at this simulation effort, evaluation noise may obscure whether such a candidate step improves the objective. It is not evidence that the parameters are wrong or that the model is inadequate. The next check is to increase integration or simulation effort, then repeat at the same parameter vector and compare the spread. The numerical result does not by itself establish how much more effort is sufficient.

Why Evaluation Noise Can Mislead Optimization

An optimizer compares objective values at different parameter vectors. Write a stochastic evaluation as \(\hat F(\theta)=F(\theta)+\epsilon\), where \(F(\theta)\) is the target objective and \(\epsilon\) is evaluation error. For a proposed move from \(\theta_0\) to \(\theta_1\), the observed difference is \(\hat F(\theta_1)-\hat F(\theta_0)=F(\theta_1)-F(\theta_0)+\epsilon_1-\epsilon_0\). Thus, the comparison includes the difference in evaluation errors as well as the actual change in the objective.

A simple justification makes the practical issue clear. If the errors at the two points are independent, have mean zero, and each have variance \(\tau^2\), then their difference has variance \(2\tau^2\), because \(\operatorname{Var}(\epsilon_1-\epsilon_0)=\operatorname{Var}(\epsilon_1)+\operatorname{Var}(\epsilon_0)=2\tau^2\). Its standard deviation is therefore \(\sqrt{2}\tau\). When the true objective change is small relative to this scale, the observed comparison can have the wrong sign. If the errors are approximately normal, the probability of a wrong sign for a true change of magnitude \(|\Delta|\) is \(\Phi(-|\Delta|/(\sqrt{2}\tau))\), where \(\Phi\) is the standard normal cumulative distribution function. The normal approximation is not required for the diagnostic; it illustrates why small optimizer steps are vulnerable to noisy evaluations.

Using common random numbers at nearby parameter values can sometimes make the errors positively correlated and reduce the variance of their difference. That may help a comparison, but it does not make either objective value deterministic. A reproducibility report should say whether the evaluations used common or independent random streams rather than treating the resulting variability as interchangeable.

1
Freeze the evaluation input.
Save the data, parameter vector, model and likelihood settings, numerical tolerances, seed policy, and relevant parallel-computing settings.
2
Repeat without optimization.
Call the objective at the saved parameter vector several times. First use identical conditions; then use different seeds if stochastic integration is involved.
3
Quantify and compare variation.
Report the repeated values, their sample standard deviation and range, and the size of objective changes relevant to the fitting decisions.
4
Change one computational feature at a time.
If the spread is concerning, investigate simulation effort, integration settings, solver tolerances, parallel execution, or state and caching behavior, then repeat the fixed-point check.

Worked Diagnostics

Worked Example: Checking a Nearly Deterministic Evaluation

At a fixed parameter vector and data set, a hypothetical program reports 836.4127, 836.4128, 836.4127, and 836.4131 under repeated runs with identical settings. The reported objective is \(-2\ell\). The range is \(836.4131-836.4127=0.0004\). The relative range, using the mean as a scale, is approximately \(0.0004/836.4128=4.782\times10^{-7}\).

The values agree closely at the displayed precision, although they are not bit-for-bit identical. This may be consistent with small floating-point differences, for example from a different summation order. Whether it is acceptable depends on the fitting task: compare \(0.0004\) with the objective changes and stopping tolerances relevant to the optimizer. The relative range alone does not establish that the calculation is adequate, and a difference this small does not identify its cause. If exact repeatability is required, check whether the same execution path, thread count, and data ordering were used.

Worked Example: Comparing Two Levels of Simulation Effort

At a single fixed parameter vector, suppose a hypothetical simulation-based evaluator produces four objective values with 500 draws: 1002.4, 1001.7, 1002.1, and 1003.0. Their mean is \(4009.2/4=1002.3\), and their range is \(1003.0-1001.7=1.3\). The sample standard deviation is \(s_F=\sqrt{(0.01+0.36+0.04+0.49)/3}=\sqrt{0.30}=0.5477\).

After increasing the effort to 8000 draws, four new evaluations at the same parameter vector give 1002.05, 1002.18, 1002.11, and 1002.08. Their mean is \(4008.42/4=1002.105\), and their range is \(1002.18-1002.05=0.13\). The sample standard deviation is \(s_F=\sqrt{(0.003025+0.005625+0.000025+0.000625)/3}=\sqrt{0.0031}=0.05568\).

The observed range and sample standard deviation are both smaller with 8000 draws in this hypothetical check. This supports increasing the effort as a way to reduce the observed simulation variability. Four repetitions are still limited evidence, and a smaller spread does not prove the approximation is unbiased or that every parameter region will behave similarly. Repeat the check at points relevant to the fit before relying on the objective comparisons there.

Failure Modes, Alternatives, and Limits

If identical-condition repeats differ more than expected, do not immediately label the optimizer as failed. First confirm that the inputs are truly fixed. Then investigate potential sources in a controlled order. Randomized integration can cause variation across seeds; insufficient integration effort can leave variation large enough to affect comparisons. Numerical solvers and quadrature can be sensitive to tolerances. Parallel calculations can change the order in which floating-point values are combined. A stateful implementation, unintended cache reuse, or an accidental change to records or settings can also produce a discrepancy. Change one feature at a time so the result is interpretable.

The main alternative to repeated evaluation is to inspect a single objective value and rely on the software's convergence output. That is faster, but it cannot reveal whether the evaluator itself changes at a fixed point. A complementary approach is to repeat evaluations with a more accurate or deterministic integration method, where available. Agreement between methods is useful evidence about numerical stability, but it is not guaranteed: different approximations can share bias, and changing methods can change the numerical objective. These checks address computation, not model adequacy.

There is no universal cutoff for an acceptable objective-function range. A variation of 0.1 may be irrelevant if meaningful comparisons differ by many units, or consequential if the optimizer is distinguishing changes much smaller than 0.1. Similarly, the sample standard deviation across a few stochastic evaluations is uncertain. Report the actual repeated values and the conditions used, not only a declaration that reproducibility “passed.”

Finally, fixed-point reproducibility is not a substitute for examining parameter estimates, gradients, or other convergence evidence. A perfectly repeatable objective can be evaluated at a poor parameter vector, and stable repeated evaluations do not prove global optimality. Conversely, noisy objective evaluations can complicate optimization even when the underlying statistical model is appropriate. The check tells you whether the computational objective is stable enough to support the decisions being made; it does not settle those other questions.

Common Mistake

Common mistake: “The objective changed between two optimizer iterations, so the model improved.” That conclusion is not justified if the calculation itself varies. Repeat evaluations at the same fixed parameter vector first. If their spread is comparable to the apparent improvement, the direction of that small change is uncertain. Reduce or characterize the evaluation variability before interpreting it as optimization progress.

Check Your Understanding

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

  1. Why must the parameter vector and data be held fixed when checking objective-function reproducibility?
  2. At one fixed point, four hypothetical values are 510.2, 510.5, 510.1, and 510.4. Calculate the mean and range. What can you conclude if recent optimizer changes are about 0.1?
  3. What is the difference between repeating with the same random seed and repeating with different seeds?
  4. Name two computational settings or behaviors that could cause small differences in an otherwise deterministic evaluation.
  5. Does a very small repeated-evaluation range prove that the NLME model fits well? Explain.

Solutions. (1) Holding the data and parameters fixed isolates variability in the calculation. If either changes, an objective difference could reflect a different likelihood input rather than reproducibility. (2) The mean is \((510.2+510.5+510.1+510.4)/4=2041.2/4=510.3\). The range is \(510.5-510.1=0.4\). Since 0.4 exceeds the approximate 0.1 optimizer changes, the observed spread could obscure those small comparisons; repeat and investigate the evaluation. (3) Same-seed repeats check repeatability under the same random stream and execution conditions. Different-seed repeats help quantify variability due to random simulation or integration. (4) Examples include changed parallel summation order and different solver tolerances; data ordering or stateful caching may also matter. (5) No. A small range supports computational stability at that fixed point under the tested conditions. It does not show that the parameter vector is optimal or that the model adequately describes the data.