Saving solution to differential equation from previous time point and carry over to next time point

1 messages 1 people Latest: Oct 22, 2015
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