Documentation

3.1 The demo project and what is in it

Every tour needs a place to go. In this chapter it is a synthetic project that nlmx writes for itself: a dataset simulated from a known model, a base control stream, and the results of fitting that control stream. Because the data are synthetic, the truth is known, so you can see whether each analysis finds it; and because nothing about the project is confidential, every output in this book can be reproduced and shared.

3.1.1 Generate it

Start in an empty working folder and run:

nlmx generate --output demo
$ nlmx generate --output demo --no-color
   0.01s ok    configuration accepted: method frozen, 4 covariate(s), 6 relationship(s)
   0.01s ok    control stream parsed: 14 record(s), 13 $INPUT column(s), 5 THETA, 2 ETA, 1 EPS
   0.01s stage simulating the dataset from the truth model (covariate effects included)
   0.03s stage fitting the base model (no covariates) by maximum likelihood
   1.83s ok    fit of run101: OFV = -2880.2130 after 9 iteration(s) (converged), THETA = [3.3446, 43.7421, 1.0973, 0.1760, 0.0235]
   1.83s stage covariance step (observed information at the optimum)
Example project written to demo
Next: nlmx cov --config demo/nlmx.covar --output demo/out
   2.55s ok    example project written — total elapsed 2.55s
[exit 0]

Read the log lines in order, because every command in this book prints the same kinds of line. A stage line says what the program starts doing; an ok line says it succeeded and gives the main number; info lines give context; a warn line (none here) is something to read; an error line ends the run. The left column is the elapsed time. The two lines that matter are the fit: nlmx simulated the dataset, then fitted the base model by maximum likelihood, and reached an objective function value (OFV) of −2880.213 with the five population parameters shown. The last line before the end, Next:, is the program suggesting what to do.

The command accepts options that change the design (--structure, --groups, --doses, --subjects-per-group, --effects, …; Chapter 29). The tour uses the default: the analytic preset, a one-compartment model with first-order absorption.

3.1.2 The folder

demo/
├── README.md                what the project is and which commands to try
├── data/analysis.csv        the dataset
├── models/
│   ├── run101.ctl           the base control stream
│   └── run101.ext .cov .cor .coi .phi    the results of its fit, in NONMEM format
├── nlmx.covar               settings of the covariate analysis
├── nlmx.vpc                 settings of the predictive check
└── run101_files.txt         an explicit list of the files, for --files (Section 4.1)

The run family run101.* is how a NONMEM project names a run: one stem, several files. The control stream is the model; .ext holds the estimates by iteration (the last line is the final estimate and the OFV); .cov, .cor and .coi are the covariance, correlation and inverse-covariance matrices of the estimates; .phi holds each subject's individual estimates and their uncertainty. Chapter 5 describes each file. nlmx reads the family by its stem, so one name (run101) stands for all of them.

3.1.3 The synthetic study

The dataset has 200 subjects and 2,200 records in 13 columns: ID TIME AMT ADDL II EVID MDV DV CMT WT SEX EGFR CRCL.

Item Value
Dosing 100 mg by mouth, one record per subject at time 0, with ADDL = 4 and II = 24: five daily doses
Sampling ten samples per subject, at 0.5, 1, 2, 4, 8, 12 and 23.9 h after the first dose, and at 96.5, 100 and 108 h (around the fifth dose)
Compartments doses go to CMT 1 (the depot), observations are in CMT 2 (the plasma concentration)
Concentrations DV in mg/L, up to 6.5; one value is negative (−0.016), a small residual-error artefact that the checks will find
Covariates WT (kg): median 71.6, range 31.5 to 141.4; SEX: 102 coded 0 and 98 coded 1; EGFR (mL/min/1.73 m²): median 96.2, range 33.8 to 263; CRCL: a near-copy of EGFR (correlation 0.985)
Log-scale concentration against time for the 200 subjects: samples after the first dose and around the fifth dose, none between 24 and 96 hours
Figure 3.1.1. The demo dataset: concentrations of the 200 subjects (log scale), from the eda command (Section 3.3). Samples follow the first and the fifth dose; none lie between 24 and 96 h.

What is true. The data were simulated from a model in which clearance depends on body weight and on renal function, and the volume on body weight. The README in the project says so, which is possible here only because the data are synthetic:

Relationship Truth used to simulate
CL on WT power, exponent 0.75
V on WT power, exponent 1.0
CL on EGFR power, exponent 0.6
CL on CRCL none: CRCL is a proxy of EGFR
CL on SEX, V on SEX none: SEX is a null covariate

A good covariate analysis should retain the relationships in the first three rows, reject SEX, and be uncertain about CRCL, because EGFR explains the same signal. Keep this table in mind: Section 3.5 compares the answer with it.

3.1.4 The base control stream

models/run101.ctl is a complete NM-TRAN control stream with a commented header. Its central part is short enough to read in full:

