Documentation

8.1 From control stream to executable model

NmModel::build converts the parsed control stream into a reusable model object before any subject likelihood is evaluated. The process is staged:

  1. collect non-dropped $INPUT items and aliases;
  2. parse $PK, $ERROR, $DES or $PRED abbreviated code;
  3. compile names into indexed slots for local variables, data, parameters and special values;
  4. resolve $SUBROUTINES and $MODEL into an ADVAN specification;
  5. bind required parameters, compartment modifiers and scale variables;
  6. derive ODE tolerances and likelihood metadata;
  7. reject incomplete or incompatible model definitions.

Compilation is performed once. Record execution then uses numeric slots rather than repeatedly resolving strings, while the parsed source is retained for analysis and drafting.

$PRED versus compartment models

A $PRED model has no compartment system and executes its prediction code directly. A PREDPP-style model uses $PK, an ADVAN/TRANS or $MODEL system, and $ERROR. A control stream containing both $PRED and $PK is rejected. An ADVAN model without $ERROR is also rejected, and the code must assign Y somewhere.

User-supplied routines named in $SUBROUTINES cannot be executed. nlmx requires the behavior to be expressed in abbreviated $PK, $DES, $ERROR or $PRED code.

Name resolution

Each identifier resolves to one of these sources:

  • a local model variable;
  • a non-dropped data item or synonym from $INPUT;
  • THETA, ETA, EPS, compartment or model-event arrays;
  • a special variable such as NEWIND, ICALL or $DES time T.

Undefined names are refused with the block name and available data items. This prevents a misspelled covariate from silently becoming zero.

Build-time notes

Some conditions are accepted with notes: a synonym may satisfy a TRANS parameter, $DES is ignored for an analytic ADVAN, and absent $ESTIMATION leads the model metadata to assume FOCE with interaction. Notes belong in validation evidence because they expose interpretation choices that do not stop execution.

Common mistakes

  • Treating text parsing and model construction as one opaque step.
  • Assuming a user routine or arbitrary Fortran can be linked dynamically.
  • Ignoring build notes because the model did not fail.

Checklist

  • Identify whether the model is $PRED, analytic, general linear, nonlinear or $DES.
  • Confirm every required block and Y assignment exists.
  • Review all model-build notes before fitting.

Further reading

See source normalisation, unsupported constructs and ADVAN support.