Documentation

3.4 Build: autoinit, screen, fit

Building a base model has three questions in order. Where do I start? (autoinit), which structure? (screen) and what are the estimates and how certain are they? (fit). The three commands answer them from the dataset alone; none of them needs a control stream to begin.

3.4.1 autoinit: initial estimates from the data alone

nlmx autoinit data/analysis.csv -o out_init

Starting values matter: a fit that begins far from the optimum can stop at a poor solution, or not converge. autoinit derives them in three independent ways and combines them: a non-compartmental analysis, individual least-squares fits, and a machine-learning step (a k-nearest-neighbour search over simulated profiles). It reports all three beside the recommendation:

Dosing regimen
  group              subjects route                  doses               n/subj interval   SS infusion  samples  sampling
  all                     200 oral                   100                      5       24   no        –       10  0.5–108

Initial estimates — all (200 subjects, 2000 observations, oral; methods: nca, nls, ml)
  param          NCA         NLS          ML  recommended     OMEGA     CV%  note
  CL           3.765       3.352       3.357        3.486    0.1726      43  clearance (apparent, /F)
  V           42.071      43.839      44.163       43.348    0.0934      31  volume, one compartment (apparent, /F)
  KA           1.118         1.1       1.111         1.11    0.0224      15  first-order absorption rate
  ALAG             0           –           –            0         –       –  no lag needed (0% of oral subjects show one)
  F1               –           –           –            1         –       –  not identifiable without intravenous data: fix F1 = 1 …
  residual error: proportional 0.1715 (CV), additive 0.173 (SD); corr(CL, V) = 0.39

The three methods agree to within about 10 % on clearance and volume (3.77, 3.35 and 3.36 L/h against the recommended 3.49), which is the sign that the starting values are trustworthy. The command also states the regimen it found (200 subjects, oral, 100 mg five times at a 24-hour interval) and what it decided about lag time (none needed) and bioavailability (fixed at 1, because there are no intravenous data).

The most useful file is init_blocks.txt: ready-to-paste NONMEM blocks for one-, two- and three-compartment models with these estimates, for example

$SUBROUTINES ADVAN2 TRANS2
$PK
CL = THETA(1)*EXP(ETA(1))
V = THETA(2)*EXP(ETA(2))
KA = THETA(3)*EXP(ETA(3))
S2 = V
…
$THETA
(0, 3.4864) ; CL (clearance)
(0, 43.3481) ; V (central volume)
(0, 1.1097) ; KA (absorption rate)
(0, 1.7153E-1) ; proportional error (CV)
(0, 1.7300E-1) ; additive error (SD)
$OMEGA
1.7255E-1 ; IIV CL (CV 43%)
9.3385E-2 ; IIV V (CV 31%)
2.2394E-2 ; IIV KA (CV 15%)

The table of starting values is a reference, not a fit; Chapter 16 describes the three methods and their limits.

3.4.2 screen: which structural model?

nlmx screen data/analysis.csv -o out_screen

screen fits a set of candidate structures, starting from the autoinit values, and compares them. For oral data it fits first-order absorption with one, two and three compartments (1cmt_abs, 2cmt_abs, 3cmt_abs); for data that show nonlinear exposure it adds target-mediated drug disposition models (not here: "dose proportionality not assessable", since there is one dose level). It takes about 30 seconds, the longest step of the tour except the stochastic power run.

   1.53s stage fitting 1cmt_abs (1 of 3 candidate(s))
   8.55s warn  covariance step failed: OMEGA is not positive definite (diagonal [1.8609e-1, 1.0915e-1, -8.9859e-7])
   8.56s warn  OMEGA(3,3) is near its boundary: the variance collapsed to 1.01414E-7 (from 0.022394) …
   8.60s warn  1cmt_abs: the variance of the ETA on KA collapsed to about 0 or cannot be estimated (RSE > 100%); refitting without it
   …
  model                  OFV   k         AIC         BIC     ΔBIC  weight   cov  max RSE  max sh  flags
