From: Nick Holford <*n.holford*>

Date: Fri, 23 Oct 2015 07:56:30 +1300

Tommy,

When a variable is defined in NM-TRAN it persists to all subsequent

records in the data set.

You could do something like this:

$ERROR

IF (NEWIND.LE.1) lastA3=0 ; initialize lastA3 for each subject to an

appropriate value

PBDREF_ = -PBINT*EXP(-PBRATE*TIME_) + DEACR*(1-lastA3)

IF (TIME_.NE.0.AND.EVID.NE.1) THEN

lastA3=A(3)

THEN ; special trick is to re-assign lastA3 to itself

lastA3=lastA3

ENDIF

I've not attempted to reproduce the logic of your code example. This is

just to illustrate the principle.

Note that if A(3) is computed with a random variable and if you compute

lastA3 in a conditional block then you need to use a special trick to

save the value. This trick is required because otherwise lastA3 will

have a value of 0 ( the default behaviour for random variables).

Nick

On 23-Oct-15 06:34, Tommy Li wrote:

*> I am currently developing a nonmem model that attempt to correlate
*

*> binary endpoint with binary endpoint from previous time point. This
*

*> requires me to save solution to differential at a time record (for
*

*> example TIME = 1) so that I can use that value (solution at TIME = 1)
*

*> and perform computation at the next TIME record (TIME =2 for example).
*

*> Essentially, I need to A(3)t=1 and A(3)t=2 at TIME=2, where A(3)
*

*> represent integrated solution of the differential equation specified
*

*> in the nonmem model.
*

*>
*

*> In my data, i have current TIME record as well as TIME_, which
*

*> represent previous time value. In addition, I have DV and DV_, which
*

*> represent current and previous observations. I want to calculate the
*

*> effect (PBDREF) at current time as well as effect (PBDREF_) at
*

*> previous time. For PBDREF_, i need value A(3) at previous time
*

*> (A(3)Previous).
*

*>
*

*> example data structure:
*

*> ID,DV,DV_,TIME,TIME_
*

*> 1,0,0,.,1,0
*

*> 1,0,0,0,2,1
*

*> 1,0,0,0,4,2
*

*> 1,0,0,0,8,4
*

*> 1,0,0,0,16,8
*

*> 1,0,0,0,24,16
*

*> 1,0,0,0,36,24
*

*>
*

*> I came up with the following code but I am not sure if it will work:
*

*> I have a PK model and an effect compartment described by DADT(3)
*

*>
*

*> $DES
*

*> DADT(1) = -KA * A(1)
*

*> DADT(2) = KA * A(1) - CL/V * A(2)
*

*> CP = A(2)/V
*

*> DADT(3) = KIN * (1 - (CP/(IC50+CP))) - KOUT * A(3)
*

*>
*

*> $ERROR
*

*> "USE SIZES, ONLY: NO
*

*> "REAL (KIND=DPSIZE) :: A3(NO)
*

*> "INTEGER (KING=ISIZE) :: I
*

*>
*

*> ..... ## Theta declarations
*

*>
*

*> "IF (NEWIND.NE.2) THEN
*

*> "I = 0
*

*> "ENDIF
*

*> "IF (TIME_.EQ.0.AND.EVID.NE.1) THEN
*

*> "I = I+1
*

*> "A3(I)=A(3)
*

*> "PBDREF = -PBINT*EXP(-PBRATE*TIME) + DEACR*(1-A(3))
*

*> "PBDREF_ = PBDREF
*

*> "ELSE IF (TIME_.NE.0.AND.EVID.NE.1) THEN
*

*> "I = I+1
*

*> "A3(I) = A(3)
*

*> "PBDREF = -PBINT*EXP(-PBRATE*TIME) + DEACR*(1-A(3))
*

*> "PBDREF_ = -PBINT*EXP(-PBRATE*TIME_) + DEACR*(1-A3(I-1))
*

*> "ENDIF
*

*>
*

*> .....
*

*>
*

*> What I want to do with the code is to save the values of A(3) in an
*

*> array (A3). By saving the values of A(3) in order and using the
*

