From:  "Anthe Zandvliet" Apaza@SLZ.NL
Subject:  [NMusers] simulation of dose escalation study 
Date:  Fri, April 15, 2005 5:34 am 

Dear all,

I want to simulate a dose escalation study based on a PKPD population model. With
the attached files, I can indeed perform the simulation. However, I need to redefine
the seed for each individual. Does anyone know how to perform this simulation in a
more automated manner? 

The PKPD model (which I have simplified for the purpose of asking for your
recommendations) comes down to:
- a 1-compartment linear PK model. The drug is administered as a singel bolus at
time=1.
- a PD model representing a side effect of the drug.
- a dummy compartment to calculate the maximal side effect.

The maximal side effect is representative for the severeness of the side effect and
determines whether or not the dose is escalated. If the maximal side effect remains
below 50 in a particular patient (A),  the dose for the subsequent patient (B) is
escalated to the next dose level. If the maximal side effect of patient A is larger
than 50, the dose for patient B remains at the same level. etc.

Using 006_1.ctl, the maximal side effect Emax is simulated for patient A.
Subsequently, 007.ctl is applied to determine the dose level for patient B. Emax of
patient B is determined with 006_2.ctl where the seed is changed from 1 to 2. Again,
007.ctl calculates the dose level for patient C. etc.
This can be done quite easily for a couple of patients using a batch file. However,
in order to simulate 200 studies of 20 patients each, 4000 control streams should be
renamed and seeds need to be changed. 

Does anyone know how to do this more conveniently? Thank you in advance!

Best regards, Anthe

************************************
nmusers.for

      SUBROUTINE READER() 
      COMMON /READ/ TID,TCOV 
      REAL TID(13),TCOV(13,2) 
      OPEN(UNIT = 77,FILE = 'DATA.CSV') 
      REWIND 77 
      DO 11,I = 1,13 
      READ(77,*) TID(I),TCOV(I,1), TCOV(I,2)
 11 CONTINUE 
      END 

      SUBROUTINE GET_SUB(NEWIND,ID,CURID,COV1,COV2,MID) 
      COMMON /READ/ TID,TCOV 
      REAL ID,CURID,COV1,COV2,MID 
      INTEGER NEWIND 
      REAL TID(13),TCOV(13,2) 
      IF (NEWIND.EQ.1) THEN 
 12 CONTINUE 
      IF(ID.GT.TID(CURID)) THEN 
      CURID =CURID + 1 
      GOTO 12 
      END IF 
      ELSEIF(NEWIND.EQ.0) THEN 
      CURID = 1 
      END IF 
      COV1 = TCOV(CURID,1) 
      COV2 = TCOV(CURID,2) 
      MID =  TID(CURID) 
      END 

************************************
006.csv

SID        ID        TIME        AMT        LEV        DV        NUL
1        13        0        0        50        0        0
1        13        1        1        50        0        0
1        13        2        0        50        0        0
1        13        3        0        50        0        0
1        13        4        0        50        0        0
1        13        5        0        50        0        0
1        13        6        0        50        0        0
1        13        7        0        50        0        0
1        13        8        0        50        0        0
1        13        9        0        50        0        0
1        13        10        0        50        0        0
1        13        11        0        50        0        0
1        13        12        0        50        0        0

*****************************
006.bat

CALL NMFE5 006_1.CTL 006_1.RES
CALL NMFE5 007.CTL 007.RES
CALL NMFE5 006_2.CTL 006_2.RES
CALL NMFE5 007.CTL 007.RES
CALL NMFE5 006_3.CTL 006_3.RES
CALL NMFE5 007.CTL 007.RES

************************************
006_1.ctl

$PROB RUN# 006
$INPUT SID ID TIME AMT LEV DV NUL
$DATA 006.CSV IGNORE=@ 
$SUBROUTINES ADVAN6 TOL=5
$MODEL COMP=(PK, DEFDOS) 
       COMP=(PD, DEFOBS)
       COMP=(EMAX)

$PK 
F1=LEV
S1=THETA(1)*EXP(ETA(1)) 
K12=THETA(2)*EXP(ETA(2))
S2=THETA(3)*EXP(ETA(3))
K20=THETA(4)*EXP(ETA(4))

IF(TIME.EQ.0)  CID=1
IF(TIME.EQ.1)  CID=2
IF(TIME.EQ.2)  CID=3
IF(TIME.EQ.3)  CID=4
IF(TIME.EQ.4)  CID=5
IF(TIME.EQ.5)  CID=6
IF(TIME.EQ.6)  CID=7
IF(TIME.EQ.7)  CID=8
IF(TIME.EQ.8)  CID=9
IF(TIME.EQ.9)  CID=10
IF(TIME.EQ.10) CID=11
IF(TIME.EQ.11) CID=12
IF(TIME.EQ.12) CID=13

$DES
DADT(1)=-K12*A(1)
DADT(2)=K12*A(1)-K20*A(2)
IF(DADT(2).GT.0) THEN
DADT(3)=DADT(2)
ELSE
DADT(3)=0
ENDIF

