From: Sebastien Bihorel <*Sebastien.Bihorel*>

Date: Tue, 29 Nov 2011 16:22:16 -0500

Hi Rob,

I realized that my implementation of your suggestion did not take into

account all possible situations (which depend on how DUR relates to the

sign of the sine function and its first derivative over 24h). However,

the integration is still incomplete even with the appropriate

corrections (see attachment; checked in Berkeley Madonna over a large

range of SHIFT and DUR values).

Sebastien

Sebastien Bihorel wrote:

*> Thanks Rob for your reply.
*

*>
*

*> I have tried something in the line of what you suggested (see
*

*> circadian4.ctl in attachment) but the integration is still not
*

*> complete in some conditions (SHIFT, DUR values and dataset records).
*

*> However, the same equations plugged in Berkeley Madonna work fine, so
*

*> I tend to think that the model somehow needs to be tweaked in such a
*

*> way that the NONMEM integration routine considers the switch times
*

*> correctly.
*

*>
*

*> By the way, I have tried to run these dummy models with ADVAN6, 8, and
*

*> 13. All ADVAN have produced incomplete (but different) integration in
*

*> one condition or another.
*

*>
*

*> Sebastien
*

*>
*

*> PS: I have also re-attached the previous control streams that
*

*> contained minor typos in the assignment of the MPAST1 and MPAST2
*

*> output variables.
*

*>
*

*> R.ter.Heine *

*>> Hi Sebastien,
*

*>>
*

*>> Have you tried including a cosine function with a flag that is turned on
*

*>> or off when it is above a certain value or a flag that changes value
*

*>> when the first derivative changes from negative to positive or vice
*

*>> versa?
*

*>>
*

*>> Cheers,
*

*>>
*

*>> Rob
*

*>>
*

*>> ----------
*

*>> Rob ter Heine, PhD, PharmD
*

*>> Hospital pharmacy resident
*

*>> Meander Medical Center, Amersfoort, The Netherlands
*

*>> T: +31-33-8502335
*

*>> E: r.ter.heine *

*>>
*

*>> -----Oorspronkelijk bericht-----
*

*>> Van: owner-nmusers *

*>> Namens Sebastien Bihorel
*

*>> Verzonden: dinsdag 29 november 2011 17:05
*

*>> Aan: nmusers
*

*>> Onderwerp: [NMusers] How to implement a circadian reset of a step
*

*>> function in $DES using MTIME variables
*

*>>
*

*>> Dear NONMEM users,
*

*>>
*

