User-defined subroutines
NONMEM supports subroutines and functions called by NONMEM, PREDPP or user code. NONMEM releases contain dummy implementations (that do nothing) of these routines, to be replaced by user-written code in advanced applications.
-
User-defined subroutines in NONMEM
CRIT Modifies the computation of the default objective function. CONTR Specifies the contribution to the objective function of a level 1 ("L1") record. CCONTR Specifies the contribution to the objective function of a level 2 ("L2") record. MIX Describes the mixing parameter of a mixture model. PRIOR Allows a Bayesian penalty to be included in the objective function. SPTWO SPTWO can be used to redefine the RES and WRES items for observation records. THETAI THETAI is used to transform initial THETAs. THETAR THETAR is used to transform final THETAs for reporting. -
User-defined subroutines for PREDPP
INFN Initialization/Finalization routine. - User-defined subroutines for user functions in abbreviated code:
FUNCA,FUNCB,FUNCC, … .
User-defined subroutines/functions should be placed in a file and provided to $SUBROUTINES:
|
|
ICALL
ICALL is an argument passed by NONMEM to user-supplied
subroutines CCONTR, CONTR, CRIT, PRED, PRIOR and MIX. It is also
selectively passed to PK, ERROR, and INFN. It can be used in
$PK, $ERROR, and $PRED abbreviated code. The discussion below
describes the values of ICALL as seen by PRED.
- ICALL=-1: the routine has been called for the PRED_IGNORE_DATA
feature (NM75). One call per data record, at the start of the run.
These calls occur only if abbreviated code uses variables
PRED_IGNORE_DATA or PRED_IGNORE_DATA _TEST, or if the
PRED_IGNORE_DATA option of
$DATAis used. Otherwise, there are no calls to PRED with ICALL=-1. - ICALL=0: the routine has been called for initialization at the beginning of the NONMEM run; one such call per run.
- ICALL=1: the routine has been called for initialization at the beginning of a NONMEM problem; one such call per problem.
- ICALL=2: the routine has been called for a prediction. Multiple calls occur.
- ICALL=3: the routine has been called for finalization at the end of a NONMEM problem; one such call per problem.
- ICALL=4: the routine has been called during the Simulation Step; multiple calls occur, as with ICALL=2.
- ICALL=5: the routine has been called when expectations are being computed; multiple calls occur.
- ICALL=6: the routine has been called when raw data averages are being computed; multiple calls occur.
Note that not every subroutine listed is called all possible ICALL values.
One common pattern of using ICALL is to test it in the abbreviated code:
|
|
See code blocks for extensive use of ICALL.
CONTR
USAGE:
|
|
CONTR is a user-supplied routine for computing the contribution made to the objective function from an L1 record. It is used to override the NONMEM default objective function.
A user-supplied CONTR routine may be used when the dimension of OMEGA is zero, i.e., when there are no ETAs in the problem, and in other situations, e.g., with categorical data.
When NM-TRAN is used, the $CONTR record may be used to request that
information from the data records be made available to CONTR.
Input argument:
- I Similar to ICALL for PRED subroutine. Possible values: 0, 1, 2
Output argument:
- CNT Contribution to -2log likelihood for data from the individual record.
- IER1 0 - Normal return; non-zero - error return.
- IER2 0 - error-recovery is to be implemented when IER1 is nonzero; 1 - NONMEM is to stop when IER1 is nonzero.
Other Inputs: other inputs are available to CONTR in NONMEM read-only global variables. In particular:
- Current THETA (See also CONTR_MIX:THETA)
- DV and data values for this L1 record. (See $CONTR)
- Predictions and derivatives. (See CONTR)
NONMEM Utility routines may be called by CONTR, depending on the type of data:
| POPULATION | SINGLE-SUBJECT | |
|---|---|---|
| CONTINUOUS | ELS, NCONTR | ELS |
| (note: same result) | ||
| CATEGORICAL | NCONTR | none |
If the scatterplot step is implemented, and zero lines are appropriate for values of RES and/or WRES, CONTR should request that NONMEM generate such lines. (NONMEM does this by default when a user supplied CONTR is not supplied.) To request zero lines for RES and WRES, CONTR should set OPSCRS(2) and OPSCRS(3) (respectively) to 1. e.g.,
|
|
CCONTR
|
|
CCONTR is a user-supplied routine for computing the contribution made to the objective function from an L2 record. It is used to override the NONMEM default objective function.
CCONTR may be used when there are no EPS or ETA and in other situations, e.g., with categorical population data.
NONMEM could output error message:
|
|
This can happen when POSTHOC ETAs are requested, but the data are single-subject data. The user may have included the POSTHOC option in error.
The CCONTR routine may contain the following code:
|
|
If the data is correlated across L2 records (e.g., auto-regressive data), CCONTR computes the contribution to the objective function for data from an entire individual record.
Input argument:
- I Similar to Ifor PRED subroutine Possible values: 0, 1, 2
Output argument:
- CNT The conditional contribution to the objective function for this L2 record.
- P1 P1(i) is the partial derivative of CNT with respect to eta(i).
- P2 P2(i,j) is the second partial derivative of CNT with respect to eta(i) and eta(j) (for i <= j). At ICALL=1, CCONTR sets P2(1,1)=-1 if second derivative values are to be used. Otherwise, if cross-gradient values are to be used.
- IER1 0(Normal return); >0(error return).
- IER2 0 if error-recovery is to be implemented when IER1 is nonzero; 1 if NONMEM is to stop when IER1 is nonzero.
- Other inputs Other inputs are available to CCONTR in NONMEM read-only global variables. (See CONTR_MIX:THETA) E.g., USE ROCM_REAL, ONLY: THETA=>THETAC (See CCONTR:_Y,DATA,N1,N2,DIM) (See CCONTR:_F,G,H)
CCONTR is called by NONMEM's NCONTR routine with one level 2 ("L2") record after another. If no CCONTR routine is supplied by the user, NCONTR calls NONMEM utility CELS ("Conditional ELS"; ELS contribution conditional on knowing eta). If no L2 data item is present, each level 2 record is a single observation event record. Otherwise, it is a group of observation records grouped together by a common value of L2.
CRIT
USAGE:
|
|
The CRIT subroutine is used to modify the NONMEM objective function used with the First-Order (or the Extended Least Squares) Estimation method. This objective function may be regarded as being the sum of contributions computed from each individual record. The first term in the contribution from an individual record is independent of data, but the second term in the contribution is the sum of the squared weighted residuals for the data in the record. The weights are functions of the model parameters and are obtained so that with a given set of parameter values, assumed to be the true parameter values, each weighted residual has unit variance and all the weighted residuals are mutually uncorrelated. With the CRIT routine, a function of the weighted residuals other than the sum of their squares may be substituted for the second term. The function may vary between individual records. The CRIT routine is called by NONMEM with one individual record after another (individual records without observations are skipped).
Input argument:
-
ICALL Similar to ICALL for PRED subroutine.
- 0 - First call to CRIT in the run
- 1 - First call to CRIT in the current problem
- 2 - Computation of function value required
- J Number of individual record
- N Number of observations in the individual record
- WRES Vector of weighted residuals (as many residuals as there are observations)
Output argument:
- V Value of function
Note: When a user CRIT is supplied, NONMEM subroutine CELS may not be called.
AES
For use with PREDPP's ADVAN9 and ADVAN15 and ADVAN17.
|
|
In general, a system of differential-algebraic equations has the form $$ \frac{dA(t)}{dt}=g(A(t), p, t),\quad 0=h(A(t), p, t) $$ For both equations the left-hand-side (LHS) and right-hand-size (RHS) are vectors in general, \(A=[A_1, \dots, A_{n_1}]^T\), \(g=[g_1, \dots, g_{n_1}]^T\), \(h=[h_1, \dots, h_{n_2}]^T\). A denotes the drug amount in all compartments except the output compartment, \(p\) the internal PK parameters, and \(t\) the time. This is used to describe a system with \(n_1\) compartments in nonequilibrium and \(n_2\) compartments in equilibrium.
For example, $$ p=[K_e, K_a, R]^T,\quad g_1=-K_aA_1, \quad g_2=K_aA_1-K_2A_2, \quad h_1=A_3-RA_2 $$ describes the one compartment model with linear elimination and absorption from a drug depot (ADVAN2), coupled with a third compartment in equilibrium with the central central compartment. Constant R is the ratio of the drug amount.
The AES subroutine is called by PREDPP to evaluate algebraic expressions for ADVAN9, ADVAN15, and ADVAN17. It evaluates \(h()\) functions and store the results in vector E. The evaluation \(g()\) is delegated to the DES routine.
Input argument:
- P(n) The value of the nth PK parameter.
- T: Time. T takes values continuously over an integration interval.
Input/output arguments:
- INIT When AES is called with INIT=1, this is an initial condition call at the start of an integration interval. Approximate amounts in each equilibrium compartment n at time T must be stored in A(n). (The amounts in the non-equilibrium compartments are already stored in the lower-numbered elements of A.) DA, DP, DT need not be computed. If AES stores approximate values in A, it must set INIT=0; if AES stores exact values in A, it must leave INIT unchanged. When AES is called with INIT=2, the values of the algebraic expressions must be stored in E and the derivatives in DA, DP, and DT.
- A(n) The amount in the nth compartment at time T.
Output argument:
- E(k) The value of the algebraic expression g(k).
- DA(k,j) The derivative of g(k) with respect to A(j).
- DP(k,j) The derivative of g(k) with respect to P(j).
- DT(k) The derivative of g(k) with respect to T.
Also see variables in NONMEM modules, NONMEM-PRED modules, particularly DES AES: ICALL,IDEFD,IDEFA.
REFERENCES: Guide IV, section V.C.8 , V.C.9
DES
For use with ADVAN 6,8,9,13,14,15,16,17,18, called by PREDPP to evaluate right-sides of differential equations.
|
|
In general, a system of differential equations has the form
$$ \frac{dA(t)}{dt}=g(A(t), p, t). $$
Here both left-hand-side (LHS) and right-hand-size (RHS) are vectors of dimention n: \(A=[A_1, \dots, A_n]^T\), \(g=[g_1, \dots, g_n]^T\). A denotes the drug amount in all compartments except the output compartment, \(p\) the internal PK parameters, and \(t\) the time. For example, for the one compartment model with linear elimination and absorption from a drug depot (ADVAN2) we have $$ n=2,\quad p=[K_e, K_a]^T,\quad g_1=-K_aA_1,\quad g_2=K_aA_1-K_eA_2 $$
The above arguments are the input arguments for the DES routine. The routine's output argument DADT stores the evaluation of \(g()\).
Input argument:
- A(n): the amount in the nth compartment at time T.
- P(n): the value of the nth PK parameter.
- T: time. T takes values continuously over an integration interval.
Output argument:
-
DADT(n) The derivative with respect to T of the nth compartment's amount. It is important to note that PREDPP itself adds in the rates for any infusions that may be active.
For example, the above equations for ADVAN2 can be coded as:
1 2DADT(1)=-P(2)*A(1) DADT(2)= P(2)*A(1)-P(1)*A(2) -
DA(i,j) The derivative of \(g_i()\) with respect to A(j). Continuing the above example,
1 2 3DA(1,1)=-P(2) DA(2,1)= P(2) DA(2,2)=-P(1) -
DP(i,j) The derivative of \(g_i()\) with respect to P(j). Continuing the above example,
1 2 3DP(1,2)=-A(1) DP(2,2)= A(1) DP(2,1)=-A(2) - DT(n) The derivative of \(g_i()\) with respect to T.
The full implementation of the above example model is
|
|
See variables for module variables involved in the code.
The format of arrays DA, DP, DT described above is called "full format". It is the default format. Alternately, compact format may be used. See Guide VI, Appendix IV. Compact Arrays in DES.
Also see variables in NONMEM modules, NONMEM-PRED modules, and PREDPP modules, particularly DES AES: ICALL,IDEFD,IDEFA.
ERROR
|
|
The ERROR subroutine is called by PREDPP to model intra-individual error in observed values. It can also be used to to convert predictions from PREDPP, i.e., scaled drug amounts, to other types of predictions (for example, to obtain the prediction of a drug effect as a function of concentration, in a pharmacodynamic study).
Input argument:
-
ICALL: see ICALL above for general discussions.
- ICALL=1: ERROR is being called for initialization at the beginning of a NONMEM problem; one such call per problem. EVTREC contains the first event record. THETA contains the initial estimates. ERROR must return values in IDEF which inform PREDPP what tasks it will perform at later calls. It may also set elments of HH to the appropriate derivatives, when it has requested that ERROR be called only once per problem.
- ICALL=2: ERROR has been called to obtain the modeled value;
multiple calls occur. ERROR should compute derivatives of prediction F to
be stored in
HH. If ERROR changes F, it should also change the derivates of F in G. - ICALL=4: ERROR has been called during the Simulation Step; multiple calls occur. ERROR should compute simulated observations and store them in F.
- ICALL=5: ERROR has been called during the computation of expectations; multiple calls occur. Such calls occur when the marginal (MRG_) data item is defined in the data set and has non-zero values for some records. If the MRG_ data item has the value 1 or 2, expectations are computed for that record, and the value returned by ERROR in F contributes to the expectation that is being computed for the PRED data item. The value of an ERRORdefined item contributes to the expectation computed for the item.
- ICALL=6: ERROR has been called during the computation of raw data averages; multiple calls occur. Such calls occur when the rawdata (RAW_) data item is defined in the data set and has the value 1 for some records (See template). ERROR may re-compute DV when the value of DV in the data record is not the quantity to be included in the average. ERROR may return a value of 1 in F if no DV item is to be included in the average with the particular record.
- THETA The NONMEM THETA vector.
- EVTREC The PREDPP event record.
- INDXS
The values specified in the
$INDEXrecord of the NM-TRAN control stream. (This is the NONMEM INDXS array starting at position 12, the first position beyond those positions used by PREDPP itself.)
Output argument:
-
IDEF ERROR should store values in IDEF only when ICALL=1. A value of 1 in IDEF(1) indicates that ERROR will store the derivatives of log y in HH (which causes PREDPP to multiply each element of HH by F). That is, PREDPP understands that the "error in log y" is modeled.
The value in IDEF(2) describes when ERROR should be called:
- -1 call with every event record.
- 0 call once per observation record.
- 1 call once per individual record.
- 2 call once per problem.
The value in IDEF(3) describes whether ERROR uses derivatives of compartment amounts (i.e. whether compartment amounts themselves are used as random variables in arithmetic statements in ERROR).
- -1 ERROR may use derivatives of A.
- 0 ERROR does not use derivatives A.
- 1 ERROR does use derivatives of A.
The default used by PREDPP is IDEF(3)=-1. However, when ERROR does not use A, then if IDEF(3) is set to 0, PREDPP can avoid some time-consuming processing. Indeed, when
$ERRORabbreviated code is supplied, and there is no reference to a compartment amount A(n) (as a random variable in an arithmetic statement) in the abbreviated code (or to its derivatives in verbatim code), then NM-TRAN sets IDEF(3)=0.
Input/Output argument:
- F: On input, the prediction based on the pharmacokinetic model, i.e., the value of the scaled drug amount in the observation compartment. On output, F may be unchanged, or it may be modified, e.g., when a PD prediction is needed. If ERROR modifies F and uses population eta variables to do so, then at ICALL=2 ERROR must call GETETA to obtain eta values prior to modifying F. When ICALL=4, ERROR should calculate the simulated observation (after calling SIMETA and/or SIMEPS to obtain simulated ETA and EPS, as necessary) and place its value in F. With the Simulation Step, ERROR may return the simulated observation as the DV data item, rather than in the argument F. With discrete data the simulated observation must be returned as the DV data item. (See $ESTIMATION).
- G: On input, at ICALL=2 when the data are population, an array of partial derivatives of F with respect to ETAs G (i,1) is the partial derivative of F with respect to eta(i). G (i,j+1) is the second derivative of F with respect to eta(i), eta(j) (lower-triangular; j=1, …, i). (Second derivatives are only needed with estimation by the Laplacian method.) On input, G contains zeros when the data are single-subject data. At ICALL=2, ERROR must modify G when it has changed F and has thus changed the derivatives of F with respect to the population ETAs.
- HH: An array of partial derivatives of F with respect to ETAs (when the data are single-subject data) or EPSILONs (when the data are population). Values should be stored when ICALL=2 and also when ICALL=1 if ERROR sets IDEF(2)=2. HH(i,1) is the derivative of F with respect to eta(i) or eps(i). HH(i,j+1) is the derivative of H(i,1) with respect to eta(j) (but are only needed with conditional estimation when the dependence on ETAs of the variance of intra-individual random error should be preserved in the computation of the objective function; see the INTERACTION option of $ESTIMATION).
Also see modules for NONMEM read-only modules (of the form ROCMn), NONMEM-PRED modules (of the form NMPRDn), and PREDPP read-only modules (of the form PROCMn).
Calling protocol
As the pharmacokinetic system is advanced, ERROR is called one or more times, each time with some argument record. The event records comprise these argument records, and are passed to ERROR in time order. The simulation and/or data analytic computations will normally be done correctly if routine ERROR is called with one event record after another (within an individual record), no event records being skipped, and no event record being repeated. This is the default. However, PREDPP can implement a few different protocols for calling ERROR. A protocol is specified by setting IDEF(2) to various values at ICALL=1 (for more about IDEF, see section B.1). The default is IDEF(2)=-1 (call with every event record), described above. The ERROR routine can be called only with each observation event record of the individual record. If this more limited sequence of calls is desired, this can be accomplished by setting IDEF(2)=0. Note, though, that in this case, IDEF(2) must be explicitly set to 0.
There are two general considerations to be remembered about calling-protocols with ERROR. First, no matter what calling-protocol is used, it applies only to calls to ERROR at ICALL=2; at ICALL=4 (i.e. during simulation) ERROR is always called with every event record. [This differs from calling-protocols with PK, where whatever calling-protocol is used for PK at ICALL=2 is the same as that used at ICALL=4.] Second, a calling-protocol that limits the sequence of calls to ERROR should not be requested when the value of F returned by ERROR may differ from the value input to ERROR.
Often, none of the EPS derivatives depend on concomitant variables whose values vary within an individual record i.e. vary over time. This is true if y is given by (1) or (6), for example, or if log y is given by (5). This may not be true if y is given by (2); it depends on whether the value of Z varies over time. Unless there is only one observation per individual, this generally is not true if y is given by (3) or (4), since when time varies, f(P) varies, and time itself is to be regarded as a concomitant variable. When though this is true, then the values stored in the HH array must be the same for each observation event record of a given individual record (for THETA and ETA fixed). Considerable computation time can be saved; PREDPP need call ERROR only once per individual record, with the first event record only (for any given values of the THETA and ETA arrays). The user can request this calling-protocol by setting IDEF(2)=1. Since the first event record need not be an observation record, care must be taken that HH is indeed set with this record, and that any data items needed for this purpose are contained in that record.
Notice that with y given by (1), for example, the EPS-derivatives do not depend on any concomitant variables, nor do they depend on ETA or THETA. In such a case the values stored in the HH array must be the same for each observation event record of the entire data set; indeed, these values could be computed only once during the entire NONMEM problem. If at ICALL=1, IDEF(2) is set to 2, then at ICALL=2 values for HH will always be taken to be (constant) values stored in HH at ICALL=1. Note that the HH array is initialized to zero immediately before the call to ERROR with ICALL=1.
If log y is given by (5), the derivatives of log y with respect to the EPS are particularly simple; they satisfy the requirement for using IDEF(2)=2. By setting IDEF(1)=1, the user is specifying that when ICALL=2, the derivatives of log y are to be found in HH (see section B.1). By also setting IDEF(2)=2, these derivatives are actually taken to be the values stored in HH at ICALL=1.
Even when IDEF(2)=0, 1, or 2, a call to ERROR with any given event record can be forced with the use of the CALL data item.
IDEF(2) may be set to -1, or not set at all, i.e. this is the default. This results in ERROR being called with every event record (see above).
NM-TRAN abbreviated code provides a reserved variable CALLFL and corresponding pseudo-statements to specify the value for IDEF.
INFN
|
|
A run consists of one or more problems, and each problem consists of one or more subproblems. With NONMEM 75, there is an opportunity to drop data records from the NONMEM data set at the start of the run, using the PRED_IGNORE_DATA feature. There are opportunities to make some rudimentary computations at the beginning of a run (run initialization), at the beginning of a problem (problem initialization), at the end of a subproblem (subproblem finalization), at the end of a problem (problem finalization), and at the end of a run (run finalization). For example, at problem initialization, data transgeneration may take place, or a variable that will be modified at subproblem finalization, may be initialized. At problem finalization, the value of this variable may be written to a user file. There is no opportunity to do subproblem initialization.
The INFN subroutine is called by PREDPP to make initialization and finalization computations. The dummy distributed with PREDPP may be replaced by a user-written code.
Input/Output argument:
-
ICALL
-
ICALL=-1: INFN may set PRED_IGNORE_DATA=1 for records to be dropped. The following is required:
1USE NMPRD_INT, ONLY: PRED_IGNORE_DATA,PRED_IGNORE_DATA_TESTThe option
$DATAPRED_IGNORE_DATA option is required to cause NONMEM to make a PRED_IGNORE_DATA pass. - ICALL=0: INFN may now make computations for run initialization. ICALL may be reset by INFN to a number in the range 1-8999. This number will appear on NONMEM output, allowing the user to identify the INFN routine being used.
- ICALL=1: INFN may now make computations for problem initialization.
- ICALL=3: INFN may now make computations for problem finalization. If there are subproblems, first do subproblem finalization, if required. Then test for IREP=NREP (the number of the current subproblem equals the total number of subproblems), and if true, do problem finalization. Values of IREP and NREP may be found in NONMEM modules (See Simulation: NREP,IREP).
-
INPUT ARGUMENTS:
- DATREC DATREC contains the first data record of the current problem. (at icall=0, the current problem is the first problem.) using pass (see below), the contents of datrec are replaced by other data records for the current problem, allowing all these other records to be read and even modified.
- THETA The NONMEM THETA vector. At ICALL=0, THETA contains the initial estimates for the first problem. At ICALL=1, THETA contains the initial estimates for the current problem. At ICALL=3, THETA contains the final estimates for the current problem.
- INDXS
The values specified in the
$INDEXrecord of the NM-TRAN control stream. (This is the NONMEM INDXS array starting at position 12, the first position beyond those positions used by PREDPP itself.) - NWIND NWIND has value 0 when INFN is called. It changes value during a pass through the data using PASS (see below). NWIND=0: First record of the data set. NWIND=1: First record of a subsequent individual record. NWIND=2: Subsequent data record of an individual record.
EXAMPLES OF USAGE:
- Initialization: constants in the PK routine can be set if they are stored in a module or common block declared both in INFN and PK.
- Transgeneration: the data can be accessed and even modified via use of the NONMEM utility routine PASS in routine INFN. As the data records are passed one-by-one to INFN, each record is stored in turn in DATREC. Data can be transgenerated and additional data items can be produced at both initialization and finalization. Data items that appear in a table or scatterplot with a given subproblem or problem are produced or left unchanged at the subproblem or problem finalization. At finalization estimates of the eta's can be obtained via the NONMEM utility routine GETETA. When used in conjunction with PASS, the values returned for the eta's with each call to GETETA are appropriate for the individual whose data record is currently in DATREC.
- Interpolation: as an example of transgeneration, interpolated values of a covariate can be computed for event records in which values are missing, e.g. for other-type event records that have been included so that predictions can be obtained at the times in these records. This could also be done in PK or ERROR, but then this would be done with every call to these routines; if done in INFN, the computation is done once only. (See Infn interpolation example).
MIX
USAGE:
|
|
MIX is a NONMEM routine that is replaced by a user-supplied routine when a mixture model is used. The MIX subroutine is used to describe the mixture parameters of a mixture model. It is called by NONMEM with one individual record after another.
Input argument:
- ICALL Similar to ICALL for PRED subroutine.
Output argument:
- NSPOP: an integer variable or integer constant. The maximum number of sub-populations that are possible. Must be given a value when ICALL=1.
- P: an array. For each i (i=1, … , NSPOP), P(i) gives the modeled fraction of the population in the ith subpopulation. The sum of the P(i) should equal 1. In principle, the P(i) can change from individual to individual. If for a given individual, the second (for example) subpopulation doesn't apply, then set P(2)=0 for that individual.
Other inputs are available to MIX in NONMEM read-only global
variables. In particular, data items that are requested using the
$CONTR record, and the current value of THETA, as shown above. (See
MIX:DATA, CONTR_MIX:THETA).
The MIX CONTR: TEMPLT data record in a NONMEM read-only global variable also serves to provide an additional way for individual-specific information to be made available.
See also MIXNUM, MIXEST and MIXP.
See mixture model example for using $MIX and MIX.
MODEL
|
|
The MODEL subroutine is called by PREDPP only once at the start of a run when a general ADVAN (ADVAN 5, 6, 7, 8, 9, 13, 14, 15, 16, 17, 18) is used. It allows the user to specify aspects of the particular model he wishes to use. When NM-TRAN is used, the $MODEL record supplies this information.
Input argument: None.
Output argument:
- IDNO: An identification number for the MODEL routine. The value assigned by MODEL to IDNO is printed on the first PREDPP problem summary page. The user may have several MODEL routines and use different ones for different runs. The routine used in a particular run can be identified from the output. For this to happen, an integer identification value should be assigned by MODEL to the variable IDNO. This value will be printed on the first PREDPP problem summary page. When NM-TRAN abbreviated code is used, IDNO is set to 9999.
- NCM: the total number of compartments in the model, excluding the output compartment. Contains 0 when MODEL is called. NCM must be no greater than PC-1.
- NPAR: basic PK parameters exist for general linear and nonlinear
models as they do for more specific models. A TRANS routine is
used which translates the set of basic PK parameters whose values
are computed in the PK routine to a set of parameters used
internally by the ADVAN routine. The maximum number of basic PK
parameters to be used in any TRANS routine is specified by
assigning this number to the variable NPAR. NPAR may be 0, e.g.,
when only THETA and data record items are used in differential
equations. The maximum number of basic PK parameters plus the
number of additional parameters whose row indices are given
explicitly in PK (at ICALL=1) cannot exceed PG, a constant in
SIZES.f90 which is given by PARAMETER (PG=50+PCT), where PCT is
the maximum number of model event time parameters given by
PARAMETER (PCT=30) Both these parameters can be changed with the
$SIZESrecord. With the general non-linear models (ADVAN6, ADVAN8, ADVAN9, ADVAN13, ADVAN14, ADVAN15, ADVAN16, ADVAN17, ADVAN18), NPAR may remain 0. -
IATT: Values of compartment attributes. The values of IATT(I,*) refers to the ith compartment.
- IATT(I,1)=0 initially off
- IATT(I,1)=1 initially on
- IATT(I,2)=0 may not be turned on and off
- IATT(I,2)=1 may be turned on and off
- IATT(I,3)=0 may not receive doses
- IATT(I,3)=1 may receive doses
- IATT(I,4)=0 not the default observation compartment
- IATT(I,4)=1 the default observation compartment
- IATT(I,5)=0 not the default dose compartment
- IATT(I,5)=1 the default dose compartment
Most pharmacokinetic models involve only nonequilibrium compartments, compartments such that the amounts of drug in them can be given by a solution to a system of differential equations. However, some ADVAN routines - ADVAN9, ADVAN15, ADVAN17 - allow a model (a general nonlinear model) to be comprised of both nonequilibrium and equilibrium compartments. Equilibrium compartments are, roughly speaking, compartments such that at any time the amounts of drug in them can be given by a solution to a system of algebraic equations. These ADVAN routines allow the user to define a model consisting only of equilibrium compartments, in which case the ADVAN becomes a purely algebraic equation solver. The quantities A(i) may be thought of as unknowns to be determined rather than as "compartment" amounts. Records with EVID=1 and EVID=4 (dose, reset and dose) may not be present in the data set because doses cannot be placed in equilibrium compartments. Similarly, data items related to doses (RATE, AMT, SS, II, ADDL) may or may not be used in the data set. If used, they must contain null values. The TIME data item is optional. If TIME is used, ADVAN is called exactly as other ADVAN routines are called: when the value of TIME increases. If TIME is not defined, AES routine specifies the calling protocol for ADVAN: call with every event record (the default) or once per individual record (see section E.C). If calls to ADVAN are limited, the CALL data item may be defined in the data set and given the value 10 to force additional calls to ADVAN (see chapter V, section J). There are two additional attributes to which values must be given only when these ADVAN routins are used. The first of these simply identifies the compartment as an equilibrium compartment or not. The second of these relates to the output compartment. The amount of drug in the output compartment at time t is given by A+B-C, where A is the total amount in the system at s, the time the compartment is turned on, B is the total amount of drug input to the system between times s and t, and C is the total amount in the system at time t. If an equilibrium compartment represents a subcompartment, i.e. the amount D of drug in the compartment is part of the amount of drug in another compartment, D should be excluded from A and C. The attribute in question is concerned with whether D should or should not be excluded from A and C. The settings below is used only with ADVAN9, ADVAN15, and ADVAN17:
- IATT(I,8)=0 not an equilibrium compartment
- IATT(I,8)=1 an equilibrium compartment
- IATT(I,9)=0 should not be included in the total drug amount in the system interior
- IATT(I,9)=1 should be included in the total drug amount in the system interior
- NAME: labels for the compartments (to be printed on the PREDPP summary page under "FUNCTION"). NAME(I) is the label for compartment i. With versions before NONMEM 7.4, NAME was limited to 8 characters. With NONMEM 74 NAME may be up to SD characters long. SD is defined in SIZES and is set to 30 with NONMEM 7.4.
-
LINK: Only used with general linear models (ADVAN5 and ADVAN7). The internal parameters of these models are the rate constants. The user assigns each rate constant a number, any number between 1 and the value assigned to NPAR. The numbering is estab- lished using the LINK array. LINK is a two-dimensional integer array. If no drug can distribute from the Ith compartment to the Jth compartment, then one can assign 0 to LINK(I,J), or not bother assigning any value to LINK(I,J). In particular, LINK(I,I) should always be ignored. If drug can distribute from the Ith compartment to the Jth compartment, then one assigns to LINK(I,J) the number of the rate constant quantifying this (first- order) distribution. The LINK array should, in particular, account for the distribution of drug from com- partment I to the output compartment. That is, if such distribution can take place, then a number should be assigned to LINK(I,NCM+1). The numbers of the rate constants need not start with the number 1, and they need not be consecutive, i.e. numbers may be skipped. Moreover, two rate constants can be assigned the same number; this forces their values and η-derivatives to be the same. With NM-TRAN, there are two ways to specify LINK. When the
$PKabbreviated code is used, link relationships are implied by variable names such as Kij or KiTj (where "T" stands for "TO"). When a user-supplied PK is used, the LINK relationships must be specified explicitly on the$MODELrecord using options such as Kij.With a general nonlinear model the user explicitly specifies by DES. These equations are parameterized in terms a set of internal kinetic parameters. The LINK array plays no role with a general nonlinear model. The internal parameters are numbered between 1 and the number assigned to NPAR. The rules concerning internal parameter numbering are the same as given above for rate constant numbering.
- LINK(I, J)=0: no drug may distribute from compartment i to compartment j.
- LINK(I, J)=K: drug distributes from compartment i to compartment j. The rate constant quantifying this first order distribution is computed by PK and stored in the kth row of GG. When MODEL is called, all elements of LINK are 0.
Example below uses MODEL routine to specify the one compartment linear model with first order absorption, just as with ADVAN2.
|
|
For another example, we implement the MODEL routine for the following
$MODEL block
|
|
|
|
(See SIZES).
An initial steady state may be requested by routine MODEL; (See Initial Steady State: I_SS,ISSMOD).
PK
USAGE: before NONMEM 7.2:
|
|
With NONMEM 7.2 and higer:
|
|
The PK subroutine is called by PREDPP to obtain values for basic and additional pharmacokinetic parameters. Basic PK parameters are typically the rate constants ("micro-constants") for use in kinetic formula. PK can compute instead parameters such as clearance and volume, and a translator ("TRANS") subroutine can be used to convert these to rate constants. Additional PK parameters include compartment scale parameters, which PREDPP uses to convert compartment amounts to concentrations, and dose-related parameters such as modeled infusion rates.
Input argument:
-
ICALL: see ICALL above for general discussions.
- ICALL=1: PK routine is being called for the first time in the NONMEM problem. At such a time PK must store certain information in array IDEF, and optionally certain information in GG.
- ICALL=2: PK routine is being called for regular data analysis and that values of PK parameters are to be stored in the first column of GG. These can be typical (population mean) values , or they can be subject-specific values. In addition, partial derivatives are also stored. see sections D and E.
- ICALL=4: PK routine is being called for regular data simulation. If the data are population data, simulated subject-specific PK parameters values are to be stored in the first column of GG; see section E.2. However, if the data are all from a single subject, so that the subject’s specific values are synonomous with the typical values, then typical values are stored in this column.
- ICALL=5: PK routine is being called for regular expectations computation. Multiple calls can occur. See Expectation blocks. In this case no ETA derivatives are needed.
If there is abbreviated code in the $PK block conditional on ICALL=0, ICALL=1, or ICALL=3, the
code is transcribed to the INFN routine as part of an $INFN
block.
- THETA: the NONMEM THETA vector.
- EVTREC: the PREDPP event record. See EVTREC.
- INDXS: the values specified in the
$INDEXrecord of the NM-TRAN control stream. (This is the NONMEM Index array starting at position 12, the first position beyond those positions used by PREDPP itself). - NETAS: the number of population ETAs in the problem.
Output argument:
-
IDEF: stores values only when ICALL=1. Values may be stored in the following elements:
- IDEF(1,1)=-9 (required)
-
IDEF(1,2) is the call limiting element (compare
$PK's CALLFL). Values are:- -2: call with every event record and at additional and lagged dose times.
- -1: call with every event record (default)
- 0: call with first event record and new TIME values
- 1: call once per individual record
Compartment initialization may be performed by routine PK.
An initial steady state may be requested by routine PK;
-
IDEF(1,3) describes whether PK performs compartment initialization, i.e., whether or not PK initializes elements of the initial state vector A_0(n). Values are:
- -1: PK may initialize A_0.
- 0: PK does not initialize A_0.
- 1: PK does initialize A_0.
The default used by PREDPP is IDEF(1,3)=-1. However, when compartment initialization is not implemented, then if IDEF(1,3) is set to 0, PREDPP can avoid some time-consuming processing. Indeed, when
$PKabbreviated or verbatim code is supplied, and there is no reference to compartment initialization amounts A_0(n) in either the abbreviated or verbatim code, then NM-TRAN sets IDEF(1,3)=0.Compartment amounts may be used by routine PK (See State Vector A).
-
IDEF(1,4) describes whether PK uses derivatives of compartment amounts (e.g. compartment amounts themselves are used as random variables in arithmetic statements in PK). Values are:
- -1: PK may use derivatives of compartment amounts.
- 0: PK does not use derivatives of compartment amounts.
- 1: PK uses derivatives of compartment amounts.
The default used by PREDPP is IDEF(1,4)=-1. However, when derivatives of compartment amounts are not used, then if IDEF(1,4) is set to 0, PREDPP can avoid some time-consuming processing. Indeed, when
$PKabbreviated or verbatim code is supplied, and there is no reference to A(n) (as a random variable in an arithmetic statement) in the abbreviated code (or to derivatives of A(n) in the verbatim code), then NM-TRAN sets IDEF(1,4)=0. -
Remaining elements contain row numbers in GG:
- IDEF(2,1): row number of F0 (output fraction)
- IDEF(2,2): row number of XSCALE (Time Scale)
- IDEF(2,3): row number of lowest-numbered MTIME
- IDEF(2,4): row number of highest-numbered MTIME
- IDEF(3,n): row number of Sn (Scale for comp. n) (thru n+1 output)
- IDEF(4,n): row number of Fn (bioavailability fraction for comp. n)
- IDEF(5,n): row number of Rn (modeled rate for comp. n)
- IDEF(6,n): row number of Dn (modeled duration for comp. n)
- IDEF(7,n): row number of ALAGn (absorption lag for comp. n)
-
GG: the array of PK parameters and their eta derivatives, initialized to zero immediately before PK calls. The maximum number of rows in GG is given by IRGG, which is the same as constant PG found in file SIZES (See SIZES).
-
At ICALL = 2:
- GG(k,1,1) contains the value of the k'th parameter;
- GG(k,i+1,1) contains its derivative with respect to the ETA(i);
- GG(k,i+1,j+1) contains its second derivative with respect to
ETA(i) and ETA(j) (lower-triangular; j=1, …, i). Recall that
second derivatives are only needed with METHOD=LAPLACE,
therefore GG may be declared as a two-dimensional array
GG(IRGG,*)when the Laplacian method is not used.
- At ICALL = 4: GG(k,1,1) contains the individual-specific value of the k'th parameter. Since ICALL=4 indicates simulation, other columns of GG for partial derivatives need not be computed.
- At ICALL = 1: GG(k,1,1)=[0|1] specifies transformation of the values that will be stored at GG(k,1,1) during calls with ICALL=2 or 4. GG(k,1,1)=0 means no transformation, while GG(k,1,1)=1 indicates GG(k,1,1) will store a log-transformed parameter value.
-
Also see variables in NONMEM modules, NONMEM-PRED modules, and PREDPP modules.
Calling protocol
As the pharmacokinetic system is advanced, PK is called one or more times, each time with some argument record. The event records comprise these argument records, and are passed to PK in time order. The simulation and/or data analytic computations will normally be done correctly if routine PK is called with one event record after another (within an individual record), no event records being skipped, and no event record being repeated. This is the default. However, PREDPP can implement a few different protocols for calling PK. A protocol is specified by setting IDEF(1,2) to one of various values at ICALL=1 (for more about IDEF, see section G). For example, the PK routine can be called only with the first event record of the individual record and with every event record thereafter where the time data item differs from the time data item of the previous event record. If this more limited sequence of calls is desired, this can be accomplished by setting IDEF(1,2)=0. Note, though, that in this case, IDEF(1,2) must be explicitly set to 0 because 0 is not the default.
Often, none of the basic or additional PK parameters depend on concomitant variables whose values vary within an individual record, i.e. vary over time. In this situation the information output by PK, i.e. the GG array, is the same for each event record of an individual record (for fixed THETA and ETA). Considerable computation time can be saved; PREDPP need call PK only once per individual record, with the first event record only (for any given values of the THETA and ETA arrays). The values of continuously acting PK parameters computed with this call can be assumed to hold over all state-time intervals for the individual record, and the values of discretely acting PK parameters can be assumed to hold at each state time for the record. The user can request this calling-protocol by setting IDEF(1,2)=1.
When the data are from a single subject, PREDPP treats all event records in the entire data set as though they are associated with the same subject. (This is a consequence of the single-subject assumption; see section IV.A.) In particular, suppose that every call to PK with a different event record results in the same output from PK (for fixed THETA). Then only one call is necessary, a call with the first event record in the entire data set. The values of continuously acting PK parameters computed at this call can be assumed to hold over all state-time intervals for the entire data set, and the values of discretely acting PK parameters can be assumed to hold at all state times for the entire data set. Setting IDEF(1,2) to 1 has this effect.
Even when IDEF(1,2)=0 or 1, a call to PK with any given event record can be forced with the use of the CALL data item.
The protocol where PK is called once with every event record can be specified by setting IDEF(1,2) to -1, or by not setting IDEF(1,2) at all, i.e. this protocol is the default. If it is desired that, in addition, the values of PK parameters at any nonevent dose time t be computed with access to both the argument record associated with t and the event record describing the dose (see section B.2), set IDEF(1,2)=-2. This has the effect that PK may be called repeatedly with the same event record (for if t is a nonevent dose time, and s is the subsequent event time, PK is called with the event record for s at both times t and s). The primary use of this protocol is so that the values of certain discretely acting PK parameters, the bioavailability fractions and duration parameters, can always be computed with access to useful dose-related concomitant information contained in the dose record, such as the type of preparation, even when the dose is an additional or lagged dose. Another use of this protocol is to cause PREDPP to call PK at the time specified by a model event time parameter; this protocol is required with such parameters.
NM-TRAN abbreviated code provides a reserved variable CALLFL and corresponding pseudo-statements to specify the value for IDEF.
PRED
|
|
The PRED subroutine is called by NONMEM to obtain modeled values. PREDPP is a special PRED subroutine that is distributed with NONMEM, for common Population PK models.
Input argument:
-
ICALL
- ICALL=-1: the routine has been called for the PRED_IGNORE_DATA feature (NM75). One call per data record, at the start
of the run. These calls occur only if abbreviated code uses
variables PRED_IGNORE_DATA or PRED_IGNORE_DATA _TEST, or if the
PRED_IGNORE_DATA option of
$DATAis used. Otherwise, there are no calls to PRED with ICALL=-1. - ICALL=0: PRED has been called for initialization purposes at the beginning of the NONMEM run; one such call per run. DATREC contains the first data record. THETA contains the initial estimates. PRED need not compute F, G, or H.
- ICALL=1: PRED has been called for initialization purposes at the beginning of a NONMEM problem; one such call per problem. Otherwise, identical to ICALL=0.
- ICALL=2: For the data record contained in DATREC, PRED has been called for the purpose of computing F, the value of the prediction, and/or the values of other PRED-defined items, appropriate for the record. PRED should compute F, and also G and H as appropriate. THETA contains the values to be used to compute F. With conditional estimation, to obtain ETA values, PRED should call GETETA.
- ICALL=3: PRED has been called for finalization purposes at the end of a NONMEM problem; one such call per (sub)problem. DATEC contains the first data record. THETA contains the final estimates. Otherwise, identical to ICALL=0.
- ICALL=4: For the data record contained in DATREC, PRED has been called during the Simulation Step for the purpose of computing a value of the dependent variable and, possibly, values of independent variables, appropriate for the record. PRED should compute F (the value of the dependent variable). THETA contains the initial estimates, which are the values to be used to compute F. PRED should call SIMETA (and SIMEPS) to obtain simulated values of ETA (and EPS).
- ICALL=5: For the data record contained in DATREC, PRED has been called for the purpose of computing the expectation of the PRED item and possibly, the expectations of other PRED-defined items, appropriate for the record. Such a call occurs when the marginal data item (MRG_) is defined in the data set and has a non-zero value for the data record in question. If the MRG_ data item on the record has the value 1 or 2, the value returned by PRED in F contributes to the expectation of the PRED item. Similarly, the values returned in other PRED-defined items contribute to expectations of these items. THETA contains the final estimates. The expectations in question are over possible values of ETA, and to obtain ETA values, PRED should call GETETA.
- ICALL=6: PRED has been called for the purpose of computing the raw data average of the DV data items and, possibly, the raw data averages of PRED-defined items. Such a call occurs when the raw-data data item (RAW_) is defined in the data set and has a non-zero value for a template data record (See template). The value of the DV data item in the data record contained in DATREC will be included in the raw data average of the DV data items. However, when the raw data average corresponding to the label DV in a table or scatterplot is to be different from the raw data average of the DV items themselves, PRED may recompute the value of DV. PRED may return a value of 1 in F to omit the DV item in the data record from the average.
- ICALL=-1: the routine has been called for the PRED_IGNORE_DATA feature (NM75). One call per data record, at the start
of the run. These calls occur only if abbreviated code uses
variables PRED_IGNORE_DATA or PRED_IGNORE_DATA _TEST, or if the
PRED_IGNORE_DATA option of
-
NEWIND
- NEWIND=0: First record of the data set. THETA value may differ from value at last call with this record.
- NEWIND=1: First record of the data set, THETA value does not differ from value at last call with this record, and PRED is nonrecursive (see I_REC), or, First record of a subsequent individual record.
- NEWIND=2: Subsequent data record of an individual record.
- THETA: the NONMEM THETA vector.
- DATREC The current data record.
- INDXS
The values specified in the
$INDEXrecord of the NM-TRAN control stream.
Output argument:
- F When ICALL=2, the prediction associated with the data record.
With discrete data, the likelihood of the observation in the
record, but if there is no observation, F is ignored.
When ICALL=4, the value of the simulated observation associated
with the data record. Alternatively, F can be ignored, and the
DV item in the data record can be directly set to the value of
the simulated observation. With discrete data,
Fis ignored; PRED should directly set the DV item to the value of the simulated observation. - G An array of derivatives of F with respect to ETAs. Values should be set when ICALL=2. G(i,1) is the partial derivative of F with respect to eta(i). When the data are population, G(i,j+1) is the second partial derivative of F with respect to eta(i), eta(j) (lower-triangular; j=1,…, i). Second derivatives are needed only when the Laplacian method is used to estimate parameters.
- H An array of partial derivatives of F with respect to EPSILONs. When the data are population, values should be set when ICALL=2. H(i,1) is the derivative of F with respect to eps(i). H(i,j+1) is the partial derivative of H(i,1) with respect to eta(j) These mixed second derivatives are needed only when the INTERACTION option isused to estimate parameters. (See $ESTIMATION).
Also see variables in NONMEM modules.
SIMEPS
|
|
SIMEPS can be called by PRED during the simulation step to obtain simulated epsilon values. It can only be called with ICALL=4.
Output argument:
EPS: a 1-D array that stores simulated epsilon values EPS(1), EPS(2).
The simulated epsilon values follow a multivariate normal distribution with mean 0 and covariance matrix SIGMA. With different calls to SIMEPS with different level-two records, new and different simulated epsilon values are obtained. (A level-two record has the same value of L2 and may also be called an L2 record. When the L2 data item is not defined, all data records are level-two records, and different data records are different level-two records.) By default, with different calls to SIMEPS with the same level-two record, the same simulated epsilon values are obtained - those obtained at the first call with the record. (There is an advanced feature whereby records are "repeated". See Repetition_Variables). When records of a level-two record are being repeated, with different calls to SIMEPS with the same level-two record, the values obtained are the last values stored in these variables when the record was previously passed to PRED.
If, the NEW option is used with the first random source on the
$SIMULATION record, then each time SIMEPS is called (with the same or
different level-two record), new and different values are obtained.
With any particular call to SIMEPS, the effect of the NEW option can,
though, be overridden; (See Simulation:_IETAOL_IEPSOL)
So that simple simulation can be easily implemented with abbreviated code, values of epsilon are obtained by calls to SIMEPS occurring in the generated subroutine. When the data are population data and the Simulation Step is implemented, SIMEPS is called once with every call to PRED (or once at every call to ERROR if PREDPP is used). These calls are implemented so that even if, initially, the Simulation Step is not implemented, the NONMEM executable resulting from using an abbreviated code for PRED (or for ERROR if PREDPP is used) can be reused with a run implementing the Simulation Step.
Additional calls to SIMEPS may appear in simulation blocks of $PRED
and $ERROR abbreviated code. There is an analogous routine SIMETA.
(See SIMETA).
For example, implementation below illustrates
ERROR routine for the Simulation Step along with a data analysis step,
applicable when drug levels are being simulated under the same model
used for the data analysis. Here
EPS is obtained using SIMEPS, and the value for the observation y is
computed and returned in F. Note that the
computation at ICALL=2 implements a slightly different model for residual variability than is
simulated.
|
|
SIMETA
|
|
Routine SIMETA can be called by PRED during the simulation step, to obtain simulated eta values. It may be called only when ICALL=4.
Output argument:
ETA: an array into which SIMETA stores simulated ETA values ETA(1), ETA(2), … The dimension of the array may be smaller than the maximum, e.g., it may equal the number of ETAs in the problem.
Simulated ETA values arise from a multivariate normal pseudo-random distribution with mean 0 and variance-covariance as specified for OMEGA. With different calls to SIMETA with different individual records, new and different simulated eta values are obtained. (With population data, an individual record has the same value of ID and may also be called a level-one "L1" record.) (See ID). By default, with different calls to SIMETA with the same individual record, the same simulated eta values are obtained - those obtained at the first call with the record. (There is an advanced feature whereby records are "repeated" (See Repetition_Variables), and when records of an individual record are being repeated, with dif- ferent calls to SIMETA with the same individual record, the values obtained are the last values stored in these variables when the record was previously passed to PRED.)
If, though, the NEW option is used with the first random source on the
$SIMULATION record, then each time SIMETA is called (with the same or
different individual record), new and different values are obtained.
Thus, for example, when PRED is called with the first data record of
an individual record, PRED can in turn call SIMETA multiple times
until values are obtained such that, for example, ETA(2) is not larger
than 5 in absolute value; that is, values can be obtained from a
truncated distribution (see below). With any particular call to
SIMETA, the effect of the NEW option can, though, be overridden; (See
Simulation:_IETAOL_IEPSOL) So that simple simulation can be easily
implemented with abbreviated code, values of ETAs are obtained by
calls to SIMETA occurring in the generated subroutine. When the
data are population data, SIMETA is called once per individual record
by PRED (or PK if PREDPP is used). (In the case of PK, the array
of ETAs is stored in a common and is available to the ERROR subroutine
as well.) When the data are single- subject data, SIMETA is
called once at every call to PRED (once at every call to ERROR if
PREDPP is used).
These calls are implemented so that even if, initially, the Simulation Step is not implemented, the NONMEM executable resulting from using an abbreviated code for PRED (for PK or ERROR if PREDPP is used) can be reused with a run implementing the Simulation Step.
EXAMPLES OF USAGE:
In this example, the value of ETA(2) used by PRED will be less than 5
in absolute value. For this code to have the desired effect, the
option NEW must be used in the $SIMULATION record.
|
|
Suppose there are two ETAs to be selected in this manner. Each one needs its own CALL SIMETA loop, because each CALL SIMETA replaces all the ETAs.
|
|
Another way this can be implemented is as follows:
|
|
See also the analogous routine SIMEPS.
Error recovery
Similar to the $PRED record, PREDPP may exit with a nonzero PRED error return code. Then either the NONMEM run is immediately aborted or an error-recovery procedure is implemented. An error-recovery procedure entails continued calls to PRED, but with values of THETA or ETA different from those with previous calls which resulted in nonzero return codes. There are two error-recovery procedures: one with which different ETA values are tried, the ETA-recovery , a second with which different THETA (and possibly ETA) values are tried, the THETA-recovery . Whenever it is possible to implement the ETA-recovery, this is done. If this procedure fails, or if it is not possible to implement the ETA-recovery, and the error return code is obtained during either the search in the Estimation Step or the search in the Initial Estimation Step, then a choice exists between an abort and implementation of the THETA-recovery. If the THETA-recovery fails, or if it is not actually possible to implement the THETA-recovery, the NONMEM run is aborted.
A PRED error return code can have values 0, 1, or 2. The value 0 means that the return is a normal return. The value 1 means that if the choice exists between an abort or implementation of the THETA-recovery, then this choice is to be made using control stream information. The value 2 means that if the choice exists between an abort or implementation of the THETA-recovery, then the abort should be chosen.
When an abort occurs, an error message will appear in the NONMEM
output, in the intermediate output file (if such a file exists), and
in the PRED Error file. When the THETA-recovery is implemented, an
error message appears in the intermediate output file (if such a file
exists), in the PRED Error file, and if recovery is not possible, in
the NONMEM output. The error message is called a PRED error message .
When the PRED error return code is 1, and a choice exists between
implementation of the THETA- recovery and an abort, the THETA-recovery
is implemented if the NOABORT option is used in the $ESTIMATION
($THETA) record. Often, the most appropriate response to an abort
occuring during the Initial Estimate Step, or during the Estimation
Step after the 0th iteration summary has been output, is to rerun the
problem requesting that the THETA-recovery be implemented. Warning: If
the implementation of the THETA-recovery is requested before an actual
abort has occured, be sure to check the PRED Error file PRDERR for
possibly useful diagnostic information that is otherwise available in
NONMEM output when an abort occurs.
- Error-Recovery from PREDPP: PREDPP may exit with a nonzero PRED error return code as a result of some computation undertaken in a PREDPP kernal or Library routine, or when PK returns an invalid value of a PK parameter. The nature of the problem will be described in the PRED error message if this message appears
- Error-Recovery from PK (same as AES, DES): PK (as well as ERROR, DES, and AES) can can force an immediate return to NONMEM from PREDPP with a nonzero PRED error return code and accompanying user message. The contents of GG are ignored. See PRED EXIT code.
- Error-Recovery from ERROR: similarly ERROR can force an immediate return to NONMEM from PREDPP with a nonzero PRED error return code and accompanying user message. The contents of F, G, and HH are ignored.
PRIOR
USAGE:
|
|
A user-written PRIOR subroutine allows a penalty function based on a prior to be specified and added to the -2log likelihood function (Gisleskog et al, JPP, 2002, p. 473-505). This serves as a constraint on the estimates of THETA, OMEGA, and SIGMA and thus as a way for stable estimates to be obtained with insufficient data.
When the Simulation Step is implemented, THETA and OMEGA, and SIGMA may also be simulated (along with ETAs and EPSILONs, should any such appear in the model and have nonzero-variances) in the PRIOR subroutine. However, this need not be done (simply execute a return in PRIOR at ICALL=4), in which case the values for THETA, OMEGA, and SIGMA used in the simulation are the values given in the NONMEM control stream or input Model Specification File.
Input argument:
- ICALL Similar to ICALL for PRED subroutine. Possible values: 0, 1, 2, and 4. In a multiple problem run, PRIOR is called with ICALL=1 only with the first problem.
Output argument:
- CNT: the penalty term.
Other Inputs are available to PRIOR in NONMEM read-only modules.
PRIOR may call NONMEM utility routines NWPRI and TNPRI:
|
|
NWPRI and TNPRI compute particular types of penalty functions. NWPRI computes a function based on a prior that has a multivariate normal form for THETA, and also, in the case of population data, an inverse Wishart form for OMEGA (independent from the normal for THETA). When used during a Simulation Step, it produces a random value of THETA and a random value of OMEGA from the prior. The prior information is entered manually into the control stream. This prior is especially useful for a subjective specification of a penalty function. (See NWPRI, TNPRI below).
Model parameters may be constrained in various ways. Those parameters whose values are not fixed are transformed to new parameters whose values are not at all constrained a priori (the "unconstrained parameters", or UCP). TNPRI computes a penalty function based on a prior that has a multivariate normal form for all UCP. When used during a Simulation Step, it produces a random value of the vector of all model parameters (whose values are not fixed). The prior information is found in an input Model Specification File, and it has been automatically stored there as part of a NONMEM analysis of a prior data set. (See also $MSFI). This prior is especially useful for an empirical specification of a penalty function. (See TNPRI).
The $PRIOR statement can be used instead of a PRIOR subroutine.
(See $prior.ctl).
NWPRI
|
|
NONMEM v7+'s new $ESTIMATION methods (BAYES,
NUTS, SAEM, etc) can only use NWPRI to specify priors.
The user-written PRIOR subroutine allows a penalty function based on a prior to be specified and added to the -2log likelihood function (Gisleskog et al, JPP, 2002, p. 473-505). This serves as a constraint on THETA, OMEGA, and SIGMA estimates and thus as a way for stable estimates of these parameters to be obtained with insufficient data. NWPRI computes a function based on a prior that has a multivariate normal form for THETA, and also, in the case of population data, an inverse Wishart form for OMEGA (independent from the normal for THETA). The parameters of these forms are called "hyperparameters".
Using NWPRI, several penalties functions, each with a different set of values for the hyperparameters, may be used simultaneously. Each set of values may be thought to arise from a different prior experiment (study). In actuality, there is a way to combine the several penalties functions into one (see above reference), and this is what NWPRI computes.
When NWPRI is used during a Simulation Step, it produces a random value of THETA and a random value of OMEGA from the prior. (See Simulation example). (See nwpri example). If NWPRI is used at ICALL=2, it need not be used at ICALL=4, and vice-versa.
NWPRI should always be called at ICALL=0 or ICALL=1.
Input arguments:
-
NTHETA,NETA,NEPS:
- NTHETA=number of THETAs to be estimated;
- NETA=number of ETAs to be estimated;
- NEPS=number of EPS' to be estimated.
These are the dimensions of the THETA, OMEGA, and SIGMA arrays of the parameters that enter into the model for the data.
Before NONMEM 7.3, NEPS was ignored. With discrete data or with continuous single-subject data, where OMEGA takes the place of SIGMA, the input argument NETA must be set.
-
NTHP,NETP,NEPP:
- NTHP=number of THETAs which have a prior;
- NETP=number of OMEGAs with prior;
- NEPP=Number of SIGMAs with prior.
The prior will only affect the initial subvector of THETA of dimension NTHP and the initial submatrix of OMEGA of dimension NETP (i.e. the submatrix consisting of the intersection of the first NETP rows and the first NETP columns of OMEGA). The initial subvector and submatrix are called the prior-affected parts of THETA and OMEGA. If NTHP=0 (NETP=0), the prior does not affect THETA (OMEGA) at all. During the Simulation Step, simu- lated values for the affected parts of THETA and OMEGA are obtained according to the prior distribution, and "the simulated values" for the unaffected parts of THETA and OMEGA are simply taken to be the values given in the NONMEM control stream or input Model Specification record. Before NONMEM 7.3, NEPP was ignored.
- NPEXP: The number of prior experiments.
-
ITYP: Relevant only if NWPRI is called during a Simulation Step.
- ITYP=0: The value of the THETA vector is obtained from simple random sampling.
- ITYP=1: Within the given problem, NWPRI is to be called a specified number (NSAM) of times to obtain this number of different values of the THETA vector. These values are obtained by generating a Latin sample of size NSAM from equiprobable partitions of an ellipsoid in THETA space (hyper-ellipsoidal sampling), followed by sampling a point "uniformly" from each partition. This scheme may be used, for example, when the problem has NSAM subproblems, in which case, NWPRI would be called NSAM times, once each time during the problem when ICALL=4, and at each of these calls, a different random value of THETA will be produced.
- ITYP=2: Just as with value 1, but the NSAM values are obtained by generating a Latin sample of size NSAM from equiprobable partitions of an ellipsoid in THETA space (hyper-ellipsoidal sampling), followed by taking the "center point" of each partition.
In all three cases, each new value of the OMEGA matrix is obtained from simple random sampling.
After each call to NWPRI, the simulated values for THETA, OMEGA and SIGMA may be found in global variables and thus they are communicated directly to NONMEM. (See PRIOR_Simulation:_Parameters).
- PLEV. When NWPRI is being used at ICALL=0 or 1, but NWPRI will
not be used at ICALL=4 (i.e. during the Simulation Step), PLEV
can be set to 0. When it is being used at ICALL=2, PLEV can also
be set to 0. When NWPRI is being used at ICALL=0 or 1 and it
will be used at ICALL=4, or when it is being used at ICALL=4,
then PLEV must be set to a fraction strictly less than 1, e.g.
0.999. PLEV is double precision with NONMEM 7, and is single
precision with NONMEM VI.
A value of THETA will actually be obtained using a truncated
multivariate normal distribution, i.e. from an ellipsoidal region
R1 over which only a fraction of mass of the normal occurs.
This fraction is given by PLEV. The distribution is further
truncated to R2, the subregion of R1 lying within the
rectangular boundaries defined on the
$THETArecord. Simple random sampling occurs in R2. Latin sampled partitions are partitions of R1. However, when ITYP=1, if a uniformly sampled point from a partition lies outside R2, it is replaced by a point obtained by simple random sampling from R2. When ITYP=2, if the center point of a partition lies outside R2, an abort occurs. - NSAM. Relevant only if NWPRI is called during a Simulation Step. Consider two cases. a) Latin hyper-ellipsoid sampling is used with ITYP=1, and b) simple random sampling along with the adjustment for small sample correlation effect is used (see next input argument). In case a) NSAM should equal the exact total number of different values of THETA that must eventually be produced over the entire NONMEM problem. In case b) NSAM should be no less than this number.
-
ISS. Relevant only if NWPRI is called during a Simulation Step. A THETA value is obtained by transforming a value from the standard multivariate normal distribution - called here "the standard value". The correlation matrix of the standard normal is the identity matrix. When NSAM is small, the estimated correlation matrix from the sampled standard values might not be quite close to the identity matrix - this is here called "the small sample correlation effect".
- ISS=1: An adjustment is made for the small sample correlation effect, by first transforming the NSAM standard values altogether into new values which are very nearly standard multivariate normal values and such that the sample correlation matrix of these new values is exactly the identity matrix.
- ISS=0: No adjustment is made for the small sample correlation effect.
Output argument:
CNT Relevant only if NWPRI is called at ICALL=2. CNT is the penalty.
See PRIOR subroutine for using NWPRI. Below we discuss using it along with $THETA, $OMEGA, $SIGMA records.
The first use is to specify the multivariate normal form for THETA
(NTHP>0). After the usual set of $THETA records, add a second set
of $THETA records giving the mean of the multivariate normal.
The values on these records must be fixed. They should number NTHP
altogether. After the usual set of $OMEGA records, add a second set
of $OMEGA records giving the variance-covariance matrix of the
multivariate normal. (If there are no ETAs in the model, there will
not be a usual set of $OMEGA records.) The values on these
records must be fixed. They should number (NTHP+1)xNTHP/2 altogether,
including implicit 0's, which may occur because the
variance-covariance matrix of the normal may be block-diagonal. If a
(regular) theta is fixed, the corresponding values of the mean and
variance-covariance matrix of the normal are ignored.
Another use is to specify the inverse Wishart form for OMEGA
(NETAP>0; population data only). After the second set of $OMEGA
records (or if NTHP=0, after the first set of $OMEGA records), add
another set of $OMEGA records giving the mode of the inverse
Wishart. The values on these records must be fixed. They should
number (NETP+1)xNETP/2 altogether, including implicit 0's, which
may occur because the mode of the inverse Wishart may be
block-diagonal. If the prior-affected part of OMEGA is given as a
block-diagonal matrix, then the mode must conform to this structure.
The SAME attribute can be used. With each diagonal block of (the
prior-affected part of) OMEGA, there corresponds a number of
"degrees of freedom" of the inverse Wishart. All blocks of a given
block set are constrained to be equal (by using the SAME attribute),
and therefore, to each of these blocks there cor- responds the same
number of degrees of freedom. After the second set of $THETA
records (or if NTHP=0, after the first set of $THETA records),
add another set of $THETA records, giving for each block set in turn
the number of degrees of freedom for the blocks of the set. The
values on these records must be fixed. There should be as many
values as there are block sets with the prior-affected part of OMEGA.
The inverse Wishart for a given block of OMEGA may be explicitly given
as "perfectly flat" by specifying the number of degrees of freedom to
be the negative of the dimension of the block, minus 1. In this case
the mode for the block may be simply taken to be the 0 matrix (or any
positive definite matrix). If a block is fixed, the corresponding
values of the mode and number of degrees of freedom are ignored.
With NONMEM 7.3 and higher, you can use more informative record names instead of directly specifying NTHETA, NETA, et al:
$THETAPfor THETA priors$THETAPVfor covariance matrix for THETA's$OMEGAPfor OMEGA prior$OMEGAPDfor degrees of freedom (or dispersion factor) for OMEGA prior$SIGMAPfor SIGMA prior$SIGMAPDfor degrees of freedom (or dispersion factor) for SIGMA prior
If the informative record names are used, the records may be in any
order, and the options of $PRIOR need not be specified. Note that the
name of the record describes the kind of information it gives, rather
than the structure of the information. E.g., in the example below,
$THETAPV is used instead of an $OMEGA record and $OMEGAPV is used
instead of a $THETA record.
(See $THETAP, $OMEGAP, $SIGMAP)
Below are three examples of extra $THETA and $OMEGA records specifying
prior information from an experiment. This information concerns all
the regular elements of THETA and OMEGA. All examples are shown with
a $PRIOR record although a PRIOR subroutine could be used instead.
|
|
Perhaps it might be more perspicuous to organize the prior information thusly:
|
|
With NONMEM 7.3 and higher, informative record names can be used:
|
|
There may be prior information from a number of experiments, in which
case the $THETA and $OMEGA records specifying this information for
each experiment may be stacked, e.g.
|
|
Blocking on the variance-covariance matrix of the normal form for THETA need not be the same across experiments.
Limitation: there must be at least one THETA parameter and one OMEGA parameter in the model.
TNPRI
|
|
TNPRI provides as a constraint on the estimates of THETA, OMEGA and SIGMA for stable estimates from insufficient data. It computes a penalty function based on a multivariate normal prior for all the unconstrained parameters.
TNPRI relies a prior NONMEM run's MSF to provide parameters (called "hyperparameters" in NONMEM guides) and prior information. The prior problem should have the Covariance Step and the Estimation Step (could have been implemented in yet an earlier problem).
Alternatively, a NONMEM control stream may consist of multiple problems, where one problem (A) uses TNPRI, and the prior problem appears as an earlier problem (B) in the same control stream. The prior information from problem B can be available to problem A without the need to use a model specification file.
When TNPRI is used during a Simulation Step, it produces a random value of the vector of all model parameters (whose values are not fixed in the parameter records) from the frequency prior. (See Simulation example). (See tnpri example). If TNPRI is used during a given problem at ICALL=2, it should not be used during the same problem at ICALL=4, and vice-versa.
TNPRI may be used at ICALL=0 or ICALL=1, in which case only the values of its input arguments are checked. If it is not used at ICALL=0 or ICALL=1, then the first time it is used at ICALL=2 or ICALL=4, checking will occur.
Not to be used with the new $ESTIMATION methods of NONMEM 7.
Input argument:
-
IFND
-
IFND=0: indicates that a prior problem has been specified either earlier in the current control stream or in a previously run control stream, and that this problem has output a model specification file. The prior information will have automatically been stored in the model specification file. The prior problem should have implemented the Covariance Step (which should have computed either the default variance-covariance matrix or two times the inverse of the R matrix). The current control stream should consist of at least two problems: the problem that uses TNPRI and a preceeding problem that serves only to input the prior information from the model specification file, such as the following:
1 2 3 4$PROB READ THE MODEL SPECIFICATION FILE $DATA data $INPUT ID TIME AMT DV TYPE SS II $MSFI msf1 ONLYREADThis simple problem (B) should be the last problem in the current control stream that appears before the problem using TNPRI (problem (A)) and inputs a model specification file. The problem specification should not include any task records, but it may include e.g. a
$SUBROUTINESrecord and/or abbreviated code, if problem B is the first problem in the control stream, and these elements will be needed for a subsequent problem. If problem A inputs a model specification file msf2, any prior information in msf2 will be ignored. If problem A outputs a model specification file msf3 and implements the Covariance Step, the prior information stored in msf3 is based not only on the data being analyzed, but also on the prior information in msf1. - IFND=1: indicates that along with the current problem (with which TNPRI is being used), a prior problem has been specified earlier in the same control stream. The prior problem is taken to be the last problem in the control stream that appears before the current one and that implements the Covariance Step.
-
-
MODE. In any NONMEM problem specification, all of the last contiguously listed parameters on the
$THETArecord, whose values on this record are fixed, and assuming the value of the very last parameter itself is fixed, are called the "terminal fixed THETA parameters". There may be no such parameters. E.g. if the$THETArecord is1$THETA 3.1 FIX 6.3 .01 400 FIX 7 FIX 90 FIXthen THETA 4-6 are the terminal fixed THETA parameters. If the record is
1$THETA 3.1 FIX 6.3 .01 400 FIX 7 FIX 90then there are no terminal fixed THETA parameters, because the value 90 of the very last parameter is not fixed. Similarly, all the last contiguous fixed parameters in OMEGA (SIGMA), assuming the values in the very last block set are fixed, are called the "terminal fixed OMEGA (SIGMA) parameters". (Recall that in a diagonal
$OMEGArecord, all the values form separate block sets.)There are some rules concerning the parameter records of a NONMEM control stream that relate the parameters of the prior problem to those of the current problem:
- With the exception of the terminal fixed THETA parameters in
the prior problem, which are altogether ignored in the
current problem, the THETA parameters of the prior problem
must be the first THETA parameters listed in the
$THETArecord of the current problem, whether or not their values are fixed in the prior problem. - The order of these first THETA parameters on the
$THETArecord must be the same as that in the$THETArecord of the prior problem. The initial estimates of these parameters need not be the same, but any upper or lower bounds must be the same. - Among the first THETA parameters, values that are fixed on the
$THETArecord of the prior problem must also be fixed on the$THETArecord of the current problem, although the values need not be the same, but not vice-versa; see discussion below concerning parameter interpretation. -
THETA parameters peculiar to the current problem may be listed at the end of the
$THETArecord of the current problem, after the parameters that are shared between the prior and current problems. E.g. if the$THETArecord with the prior problem is1$THETA 3.1 FIX 6.3 (0,.01) 400 FIX 7 FIX 90 FIXthen the
$THETArecord with the current problem may be1$THETA 10 FIX 7.0 (0,.03) 80.2 100.8in which case the values 80.2 and 100.8 are the values of the THETA parameters that are peculiar to the current problem. The 2nd and 3rd parameters are used in both prior and current problems, but have different values in the two problems. The first parameter may be used in the current problem, in which case its value is fixed to 10.
The same rules apply to the
$OMEGAand$SIGMArecords of the current problem.A model specification file from a previous instance of the current problem may be used, as usual, providing that if with the previous instance, parameter records were used, the above rules were followed.
Parameter Interpretation:
The prior information concerns all parameters appearing in the prior problem whose values are not fixed in that problem. However, a parameter with a nonfixed value in the prior problem may have a fixed value in the current problem, and this gives rise to some ambiguity. Such a parameter may have an interpretation in the prior problem that remains unchanged in the current problem. Then it needs to be identified as a "shared parameter", in which case, because the value of the parameter is fixed with the current model, the frequency prior needs to be adjusted in order to approximate the -2log likelihood function for the prior data when the parameter value is regarded as being fixed in the prior model. (or when TNPRI is being called in the Simulated Step, in order to use a conditional prior distribution, given the parameter value is the fixed value). A shared parameter may not actually be used in the current problem, but the salient point is that with the current problem, the interpretation of this parameter remains unchanged. Alternatively, the parameter's interpretation may change in the current problem. Then it needs to be identified as a "prior-specific" parameter, in which case if it is actually used in the current model, its value will be the fixed value, but for the purpose of applying the prior information, TNPRI will regard this parameter as one specific to the prior model. The MODE argument concerns this distinction.
- With the exception of the terminal fixed THETA parameters in
the prior problem, which are altogether ignored in the
current problem, the THETA parameters of the prior problem
must be the first THETA parameters listed in the
-
MODE=0: all parameters with a nonfixed value in the prior problem but a fixed value in the current problem are identified as being prior-specific parameters. However, the final estimates of these parameters are their fixed values.
- MODE=1: all parameters with a nonfixed value in the prior problem but a fixed value in the current problem are identified as being prior-specific parameters. If the Estimation Step is implemented, the final estimate for such a parameter is the same one that would result from not fixing the value of the parameter in the current problem and letting it be estimated, assuming that the parameter is not at all used in the current model. This value will be similar to the final estimate of the parameter in the prior problem. (A difference from this prior estimate may result, reflecting the fact that if there is a sequence of models, each a submodel of the one succeeding it, then the data used to fit the last of the models may bear on a parameter peculiar to the first model, if only slightly.) If indeed the parameter's value were not fixed, but the parameter's estimate obtained along with the estimates of the non-prior-specific parameters, then the latter estimates and the minimum value of the objective function would be unchanged, but the search for the parameter's estimate would require additional computer time. With the value MODE=1, in fact, the parameter's estimate is obtainable posthoc, after the search, and this additional computer time is saved. The output from the Covariance Step includes all the usual type of information about the estimators of the prior-specific parameters along with that about the estimators of the non-prior-specific parameters. However, note that an output model specification file will not contain any information about the estimates of prior-specific parameters.
- MODE=2: all parameters with a nonfixed value in the prior problem but a fixed value in the current problem are identified as being shared parameters (i.e. the frequency prior is adjusted). The final estimates of these parameters are their fixed values.
-
ITYP: relevant only if TNPRI is called during a Simulation Step.
- ITYP=0: the value of the UCP (unconstrained parameter) vector is obtained from simple random sampling.
- ITYP=1: within the given problem, TNPRI is to be called a specified number (NSAM) of times to obtain this number of different values of the UCP vector. These values are obtained by generating a Latin sample of size NSAM from equiprobable partitions of an ellipsoid in UCP space (hyper-ellipsoidal sampling), followed by sampling a point "uniformly" from each partition. This scheme may be used, for example, when the problem has NSAM subproblems, in which case, TNPRI would be called NSAM times, once each time during the problem when ICALL=4, and at each of these calls, a different random value of the UCP vector will be produced.
- ITYP=2: same as ITYP=1, but the NSAM values are obtained by generating a Latin sample of size NSAM from equiprobable partitions of an ellipsoid in UCP space (hyper-ellipsoidal sampling), followed by taking the "center point" of each partition.
In all three cases, a value of the UCP vector is transformed into THETA-OMEGA-SIGMA space.
After each call to NWPRI, the simulated values for THETA, OMEGA and SIGMA may be found in global variables and thus they are communicated directly to NONMEM. (See PRIOR_Simulation:_Parameters).
- PLEV. when TNPRI is being used at ICALL=0 or 1, but TNPRI will not be used at ICALL=4 (i.e. during the Simulation Step), PLEV should be set to 0. When it is being used at ICALL=2, PLEV should also be set to 0. When TNPRI is being used at ICALL=0 or 1 and will also be used at ICALL=4, or when it is being used at ICALL=4, then PLEV must be set to a fraction strictly less than 1, e.g. 0.999. PLEV is double precision with NONMEM 7, and is single precision with NONMEM VI. A UCP value will actually be obtained using a truncated multivariate normal distribution, i.e. from an ellipsoidal region R1 over which only a fraction of mass of the normal occurs. This fraction is given by PLEV. Simple random sampling occurs in R1. Latin sampled partitions are partitions of R1.
- NSAM. Relevant only if TNPRI is called during a Simulation Step. Consider two cases. a) Latin hyper-ellipsoid sampling is used with ITYP=1, or b) simple random sampling along with the adjustment for small sample correlation effect is used (see next input argument). In case a) NSAM should equal the exact total number of different values of the parameter vector that must eventually be produced over the entire NONMEM problem. In case b) NSAM should be no less than this number.
-
ISS. Relevant only if TNPRI is called during a Simulation Step. A value of the UCP vector is obtained by first sampling a value from the standard multivariate normal distribution ( "the standard value") and then transforming this value to one from the appropriate multivariate normal. The correlation matrix of the standard normal is the identity matrix. When NSAM is small, the estimated correlation matrix from the sampled standard values might not be quite close to the identity matrix - this is here called "the small sample correlation effect".
- ISS=1. An adjustment is made for the small sample correlation effect, by first transforming the NSAM standard values altogether into new values which are very nearly standard multivariate normal values and such that the sample correlation matrix of these new values is exactly the identity matrix.
- ISS=0: No adjustment is made for the small sample correlation effect.
-
IVAR. Relevant only if TNPRI is called during a Simulation Step. When TNPRI simulates a parameter value, this value is that of an estimate of the parameter from possible data under the prior model, and this simulation is based on asymptotic statistical theory. The partial derivatives comprising the R and S matrices referred to below are taken with respect to the UCP (See covariance).
- IVAR=0: The variance-covariance matrix of the multivariate normal on the UCP is taken to be two times the inverse R matrix obtained from the prior problem. This could be appropriate if the estimated asymptotic variance-covariance matrix from the prior problem is also based only on the R matrix.
- IVAR=1: the variance-covariance matrix of the multivariate normal on the UCP is taken to be Rinv*S*Rinv matrix from the prior problem.
- IVAR=2: the variance-covariance matrix of the multivariate normal on the UCP is taken to be S matrix from the prior problem. (NM75)
In summary, IVAR=0 uses \(R^{-1}\) of a former problem; IVAR=1 uses \(R^{-1}SR^{-1}\) of a former problem; IVAR=2 uses \(S\) of a former problem.
Output argument:
CNT Relevant only if TNPRI is called at ICALL=2. CNT is the penalty.
RANDOM
|
|
The NONMEM utility routine RANDOM may be called by PRED, PK or ERROR during the Simulation Step (ICALL=4) and data average block (ICALL=5) to obtain numbers from random number generators.
Input argument:
- KR: an integer variable or integer constant. The index of the
random source. Random sources are defined using the
$SIMULATIONrecord. With standard normal as the default distribution. Typically, the first source is reserved by NONMEM to generate realizations of the ETA and EPSILON variables and/or to randomly mix individuals into different subpopulations according to the mixing parameter. Thus, typically, RANDOM must be called with KR > 1. A random source that is specified on the$SIMULATIONrecord as NONPARAMETRIC should not be used to obtain a value of R.
Output argument:
- R: A number from the KR RNG. R is of double precision since NONMEM 7 but single precision in earlier versions. Each time RANDOM is called, a new R is generated.
An abbreviated code may use RANDOM explicitly in either a simulation or a data average block. When RANDOM is called in abbreviated code, R is reserved and is used for the random number. For example, below WT (a data item and a local variable with the same name) is generated with a simulated value having mean 70 and standard deviation 7.
|
|
SPTWO
USAGE:
|
|
SPTWO is used to redefine the meaning of the RES and WRES items for observation records within an individual record. It is called with each individual record. The labels 'RES' and 'WRES' can be changed, as usual.
Input argument:
- ICALL Similar to ICALL for PRED subroutine. Possible values: 0, 1, 2
- NROB Number of observation records in the individual record.
Output argument:
- I1,I2: when SPTWO is used, by default, I1 and I2 are 0, meaning zero lines are not to be generated through RES or WRES values on scatterplots. If zero lines through RES or WRES values on scatterplots are desired, SPTWO should set I1 or I2, respectively, to 1.
- D(J,1): Value of RES for Jth observation record, J=1,…,NROB.
- D(J,2): Value of WRES for Jth observation record, J=1,…,NROB
- IER Error indicator. 0 - Normal return; non-zero - error stop.
Other Inputs:
NONMEM read-only global variables.
(See MIX:_DATA)
(See Non-active ETA for PRED)
TRANS
|
|
The TRANS subroutine translates (or transforms) the values for a set of basic PK parameters modeled in PK to a set of values for the inter nal parameters required by the ADVAN. The PREDPP Library has a number of TRANS subroutines, representing different possible parameterizations in PK, from which the user may choose. If a suitable translator is not found in the Library, the user may write his own.
Input/Output argument:
-
ITRANS
- ITRANS=1: TRANS has been called for initialization at the beginning of a NONMEM problem; one such call per problem. ITRANS must be reset by TRANS to a number in the range 1-8999. This number appears on NONMEM output, allowing the user to identify the TRANS routine being used.
- ITRANS=2: On input the GG array has stored in it the values computed by PK (except that were any PK parameter modeled in its logarithm form in PK, PREDPP would have already exponentiated its typical/subject-specific value and multiplied its eta derivatives by its exponentiated typical/subject-specific value). On output the GG array should have stored in it the values that would be computed by PK were the internal parameters of the ADVAN modeled directly in PK (and none in their logarithmic form).
- ITRANS=4: TRANS has been called during the Simulation Step. Only the first column of the GG array need be computed as with ITRANS=2. Other columns need not be computed.
- GG: the array of PK parameters and their eta derivatives.
Input argument:
- NETAS: the number of population ETAs in the problem.
Certain variables are available in modules. Their use is optional.
- Variables in read/write modules: IERPRD NETEXT ETEXT (See PRED Exit Code, PRED Error Message).
- Variables in read-only commons: NOETAS, SECOND (see Partial Derivative Indicators). When SECOND is true, PREDPP requires second-partial derivatives of ETAs.
REFERENCES: Guide VI, section III.M
TOL
|
|
Optional declarations with NONMEM 7.4:
|
|
The TOL subroutine is called by PREDPP when ADVAN 6, 8, 9, 10, 13, 14, 15, 16, 17, or 18 is used. It is also called when SS6 or SS9 is used. With NONMEM 7.4, there are multiple calls during the run, for each NONMEM step. With earlier version, TOL is called only once at the start of a run.
Output argument:
- NRD(I): The number of digits that are required to be accurate in the
computation of the drug amount in compartment I, i.e., the relative
tolerance. ADVAN 9, 13, 16, 17, and 18 have the capability of
using different values of NRD for different compartments (ADVAN 14
and 15 only allow different absolute tolerances for each
compartment). For compartments not specified, the tolerance of the
last compartment specified will be used.
However, all the other ADVAN routines requiring TOL take the
relative tolerance to be the same for all compartments; NRD(I), I >
1, is ignored, and only NRD(1) is used. With NONMEM 7.4, NRD(0) is
the relative tolerance for the Steady State computations. If
NRD(0) is not specified, NRD(1) is used.
The value of NRD(1) can also be specified using
$SUBROUTINESoption TOL. The value of NRD(0) can also be specified using$SUBROUTINESoption SSTOL. - ANRD(I) (NM74): the absolute tolerance in the computation of the
drug amount in compartment I. The default is 12 (that is,
accuracy is 10**(-12)). Used by ADVAN 9, 13, 14, 15, 16, 17,
and 18, which have the capability of using different values of ANRD
for different compartments. For compartments not specified,
the tolerance of the last compartment specified will be used.
ANRD(0) is the absolute tolerance for the Steady State
computations. If ANRD(0) is not specified, ANRD(1) is used. The
value of ANRD(1) can also be specified using
$SUBROUTINESoption ATOL. The value of ANRD(0) can also be specified using$SUBROUTINESoption SSATOL. - NRDC(I) (NM74): same as NRD(I), but used for the FOCE/LAPLACE
covariance step. Used with ADVAN 9, 13, 14, and 15, 16, 17, and 18.
If not set, NRDC defaults to the value of NRD. NRDC(0) is used
for Steady State computations during the FOCE/LAPLACE covariance
step.
The value of NRDC(1) can also be specified using
$SUBROUTINESoption TOLC. The value of NRDC(0) can also be specified using$SUBROUTINESoption SSTOLC. - ANRDC(I) (NM74): Same as ANRD(I), but used for the FOCE/LAPLACE
covariance step. Used with ADVAN 9, 13, 14, and 15, 16, 17,
and 18. If not set, ANRDC defaults to the value of ANRD. ANRDC(0)
is used for Steady State computations during the FOCE/LAPLACE
covariance step.
The value of ANRDC(1) can also be specified using
$SUBROUTINESoption ATOLC. The value of ANRDC(0) can also be specified using$SUBROUTINESoption SSATOLC.
When NM-TRAN is used, this information may be supplied by either the
TOL option of the $SUBROUTINES record or the $TOL record.
One may supply a TOL routine that assigns values of NRD and ANRD specifically for the initial (base) setting and each NONMEM step (estimation, covariance, simulation, table/scatter step, simulation, initial parameters estimate, nonparametric). For example, create a toluser.f90 file,
|
|
and incorporate it using $SUBR
|
|
Verbatim code
USAGE:
|
|
Verbatim code is Fortran code within a block of abbreviated code that is to be copied by NM-TRAN to the generated Fortran subroutine. It is not itself regarded as abbreviated code. Such code is marked by having the character " as the first non-blank character. The " is dropped and the characters to the right are copied as-is to columns 1-72 of the generated subroutine. Lines of verbatim code can include any Fortran statements: comment, declaration (e.g., INTEGER, COMMON, USE), I/O, CALL, assignment, continuation, DO, GOTO, etc.).
NM-TRAN makes some modifications to verbatim code:
- Placement: the verbatim code is adjusted as necessary to conform to FORTRAN column conventions. Alphabetic text that follows the initial ", or that follows a statement number, is moved to column 7, as required by FORTRAN.
- Comment lines: If the character that immediately follows the initial " is !, this conforms to the FORTRAN 90 syntax for comment lines. The line is copied unchanged. If the character that immediately follows the initial " is C or c or " or *, this conforms to the FORTRAN 77 syntax for comment lines. The line is copied unchanged, but C or c or " or * is replaced by !.
-
Continuation lines: Fortran 77 continuation lines (non-blank in position 6) are not permitted with NONMEM 7. Instead, the line to be continued should end with character &. Example:
1 2" X=A & " +D/E - Replacement Rule: in
$PK,$ERROR,$DES,$AES,$INFN, and$PRED, in a line of abbreviated code labels of items in the data record are replaced by direct references to the data record itself (either DATREC or EVTREC, as appropriate). Thus, for example, if such a label occurs as the left-hand side of an assignment statement, then without this rule, when the statement is executed, the value of a local variable having the label is modified, whereas with the rule, an item in the data record is modified.
The character @, immediately before a label, can be used as an "escape" to prevent the label from being replaced. If the character @ immediately follows the initial ", none of the labels occuring in the line are replaced.
Labels occurring in common statements or as subroutine arguments are never replaced.
Tab characters (and other characters that are smaller than blank in the computer's collating sequence, such as carriage return ^M) are permitted in verbatim code. With NONMEM 7, the last non-blank character on the line is replaced by a space if it is a low-value character. This permits DOS-type line endings ^M.
By default, all verbatim code goes in the main section of code and is called MAIN verbatim code. (The main section follows declarations and initial executable code inserted by NM-TRAN.) Within the main section, verbatim and abbreviated code may be freely mixed. Each line of verbatim code is positioned in the generated code after all code generated from the preceding line of abbreviated code. The user may explicitly specify a different location as follows.
- FIRST verbatim code: Verbatim lines which must be positioned immediately after the declarations which are part of the normal subroutine header, and prior to the FIRST executable statement of the subroutine, must precede the first line of abbreviated code and must start with the line "FIRST.
- MAIN verbatim code: FIRST verbatim code is normally terminated by the first line of abbreviated code. If there is both FIRST and MAIN verbatim code, and/or the main section is to start with verbatim code, the line "MAIN may be used to separate the FIRST and MAIN verbatim code.
-
LAST verbatim code: Verbatim lines which are to immediately precede the RETURN statement from the generated subroutine must follow the last line of abbreviated code and must be preceded by the line "LAST.
Example:
1 2 3 4$ERROR Y=F*(1+ERR(1)) "LAST " PRINT *,HH(1,1)This displays values after they have been assigned, immediately prior to the return.
If any lines of verbatim code are present in a block of abbreviated code, NM-TRAN generates USE statements appropriate to the kind of abbreviated code and allows variables undefined in abbreviated code to be used as right-hand quantities in abbreviated code.
FSUBS
NM-TRAN generates a special Fortran file "FSUBS" that contains subroutines and modules based on NM-TRAN input file.
FSIZESR
Since v7.2+, NONMEM employs dynamic memory allocation. Subroutine FSIZESR contains the constants
for the allocation. The $SIZES record can be used to override some of
the values in FSIZESR. Constants set to 0 cannot be determined or are
not given by NM-TRAN and will default to the values in
resource/SIZES.f90 in NONMEM source code.
NMPRD4, PRINFN, and DECLAREVARIABLES
Module NMPRD4 stores NONMEM runtime variables.
It is also accessible in user-supplied routines and generated code,
and also by NONMEM. User can use $TABLE to output the module variables.
It is possible for the user to set aside a portion of NMPRD4 for
variables defined in user-supplied code, or for variables directly
controlled by the user (see COMACT, COMRES, COMSAV in Chapters III.B.7
and IV.E.2).
Module PRINFN is only for user-supplied and generated code.
NM-TRAN creates this module only when $INFN is used.
Module DECLAREVARIABLES stores variables in $ABBREVIATED DECLARE control record. (NM73)
THETAISUB, THETARSUB
The two subroutines implement the $THETAI and $THETAR records, respectively.
They are created only when the corresponding record is used.
MUMODEL2
Subroutine MUMODEL2 subroutine is based on the PRED or PK subroutine
in FSUBS. It contains only statements (if any) for the MU model, which
is used in the new (Bayseian) methods of NONMEM.
Related to FSUBS, NM-TRAN the following files for user checking and debugging purposes. They are not directly used by NONMEM.
FSUBS_MU.F90: the file forMUMODEL2in FSUBS.FSIZES: same as theFSIZESRroutine in FSUBS.FMSG: messages (information, warning, error) NM-TRAN run, same as displayed in terminal.FORIG: the original (pre-replacement) abbreviated code and$TABLEand$SCATTERrecords.FREPL: the new (post-replacement) abbreviated code and$TABLEand$SCATTERrecords.FSUBS2,=FSUBS.F90: duplicates ofFSUBS.