$ERROR
IPRED=F
Y=IPRED*EXP(EPS(1))
E=A(2)/S2
EMAX=A(3)/S2

$THETA
1    ;S1
0.5  ;K12
1    ;S2
0.3  ;K20

$OMEGA
0.01
0.01
0.01
0.01

$SIGMA
0.01

$SIMULATION (1) ONLYSIM

$TABLE SID ID TIME AMT DV DV NUL
       FILE=006.TAB  NOAPPEND NOPRINT ONEHEADER NOFORWARD 
$TABLE CID EMAX LEV
       FILE=DATA.CSV NOAPPEND NOPRINT NOHEADER  NOFORWARD 

********************************
007.ctl

$PROB RUN# 007
$INPUT SID ID TIME AMT DVR DV NUL       
$DATA 006.TAB IGNORE=@
$SUBROUTINES OTHER=NMUSERS.FOR

$PRED
" FIRST
" REAL CURID,ICOV1,ICOV2,MID
" LOGICAL READ
" IF(.NOT.READ)THEN
" CALL READER()
" CURID=1
" READ=.TRUE.
" ENDIF
" IF(NEWIND.LT.2)THEN 
" CALL GET_SUB(NEWIND,ID,CURID,ICOV1,ICOV2,MID)
" ENDIF

COV1=ICOV1
COV2=ICOV2

EMAX=ICOV1
LEV=ICOV2

IF(LEV.EQ.50)   NEXT=100
IF(LEV.EQ.100)  NEXT=200
IF(LEV.EQ.200)  NEXT=400
IF(LEV.EQ.400)  NEXT=500
IF(LEV.EQ.500)  NEXT=600
IF(LEV.EQ.600)  NEXT=700
IF(LEV.EQ.700)  NEXT=800
IF(LEV.EQ.800)  NEXT=1000
IF(LEV.GE.1000) NEXT=LEV+100

IF(EMAX.GT.50) THEN
LEVN=LEV
ELSE
LEVN=NEXT
ENDIF

SIDN=SID+1

X=THETA(1)*EXP(ETA(1))
Y=X

$THETA
1 

$OMEGA
0.0001

$SIMULATION (9999) ONLYSIM 

$TABLE SIDN ID TIME AMT LEVN NUL NUL
       FILE=006.TAB NOPRINT ONEHEADER NOFORWARD 

$TABLE SID ID TIME LEV EMAX DVR 
       FILE=007.TAB NOPRINT ONEHEADER FORWARD 

**********************************
006_2.ctl

;Model Desc: base model
;Project Name: pkpd simulaties
;Project ID: NO PROJECT DESCRIPTION

$PROB RUN# 006
$INPUT SID ID TIME AMT LEV DV NUL
$DATA 006.TAB IGNORE=@ 
$SUBROUTINES ADVAN6 TOL=5
$MODEL COMP=(PK, DEFDOS) 
       COMP=(PD, DEFOBS)
       COMP=(EMAX)

$PK 
F1=LEV
S1=THETA(1)*EXP(ETA(1)) 
K12=THETA(2)*EXP(ETA(2))
S2=THETA(3)*EXP(ETA(3))
K20=THETA(4)*EXP(ETA(4))

IF(TIME.EQ.0)  CID=1
IF(TIME.EQ.1)  CID=2
IF(TIME.EQ.2)  CID=3
IF(TIME.EQ.3)  CID=4
IF(TIME.EQ.4)  CID=5
IF(TIME.EQ.5)  CID=6
IF(TIME.EQ.6)  CID=7
IF(TIME.EQ.7)  CID=8
IF(TIME.EQ.8)  CID=9
IF(TIME.EQ.9)  CID=10
IF(TIME.EQ.10) CID=11
IF(TIME.EQ.11) CID=12
IF(TIME.EQ.12) CID=13

$DES
DADT(1)=-K12*A(1)
DADT(2)=K12*A(1)-K20*A(2)
IF(DADT(2).GT.0) THEN
DADT(3)=DADT(2)
ELSE
DADT(3)=0
ENDIF

$ERROR
IPRED=F
Y=IPRED*EXP(EPS(1))
E=A(2)/S2
EMAX=A(3)/S2

$THETA
1    ;S1
0.5  ;K12
1    ;S2
0.3  ;K20

$OMEGA
0.01
0.01
0.01
0.01

$SIGMA
0.01

$SIMULATION (2) ONLYSIM

$TABLE SID ID TIME AMT DV DV NUL
       FILE=006.TAB  NOAPPEND NOPRINT ONEHEADER NOFORWARD 
$TABLE CID EMAX LEV
       FILE=DATA.CSV NOAPPEND NOPRINT NOHEADER  NOFORWARD 




Slotervaart Hospital˙
Dept. Pharmacy and Pharmacology
Louwesweg 6
1066 EC AMSTERDAM
The Netherlands
Telephone +31 20 512  4657
FAX +  31  20 512 4753
_______________________________________________________

From:  "Tsai, Max" max.tsai@spcorp.com
Subject: RE: [NMusers] simulation of dose escalation study 
Date:  Fri, April 15, 2005 8:07 am 