*> indexing variable I, I would be able to recall previous value of A(3)
*

*> from A3 by doing: A3(I-1). The first conditional statements is to test
*

*> if the current time point is the first record of an individual. In
*

*> that case, the indexing variable I is reset. Second conditional
*

*> statement is to test the case where previous time is 0 and there is no
*

*> observation at time 0. In that case, PBDREF and PBDREF_ will be both
*

*> be current value. In the last conditional statement, PBDREF is
*

*> assigned value based on A(3)'s current value while PBDREF is assigned
*

*> value based on A(3)'s previous value, extracted from the array A3.
*

*>
*

*> What I am not sure is whether the declared variable (A3 and I) will
*

*> stick around, since it appears to me that these two variable is
*

*> redeclared as nonmem move through data record. In that case,
*

*> redeclaring those variable would likely erase the values stored in
*

*> them. I tried to only declaring (A3 and I) when nonmem is at the first
*

*> record of an individual by moving the declaration under the first
*

*> conditional statement. However, fortran doesn't seem to allow that.
*

*> This there a way to declare persistent variables such that my code
*

*> would work as intended?
*

*>
*

*> Thank you
*

*> Tommy Li
*

--

Nick Holford, Professor Clinical Pharmacology

Dept Pharmacology & Clinical Pharmacology, Bldg 503 Room 302A

University of Auckland,85 Park Rd,Private Bag 92019,Auckland,New Zealand

office:+64(9)923-6730 mobile:NZ+64(21)46 23 53

email: n.holford

http://holford.fmhs.auckland.ac.nz/

Holford SD, Allegaert K, Anderson BJ, Kukanich B, Sousa AB, Steinman A, Pypendop, B., Mehvar, R., Giorgi, M., Holford,N.H.G. Parent-metabolite pharmacokinetic models - tests of assumptions and predictions. Journal of Pharmacology & Clinical Toxicology. 2014;2(2):1023-34.

Holford N. Clinical pharmacology = disease progression + drug action. Br J Clin Pharmacol. 2015;79(1):18-27.

Received on Thu Oct 22 2015 - 14:56:30 EDT

Date: Fri, 23 Oct 2015 07:56:30 +1300

Tommy,

When a variable is defined in NM-TRAN it persists to all subsequent

records in the data set.

You could do something like this:

$ERROR

IF (NEWIND.LE.1) lastA3=0 ; initialize lastA3 for each subject to an

appropriate value

PBDREF_ = -PBINT*EXP(-PBRATE*TIME_) + DEACR*(1-lastA3)

IF (TIME_.NE.0.AND.EVID.NE.1) THEN

lastA3=A(3)

THEN ; special trick is to re-assign lastA3 to itself

lastA3=lastA3

ENDIF

I've not attempted to reproduce the logic of your code example. This is

just to illustrate the principle.

Note that if A(3) is computed with a random variable and if you compute

lastA3 in a conditional block then you need to use a special trick to

save the value. This trick is required because otherwise lastA3 will

have a value of 0 ( the default behaviour for random variables).

Nick

On 23-Oct-15 06:34, Tommy Li wrote:

--

Nick Holford, Professor Clinical Pharmacology

Dept Pharmacology & Clinical Pharmacology, Bldg 503 Room 302A

University of Auckland,85 Park Rd,Private Bag 92019,Auckland,New Zealand

office:+64(9)923-6730 mobile:NZ+64(21)46 23 53

email: n.holford

http://holford.fmhs.auckland.ac.nz/

Holford SD, Allegaert K, Anderson BJ, Kukanich B, Sousa AB, Steinman A, Pypendop, B., Mehvar, R., Giorgi, M., Holford,N.H.G. Parent-metabolite pharmacokinetic models - tests of assumptions and predictions. Journal of Pharmacology & Clinical Toxicology. 2014;2(2):1023-34.

Holford N. Clinical pharmacology = disease progression + drug action. Br J Clin Pharmacol. 2015;79(1):18-27.

Received on Thu Oct 22 2015 - 14:56:30 EDT