* 1cmt_abs          -2874.56   7    -2860.56    -2830.56     0.00   0.999    ok       3%      3%  –
  2cmt_abs          -2874.56   9    -2856.56    -2815.36    15.20   0.000    ok   > 999%      3%  imprecise
  3cmt_abs          -2874.56  11    -2852.56    -2800.16    30.40   0.000    ok   > 999%      3%  imprecise; ill-conditioned

Recommended base model: 1cmt_abs — 1 compartment, first-order absorption (ADVAN2 TRANS2)
  * lowest BIC among the 1 model(s) that passed the checks: 1cmt_abs (BIC = -2830.6)

Three things happened, and each is a lesson in reading a screen.

  1. A random effect was dropped, automatically and visibly. The first fit included a random effect on the absorption rate (ETA on KA), as autoinit had suggested. Its variance collapsed to about zero, the covariance step failed because the OMEGA matrix was no longer positive definite, and screen said so in three warnings and refitted without it. The note at the end repeats it. The sampling gives little information on absorption variability (Section 3.3), so the data cannot support an ETA on KA.
  2. The extra compartments added nothing. The two- and three-compartment models reach the same OFV as the one-compartment model (−2874.56 in all three) while adding two and four parameters. The likelihood-ratio tests, in the output, give ΔOFV of 0.00 with p = 1.0.
  3. The penalty tells the rest. BIC (here the corrected form BICc, which penalises the random-effect parameters by the number of subjects and the fixed ones by the number of observations) rises by 15 and 30 units; the larger models also fail the precision checks (imprecise: a relative standard error above 50 %; ill-conditioned: a condition number above 1000). The recommended model is the one-compartment model.

So the data-driven answer agrees with how the data were made. The recommendation is written as out_screen/best_model.ctl, a complete control stream with the final estimates as initial values; the models are in models/ and the comparison in model_comparison.csv and lrt_tests.csv. Its OFV, −2874.56, differs from the −2880.21 of run101 because the two fits use different data: screen leaves out the one negative observation (1,999 observations, not 2,000), and an OFV is only comparable between fits to the same data.

3.4.3 fit: estimate the base model

The demo project already holds a control stream, so the tour fits that one: run101.

nlmx fit models/run101.ctl --plots -o out_fit
   0.00s ok    model: ADVAN2 TRANS2: one compartment with first-order absorption; 5 THETA, 2 ETA, 1 EPS; 200 subjects, 2000 observations
   0.00s info  estimating 7 parameter(s) by foce_i (2 fixed); 2 ETA(s) integrated
   0.03s info  initial OFV -2880.2130
   0.72s ok    OFV -2880.2130 after 3 iteration(s), 66 function evaluations — relative OFV change below 1.0e-9 for 3 iterations
   0.72s stage covariance step (R^-1 S R^-1 (sandwich))
   1.33s ok    covariance step complete; condition number of the correlation matrix 3.386e0
   1.53s ok    8 publication plot(s) in plots/ (png, 2100×1500 px at 300 dpi)
   1.56s ok    22 output file(s) written

One feature of this run needs explaining. The control stream carries the final estimates of the generating fit as its initial values, so the objective at the start (−2880.2130) is already the optimum, and the estimation only confirms it in three iterations. The generating fit took nine. If you start from the autoinit values instead (put them in $THETA and $OMEGA of a copy of run101.ctl), the run starts at an OFV of −2529.41, takes 12 iterations and 198 function evaluations, and ends at the same optimum, −2880.2130, with the same estimates. That is what good starting values do: they shorten the route, and a model with a well-defined optimum arrives at the same place from either side.

The listing

The listing printed at the end of the run is also written to fit_summary.txt and fit_summary.json.

Problem           : run101 base model (one-compartment oral, ADVAN2)
Model             : ADVAN2 TRANS2: one compartment with first-order absorption; 5 THETA, 2 ETA, 1 EPS
Estimation        : foce_i
Termination       : MINIMIZATION SUCCESSFUL — relative OFV change below 1.0e-9 for 3 iterations
Iterations        : 3 (66 objective evaluations)
OBJECTIVE FUNCTION VALUE (OFV): -2880.2130