$PROBLEM run101 base model (one-compartment oral, ADVAN2)
$INPUT ID TIME AMT ADDL II EVID MDV DV CMT WT SEX EGFR CRCL
$DATA ../data/analysis.csv IGNORE=@
$SUBROUTINES ADVAN2 TRANS2                  ; one compartment, first-order absorption
$PK
MU_1 = LOG(THETA(1))                        ; log typical clearance
MU_2 = LOG(THETA(2))                        ; log typical volume
CL = EXP(MU_1 + ETA(1))                     ; individual clearance (L/h)
V  = EXP(MU_2 + ETA(2))                     ; individual volume of distribution (L)
KA = THETA(3)                               ; absorption rate constant (1/h), no IIV
S2 = V                                      ; scale: concentration (mg/L) = amount/volume
$ERROR
IPRED = F                                   ; individual prediction (mg/L)
W = SQRT(THETA(4)**2*IPRED**2 + THETA(5)**2)  ; SD of the residual error
IF (W.LE.0) W = 1E-6                        ; guard against a zero SD
Y = IPRED + W*EPS(1)                        ; observation
$THETA  (0, 3.344584, 50) (0, 43.742092, 500) (0, 1.097278, 20) (0, 0.175994, 1) (0, 0.023534, 1)
$OMEGA 0.186286 0.109111
$SIGMA 1 FIX
$ESTIMATION METHOD=1 INTERACTION MAXEVAL=9999 PRINT=5
$COVARIANCE PRINT=E

It has two random effects (ETA on clearance and on volume), no covariate, a combined proportional-plus-additive residual error scaled by W, and an estimation by first-order conditional estimation with interaction (METHOD=1 INTERACTION). The version here omits comment lines and the three $TABLE records; the file in the companion material is complete.

3.1.5 Inspect before you do anything

The first command to run on any project is inspect. It fits nothing and writes nothing; it reads the model and the data, and prints what nlmx understood:

cd demo
nlmx inspect --config nlmx.covar
   0.00s ok    control stream parsed: 14 record(s), 13 $INPUT column(s), 5 THETA, 2 ETA, 1 EPS
   0.00s ok    model: ADVAN2 TRANS2: one compartment with first-order absorption; 5 THETA, 2 ETA, 1 EPS
   0.00s ok    read 9 final estimate(s) from .ext, OFV = -2880.2130
   0.01s ok    dataset accepted: 2200 rows, 2000 observations, 200 dose records, 200 subjects (0 without observations dropped)
   0.01s info  covariate `WT`: continuous (detected; 198 distinct values, 31.53 to 141.4) — equations: power
   0.01s info  covariate `SEX`: binary (detected; levels 0, 1; reference 0) — equations: proportional
   0.01s info    CL       ETA 1    exponential   THETA [1]  typical value 3.3446
   0.01s info    V        ETA 2    exponential   THETA [2]  typical value 43.7421
   0.01s info    KA       ETA -    none          THETA [3]  typical value 1.0973
   0.01s info  likelihood approximation: foce_i (from $ESTIMATION METHOD=1)
…
Candidate scope (parameter = typical value × equation):
  candidate                    type         status   equation
  CL~WT:power                  continuous   test     CL = TVCL × (WT/71.56)^θ
  CL~SEX:proportional          binary       test     CL = TVCL × (1 + θ if SEX = 1)
  CL~EGFR:power                continuous   test     CL = TVCL × (EGFR/96.15)^θ
  CL~CRCL:power                continuous   test     CL = TVCL × (CRCL/95.5)^θ
  V~WT:power                   continuous   test     V = TVV × (WT/71.56)^θ
  V~SEX:proportional           binary       test     V = TVV × (1 + θ if SEX = 1)

6 candidate(s) from 6 relationship(s). Nothing was fitted (inspect).

Four things to read here.

  1. The model is understood. ADVAN2 TRANS2, five THETAs, two ETAs, one EPS: this agrees with what you wrote.
  2. The estimates were read from the .ext, with the OFV −2880.2130. That is the value to compare with the fit of Section 3.4.
  3. Each ETA was matched to a parameter: ETA 1 to CL and ETA 2 to V, both entering exponentially; KA has no ETA. This map is detected from the code, and Chapter 8 explains how; it is worth checking once for every new model.
  4. The candidate scope is six relationships. Types were detected from the data (WT, EGFR and CRCL continuous, SEX binary), and each has one equation to test. nlmx.covar lists CL against WT, SEX, EGFR and CRCL, and V against WT and SEX.

If a line here disagreed with your understanding, the later results would answer a different question from the one you meant to ask. That is why inspect comes first.

3.1.6 The map for the rest of the tour

Figure 3.0.1 shows the fourteen steps. The colours are the stages of Figure 1.2.1: teal for checking, blue for exploring and building, green for estimating, orange for evaluating, simulating and planning. Each step reads the files of the demo project and writes into a folder of its own; most steps do not depend on the previous step's output, so you can stop and resume the tour at any section. The exceptions, where a step uses an earlier step's result, are named where they occur (the refit of Section 3.5 uses the draft model of cov).