*>> A few month ago, a post by Li Li ("Question regarding Calculation
*

*>> Process in $DES BLOCK") generated some interesting discussions about how
*

*>> to implement abrupt changes in a model parameter in $DES. The original
*

*>> problem proposed by Li Li was to implement a step function that turns on
*

*>> and off between two time points reset on a 24h clock time basis. Alison
*

*>> Boeckmann strongly recommended NOT to use IF statements or create a 24-h
*

*>> time variable using the INT function in $DES. Instead she suggested to
*

*>> use model time events (MTIME's). My question relates to the
*

*>> implementation of such a solution.
*

*>>
*

*>> The attachments to this post are simulation control stream illustrating
*

*>> some attempts to use MTIME's to switch on and off a FLAG variable every
*

*>> 24h. On a 24h clock time, the flag switches from 0 to 1 at time SHIFT
*

*>> (the so-called shift from time 0, bound between 0 and 24) and turns back
*

*>> to 0 at time SHIFT+DUR (DUR being the duration of the step function,
*

*>> bound between 0 and 24). Two MTIME's variables define the "switch"
*

*>> times, and the flag is set as follows: FLAG=MPAST(1)-MPAST(2). This
*

*>> would work nice and well if I did not need to reset the MTIME every 24h.
*

*>>
*

*>> In the attached model, MTIME's depend on the TX variable which is
*

*>> incremented by 24 based upon a comparison of the TIME variable with
*

*>> various equations of TX and DUR. As documented in the manual, the MTDIFF
*

*>> reserved variable is set to 1 to reflect the changes in MTIME variables.
*

*>>
*

*>> Furthermore, $DES defines 3 states to monitor MPAST(1), MPAST(2) and
*

*>> FLAG. The integration of the third state over time is expected to
*

*>> increase by DUR every 24h. But, this is not always the case depending on
*

*>> the dataset records, the values of SHIFT, DUR, and the methods of MTIME
*

*>> update:
*

*>>
*

*>> circadian1.ctl: MTIME's are coded to be reset when MTIME(1)+24 is
*

*>> reached. Results: MTIME's are never reset if SHIFT+DUR<24 and,
*

*>> apparently, if there is no dataset record between MTIME(2) and
*

*>> 0.5*(MTIME(2) + MTIME(1)+24)
*

*>> circadian2.ctl: MTIME's are coded to be reset when MTIME(1)+DUR is
*

*>> reached. Results: MTIME's are never properly set if SHIFT+DUR<24
*

*>> circadian3.ctl: a third MTIME is used and MTIME's are coded to be reset
*

*>> at the midpoint between MTIME(2) and MTIME(1)+24 (ie in between the
*

*>> steps). Results: if SHIFT+DUR<24, MTIME's are never properly reset if
*

*>> there is no dataset record between MTIME(2) and the midpoint.
*

*>>
*

*>> For all methods, the integration is "wrong" when there is a gap of more
*

*>> than 24h between dataset records (try running any models with exclusion
*

*>> of the EVID=2 records). Additionally, because SHIFT and DUR will be
*

*>> estimated for each subject in my real model, adding EVID=2 records in
*

*>> the dataset does not seem to be a reasonable option to apply the
*

*>> "circadian3.ctl" method.
*

*>>
*

*>> Basically, I am stuck and would greatly appreciate any code or dataset
*

*>> suggestions to fix this integration problem. Obviously, any alternative
*

*>> approach to implement this circadian switch function would also be
*

*>> welcome.
*

*>>
*

*>> Thank you for your time
*

*>>
*

*>> Sebastien
*

*>>
*

*>>
*

*>> ***************************DISCLAIMER****************************
*

*>> De informatie in dit e-mail bericht is uitsluitend bestemd
*

*>> voor de geadresseerde. Verstrekking aan en gebruik door
*

*>> anderen is niet toegestaan. Door de elektronische verzending
*

*>> van het bericht kunnen er geen rechten worden ontleend aan de
*

*>> informatie.
*

*>>
*

$PROBLEM circadian5

;; -----------------------------------------------------------------------------

;; PURPOSE: Circadian rhythm - using sin for flag

;; -----------------------------------------------------------------------------

$INPUT ID PID TIME AMT CMT EVID DV MDV

$DATA circadian2.csv IGNORE=

$THETA

1

1

$OMEGA

0 FIX

$SIGMA

0.1

$SUBROUTINE ADVAN13 TOL=9

$MODEL NCOMP=3

COMP=(FLG1)

COMP=(FLG2)

COMP=(FLAG)

$PK

SHIFT=THETA(1)*EXP(ETA(1))

DUR=THETA(2)

IF (PID.GT.0.5) THEN

SHIFT = 4.2

DUR = 7.1

END IF

IF (PID.GT.1.5) THEN

SHIFT = 3.3

DUR = 17.6

END IF

IF (PID.GT.2.5) THEN

SHIFT = 22.7

DUR = 8.3

END IF

IF (PID.GT.3.5) THEN

SHIFT = 14.5

DUR = 17.9

END IF

;Circadian rhythm

PI=3.14159263

IF ((SHIFT+DUR).GT.24) THEN

OFFSET = -24

ELSE

OFFSET = 0

END IF

TMPS = SIN(2*PI*(OFFSET+DUR)/24)

F1 = 0

$DES

TMP = SIN(2*PI*(T-SHIFT)/24)

DTMPDT = COS(2*PI*(T-SHIFT)/24) ; derivative of TMP1 divided by 2*PI/24

; Condition 1: 0 <= DUR < 6

FLGC1 = 0

IF (TMP.GE.0.AND.TMP.LE.TMPS.AND.DTMPDT.GE.0) FLGC1 = 1

; Condition 2: 6 <= Dur < 18

FLGC21 = 0

IF (TMP.GE.0.AND.DTMPDT.GE.0) FLGC21=1

FLGC22 = 0

IF (TMP.GE.TMPS.AND.DTMPDT.LE.0) FLGC22=1

FLGC2 = 0

IF (FLGC21.GT.0.5.OR.FLGC22.GT.0.5) FLGC2=1

; Condition 2: 18 <= Dur < 24

FLGC3 = 1

IF (TMP.LE.0.AND.TMP.GE.TMPS.AND.DTMPDT.GE.0) FLGC3 = 0

; Flag

FLG = FLGC1

IF (DUR.GE.6) FLG = FLGC2

IF (DUR.GE.18) FLG = FLGC3

DADT(1) = FLGC21

DADT(2) = FLGC22

DADT(3) = FLG

$ERROR

IPRED = A(3)

FLAG1 = A(1)

FLAG2 = A(2)

Y = IPRED*(1+EPS(1))

$SIMULATION(12345) NSUB=1 ONLYSIM

$TABLE ID TIME SHIFT DUR IPRED FLAG1 FLAG2 NOPRINT ONEHEADER FILE=circadian5.tbl

Received on Tue Nov 29 2011 - 16:22:16 EST

Date: Tue, 29 Nov 2011 16:22:16 -0500

Hi Rob,

I realized that my implementation of your suggestion did not take into

account all possible situations (which depend on how DUR relates to the

sign of the sine function and its first derivative over 24h). However,

the integration is still incomplete even with the appropriate

corrections (see attachment; checked in Berkeley Madonna over a large

range of SHIFT and DUR values).

Sebastien

Sebastien Bihorel wrote:

$PROBLEM circadian5

;; -----------------------------------------------------------------------------

;; PURPOSE: Circadian rhythm - using sin for flag

;; -----------------------------------------------------------------------------

$INPUT ID PID TIME AMT CMT EVID DV MDV

$DATA circadian2.csv IGNORE=

$THETA

1

1

$OMEGA

0 FIX

$SIGMA

0.1

$SUBROUTINE ADVAN13 TOL=9

$MODEL NCOMP=3

COMP=(FLG1)

COMP=(FLG2)

COMP=(FLAG)

$PK

SHIFT=THETA(1)*EXP(ETA(1))

DUR=THETA(2)

IF (PID.GT.0.5) THEN

SHIFT = 4.2

DUR = 7.1

END IF

IF (PID.GT.1.5) THEN

SHIFT = 3.3

DUR = 17.6

END IF

IF (PID.GT.2.5) THEN

SHIFT = 22.7

DUR = 8.3

END IF

IF (PID.GT.3.5) THEN

SHIFT = 14.5

DUR = 17.9

END IF

;Circadian rhythm

PI=3.14159263

IF ((SHIFT+DUR).GT.24) THEN

OFFSET = -24

ELSE

OFFSET = 0

END IF

TMPS = SIN(2*PI*(OFFSET+DUR)/24)

F1 = 0

$DES

TMP = SIN(2*PI*(T-SHIFT)/24)

DTMPDT = COS(2*PI*(T-SHIFT)/24) ; derivative of TMP1 divided by 2*PI/24

; Condition 1: 0 <= DUR < 6

FLGC1 = 0

IF (TMP.GE.0.AND.TMP.LE.TMPS.AND.DTMPDT.GE.0) FLGC1 = 1

; Condition 2: 6 <= Dur < 18

FLGC21 = 0

IF (TMP.GE.0.AND.DTMPDT.GE.0) FLGC21=1

FLGC22 = 0

IF (TMP.GE.TMPS.AND.DTMPDT.LE.0) FLGC22=1

FLGC2 = 0

IF (FLGC21.GT.0.5.OR.FLGC22.GT.0.5) FLGC2=1

; Condition 2: 18 <= Dur < 24

FLGC3 = 1

IF (TMP.LE.0.AND.TMP.GE.TMPS.AND.DTMPDT.GE.0) FLGC3 = 0

; Flag

FLG = FLGC1

IF (DUR.GE.6) FLG = FLGC2

IF (DUR.GE.18) FLG = FLGC3

DADT(1) = FLGC21

DADT(2) = FLGC22

DADT(3) = FLG

$ERROR

IPRED = A(3)

FLAG1 = A(1)

FLAG2 = A(2)

Y = IPRED*(1+EPS(1))

$SIMULATION(12345) NSUB=1 ONLYSIM

$TABLE ID TIME SHIFT DUR IPRED FLAG1 FLAG2 NOPRINT ONEHEADER FILE=circadian5.tbl

Received on Tue Nov 29 2011 - 16:22:16 EST