Documentation

1.1 The problem nlmx solves: the fragmented pharmacometrics toolchain

A population PK/PD analysis is rarely done with one program. The estimation engine is one tool, the checks around it are another, the diagnostics a third, and the planning of the next study a fourth. Each tool is good at its job; the trouble lives between them. This section describes that fragmentation, what it costs, and what nlmx changes about it.

1.1.1 A typical project, tool by tool

A common modelling project has a shape like this. The names are the usual ones in the field; your own project may use different pieces.

Task Typical tool What the tool expects
Estimate the model NONMEM, driven through NM-TRAN control streams a control stream and a dataset in NONMEM's own conventions
Run model-building and evaluation workflows (bootstrap, VPC, stepwise covariate modelling, SSE) PsN, a Perl toolkit that calls NONMEM a Perl installation, a NONMEM installation it can find, and versions that agree with each other
Draw diagnostics and forest plots R with packages such as xpose, vpc and ggplot2 tables written by $TABLE records, in the layout the package reads
Plan sample size and sampling times an optimal-design package such as PopED or PFIM the model written again in the package's own syntax
Non-compartmental analysis a separate NCA program or an R package the dataset again, often reshaped, with its own unit and BLQ conventions
Hold it all together shell, R and Python scripts whatever the author of the script remembered

Nothing in this table is wrong. The cost is in the arrows between the rows.

Left: a project spread over five tools and glue scripts. Right: the same work as one nlmx project folder
Figure 1.1.1. Before and after: a typical multi-tool project and an nlmx project folder.

1.1.2 What breaks between the tools

Every hand-over between two tools is a place where something can differ without anyone deciding that it should.

  • A unit or a filter differs. The NCA used all observations; the model dropped the ones flagged BLQ; the VPC dropped them differently. Three analyses that were meant to describe the same data describe three datasets.
  • A model is written twice. The design package needs the model in its own syntax. After the last change to the control stream, was the package's copy changed too?
  • A version drifts. A Perl toolkit written for one NONMEM release meets another; an R package changes the layout of a table it reads; the plotting script that worked last year needs a different package version this year.
  • A step leaves no trace. A figure in a report came from a script that was run by hand, from a folder that has since been tidied.
  • A result cannot be repeated. The simulation used a random seed that nobody wrote down, or ran on a number of threads that changed the stream of random numbers.

None of these is a failure of the tools. They are a failure of the seams, and they are hard to see because each tool, taken on its own, reports success.

1.1.3 The cost of glue code

The scripts that join the tools are rarely planned. They start as three lines that copy a file and become, over a project, a set of programs that only their author understands. Their cost shows up in three places:

  1. Reproducibility. To repeat an analysis a year later, someone must find the scripts, the right versions of every package and the exact order in which things were run. A regulator or a reviewer asking "how was this figure made?" is asking for that reconstruction.
  2. Version drift. The more tools, the more combinations of versions. A project is rarely frozen in time, but a re-run with a different combination can give a different answer with no error message.
  3. Audit trail. A reviewer needs to see what was run, with which inputs, and to trust that the outputs on the shelf are the outputs of that run. Glue code seldom records any of this.

1.1.4 What nlmx changes, and what it does not

nlmx replaces the seams, not the science. It puts the steps of the workflow behind one program with one version, which reads and writes plain text files in the formats pharmacometricians already use:

  • the dataset and the control stream are NONMEM's own, read directly. The model is whatever the control stream says; there is no second description of it;
  • the results of an estimation are written as NONMEM-format files (.ext, .cov, .cor, .coi, .phi), so that the commands that come after a fit, and NONMEM itself, can read them;
  • every command writes its results to its own, new output folder, together with a transcript of the run, the settings it used and a SHA-256 checksum of every file it wrote (Section 4.2);
  • the same seed gives the same numbers, for any number of threads (Section 4.3).

The right-hand side of Figure 1.1.1 shows the result: a project folder with data, models, small settings files, and one output folder per command. The version of the program that produced a folder is written inside it.

What nlmx does not change is the need for judgement. The program reports, flags and recommends; it does not decide that a model is fit for a purpose. And it does not remove NONMEM from the world: a project that must be submitted with a NONMEM run still needs one. nlmx reads the control streams and result files of such a project (and writes a control stream with the retained covariate effects coded in), but it estimates with its own engine (Section 1.4 lists where the two differ).

1.1.5 Who gains the most

  • The analyst with a deadline, who wants the checks, the first plots and a first fit in an afternoon, with a record of what was done.
  • The pharmacometrician building a covariate model, who wants to test many candidate effects without a NONMEM run for each one (Chapters 22 to 25).
  • The clinical pharmacologist planning a study, who wants an exposure simulation or a sample-size estimate from the model at hand, without recoding it (Chapters 28 to 31).
  • The reviewer or validator, who wants every result tied to inputs, settings and a version (Chapters 4 and 42).
  • The teacher, who wants a complete project that runs in seconds on a laptop (nlmx generate, Chapter 3).