Parameter estimates
  parameter    label                      estimate          SE     RSE%                    95% CI        derived   shrink%
  THETA(1)     THETA(1) TVCL: typica…      3.34458    0.103564      3.1         [3.1416, 3.54756]
  THETA(2)     THETA(2) TVV: typical…      43.7421     1.09379      2.5        [41.5983, 45.8859]
  THETA(3)     THETA(3) KA: absorption…    1.09728    0.017486      1.6        [1.06301, 1.13155]
  THETA(4)     THETA(4) proportional…     0.175994  0.00333197      1.9      [0.169463, 0.182524]
  THETA(5)     THETA(5) additive res…    0.0235345  0.00446095     19.0    [0.0147912, 0.0322778]
  OMEGA(1,1)   CL (iiv)                   0.186284   0.0188743     10.1      [0.149291, 0.223277]    45.2509 CV%       1.6
  OMEGA(2,2)   V (iiv)                     0.10911    0.010959     10.0     [0.0876309, 0.130589]    33.9537 CV%       3.0
  SIGMA(1,1)                                     1           –        –                     FIXED           1 SD

  EPS shrinkage (1 - SD(IWRES)): 10.2%
Covariance step: R^-1 S R^-1 (sandwich) on 7 parameter(s)
  eigenvalues of the correlation matrix: min 4.7003e-1, max 1.5916e0; condition number 3.3862e0

Read it in five steps.

  1. Termination. MINIMIZATION SUCCESSFUL with the criterion that stopped it. The objective is on NONMEM's scale; a lower value is a better fit.
  2. The estimates against the truth. The typical clearance is 3.34 L/h and the typical volume 43.7 L; these match the autoinit values within a few per cent. The absorption rate constant is 1.10 per hour.
  3. Precision. The relative standard error (RSE%) is the standard error as a percentage of the estimate. The typical values and the proportional error are at 3 % or less, and the additive error is at 19 %: it is small and poorly determined, as is usual when the proportional error dominates. The between-subject variances have RSEs of 10 %.
  4. Variability. OMEGA(1,1) = 0.186 is a between-subject coefficient of variation of 45 % on clearance, and OMEGA(2,2) = 0.109 one of 34 % on volume.
  5. Shrinkage. The shrinkage of the random effects is 1.6 % (CL) and 3.0 % (V), and of the residuals 10.2 %. Low shrinkage means the individual estimates are informative, so the diagnostic plots based on them can be trusted.

The covariance step uses the sandwich estimator, and the condition number of the correlation matrix of the estimates, 3.4, shows no near-collinearity between the parameters (a number in the thousands would).

The goodness-of-fit plots

--plots wrote eight figures to out_fit/plots/: observations against population and individual predictions, residuals against time and against predictions, individual weighted residuals, and the distributions of the random effects.

Observed concentrations against individual predictions, with a LOESS trend and the line of identity
Figure 3.4.1. Goodness of fit: DV against IPRED for the 2,000 observations of run101 (plots/gof_dv_ipred.png).

Figure 3.4.1 is the plot to look at first. Points scatter evenly around the line of identity, and the LOESS trend follows it (with a slight rise above the line at the highest predictions, where there are few points). The individual predictions fit the data well, as they should for an ETA model with ten observations per subject, and this plot alone says little about whether the population model is right. The population predictions, the residuals against covariates and the predictive check of Section 3.5 are the tests of that. Chapter 21 explains the diagnostics and what each can and cannot detect.

What the fit wrote

File Content
run101.ext, .cov, .cor, .coi, .phi the NONMEM-format results, readable by cov, forest, vpc and by NONMEM
run101.ctl the control stream with the final estimates as initial values
parameters.csv one table of all estimates with SE, RSE and the 95 % interval
predictions.csv PRED, IPRED, residuals and weighted residuals for each record
fit_summary.txt, fit_summary.json the listing, as text and as JSON
fit_command.txt every estimation setting written out, so that running the line repeats the fit
report.html, plots/ the HTML report and the eight figures
log_….txt, checksums.sha256 the transcript and the checksum of every file (Chapter 4)

fit_command.txt is worth a look: it contains the single command line that repeats this estimation with every setting explicit (--approximation foce-i --max-iterations 300 --gradient-tolerance 0.001 …). That is the no hidden state principle of Section 1.3 at work.