Frequently, patients are numbered in any manner of non-sequential
ways and the modeler may want a sequential patient numbering,
for example, to use in plotting programs. Also, it may at
times be useful to have a number for a record within an individual
or a sequential number for all records in a data set (e.g.
to aid in tracking down specific outliers). The code below
is one way to obtain all three of these goals:
SID, sequential individual number
INDR, record number within an individual
INDX, sequential number of all records in a data file
Simply add the code below to the $PK section of your control
stream and the variable names to the $TABLE record. Note this
code DOES NOT work with POSTHOC or FOCE, so as a work-around
you could to do this in a separate METHOD=0 run (without POSTOC)
if you are using either POSTHOC or FOCE methods. The desired
columns from this run could then be appended to your table from
the POSTHOC or FOCE run. [See NONMEM Users Guide V, p.78 for
a description of NEWIND.]
$PK
;TO SEQUENTIALLY NUMBER INDIVIDUALS
IF(NEWIND.EQ.0) SID=1
IF(NEWIND.EQ.1) SID=SID+1
;TO NUMBER RECORDS WITHIN AN INDIVIDUAL
IF(NEWIND.EQ.1.OR.NEWIND.EQ.0) INDR=1
IF(NEWIND.EQ.2) INDR=INDR+1
;TO NUMBER ALL RECORDS IN A DATAFILE
IF(NEWIND.EQ.0) INDX=1
IF(NEWIND.EQ.1) INDX=INDX+1
IF(NEWIND.EQ.2) INDX=INDX+1
$ESTIMATION MAXEVAL=9999 PRINT=5 METHOD=0 ;DON'T USE POSTHOC
or FOCE!!!
$TABLE ID TIME DV AMT SID INDR INDX FILE=TABLE.TAB NOPRINT
[Generic Disclaimer: Verify that this code or any other code
you receive from an outside source works with YOUR DATA.]
NONMEM Coding Challenge #2:
Why doesn't this code generate the correct values for
SID & INDX with Posthoc or FOCE?
How would you code a general method that works for M=0/M=0
Posthoc/M=1? Send your solutions to nmconsult@globomaxnm.com.
Best solution will appear as a future tip of the week.