Anthe,
I have encountered a similar issue recently.  There are two approaches that
I have taken.  The first approach utilizes a programming language (I used
SAS) to create all of the control streams to be run in your simulation.
Using a "random" number generator, specify the random value as part of a
larger character string (i.e. control stream) in SAS so that each control
stream will have a different seed value.  The second approach uses the
subproblem option of the simulation statement in NONMEM.  In your case,
subproblems=200.   This should provide different values for each replicated
study.  You may need to use SAS or some other software to help you sort
through what will be a large output table.  Hope this helps.     

-Max
_______________________________________________________

From:  "Anthe Zandvliet" Apaza@SLZ.NL
Subject: RE: [NMusers] simulation of dose escalation study
Date: Fri, April 15, 2005 8:22 am 

Dear Max,

Thank you for your prompt response. The application of SAS sounds like a solution to
the problem. I have never used it, though, and was hoping to find a solution within
nonmem. The subproblems option doesn't work in this particular case, because 2
control streams are required to simulate data for 1 individual. 

Regards,
Anthe
_______________________________________________________

From: "Leonid Gibiansky" leonidg@metrumrg.com
Subject: RE: [NMusers] simulation of dose escalation study 
Date:  Fri, April 15, 2005 9:29 am 

Anthe,
Design of the study is not completely clear from your e-mail (whether you do
escalation for all 20 
volunteers or you block them by cohorts) and I have not tested it before but: you
may be able to do 
it using
$ABBREV COMRES=
option. COMRES allows you to store and use global variables that are transfered from
one time to the 
next one and from the volunteer to the next volunteer. Using few COM(.) variables,
you may be able 
to create an indicator whether previous volunteer had adverse event (and the next
dose should be 
equal to the previous one) or dose needs to be increased. Dose increase can be done
via 
bioavailability parameter F. In your data file you assign initial (equal) doses for
all 20 patients 
but increase F if needed (if COMRES-stored variables dictate you to do so).

The control stream / data file should describe a study of 20 volunteers. The you can
use 
SUBPROBLEMS=200 options to repeat it 200 times.

Leonid
_______________________________________________________

From:  "Anthe Zandvliet" Apaza@SLZ.NL
Subject: RE: [NMusers] simulation of dose escalation study
Date: Fri, April 15, 2005 10:53 am 

Leonid, 

Thank you very much for your helpful input! I will indeed cluster the volunteers in
cohorts, but I had reduced the control stream to a minimum length for the purpose of
sending it to NMUsers. 

Anthe
_______________________________________________________

From: mark.e.sale@gsk.com 
Subject: RE: [NMusers] simulation of dose escalation study 
Date: Mon, April 18, 2005 12:23 pm 

Anthe, 
  The simulation seed can be accessed in the FCON file, which can be editted by a number of
  methods, in the line SORC.  This can be easily edited using macros (I prefer Excel, very
  easy to write)  Then, you don't have to recompile NONMEM, just run the executable again.
  (I'll be happy to share code on how to do this if needed)   Here is an FCON from simulation. 

FILE    FSTREAM                                                                 
PROB    example                                                           
DATA       1   0   0  10   0                                                     
ITEM       1   3  10  11   1   0   0   0   0   0  20   0   0                     
INDX       9   2   4   0   5   6   8   0   0   0   7                             
LABL      ID    TIME      DV     AMT      SS      II    ADDL     CMT    EVID     
         MDV                                                                     
                                                                         IOB     
                  VC      LC                                                     
FORM                                                                             
(9E5.0,1F2.0)                                                                   
STRC       6   5   1   0   0   0   4   1   0                                     
STRC       1   1   1   1   1   2   1   1                                         
THCN       1   0   0   0                                                         
THTA       .0167    83.7   0.651    1.33    1.16  0.0034                         
LOWR           0       0      -2       0-1000000       0                         
UPPR     1000000 1000000       1 1000000 1000000 1000000                         
BLST      0.0807                                                                 
BLST       0.041                                                                 
BLST      0.0829  -.0631   0.133                                                 
BLST       0.583                                                                 
DIAG   1       0                                                                 
SIML       0   1   0   0   1   0   0                                             
SORC       061997622               0 
TABL       1   2                                                                 
TABL   1   4   1   0   2   0  30   0   9   0                                     
           0   1   1   0   0                                                     
TABL   1   4   1   0   2   0  32   0  33   0                                     
           0   1   1   0   1             




And here is some simple Excel macro code to edit it with a new simulation seed 

Public Sub set_fcon() 
DoEvents 
Open "fcon" For Input As #1 
Open "fcon.new" For Output As #2 
Dim line As String 
While Not EOF(1) 
Line Input #1, line 
If Left(line, 4) <> "SORC" Then 
Print #2, line 
Else 
Print #2, "SORC       " & Format(Rnd() * 100000000, "000000000") & "               " & 0 
End If 
Wend 
Close #1 
Close #2 
FileCopy "fcon.new", "fcon" 
End Sub 



Mark Sale M.D.
Global Director, Research Modeling and Simulation
GlaxoSmithKline
919-483-1808
Mobile 
919-522-6668
_______________________________________________________