From: "Anthe Zandvliet" Apaza@SLZ.NL
Subject: [NMusers] calculation of time-to-nadir
Date: Thu, July 29, 2004 8:46 am

Dear NM Users,

I would like to calculate the time-to-nadir for a continuous variable for individual
patients (time at which IPRED is minimal). Does anyone know if this is possible with
nonmem and which code should be used for this purpose?

I have tried the following code, but this didn't work, because:
- in the $PK block DADT(1) and T are not recognized
- in the $DES block DOWHILE statements are not allowed
- in the $ERROR block T is not recognized (nor is DADT(1), but this can be redefined)

IF(ICALL.EQ.4) THEN
DOWHILE(DADT(1).EQ.0)
CALL SIMETA(ETA)
TMIN=T*EXP(ETA(1))
ENDDO
ENDIF

$OMEGA
0 FIX

In the archive of the usersnet, I have found the following statement by Lewis
Sheiner about calculation of Cmax, which made me think that it may not be possible
at all to calculate the time-to nadir. "Some very simple models, such as the 1
compartment elimination with first order absorption, can be solved explicitly for
Cmax as a function of whatever parameterization you are using. In such a case it is
simple to reparameterize with Cmax as a parameter and one of the previous
parameters, e.g., V, solved in terms of it and the other parameters. Where there is
no explicit solution for Cmax (most cases), it will be harder.There is no problem
finding Cmax: just simulate your model on a fine time grid and "read off" the
value."
File Name:99oct241996.html
Subject: Deriving Cmax and the corresponding variability
Posting: October 24, 1996 

Thank you in advance for your suggestions!

Anthe
_______________________________________________________

From: Nick Holford    
Subject: RE:[NMusers] calculation of time-to-nadir
Date: Thu, July 29, 2004 11:31 pm 

Anthe,

You are not clear about the context in which you want to calculate the
'time-to-nadir'. 

If you want to calculate the time of the minimum prediction based on a NONMEM model
and parameters then you can just follow the advice that Lewis gave previously 'just
simulate your model on a fine time grid and "read off" the value.'.

However, if you are trying to use NONMEM to estimate the 'time-to-nadir' as a model
parameter then this may only be possible for very simple cases (as Lewis pointed out
for Cmax).

If you could give us some idea of why you are trying to do this then perhaps some
suggestions could be made.

Nick
--
Nick Holford, Dept Pharmacology & Clinical Pharmacology
University of Auckland, 85 Park Rd, Private Bag 92019, Auckland, New Zealand
email:n.holford@auckland.ac.nz tel:+64(9)373-7599x86730 fax:373-7556
http://www.health.auckland.ac.nz/pharmacology/staff/nholford/
_______________________________________________________

From: "Anthe Zandvliet" Apaza@SLZ.NL
Subject: RE:[NMusers] calculation of time-to-nadir
Date: Fri, July 30, 2004 3:32 am 

Nick,

I would like to calculate the time-to-nadir for each individual as a secondary
parameter. The model is a semiphysiological PK-PD model, comprising 9 compartments.
I would like to calculate the exact time point where the derivative of the amount in
compartment number 9 (so unfortunately this is not one of the few very simple
cases...) with respect to time is 0. In my model, this time point corresponds to the
time-to nadir.

I could add some dummy time points around the time-to-nadir for each individual and
read off the value, but I prefer to calculate the exact value using NONMEM. 

I hope this clarifies my objectives.

Anthe
_______________________________________________________

From: Nick Holford n.holford@auckland.ac.nz
Subject: RE:[NMusers] calculation of time-to-nadir
Date: Fri, July 30, 2004 5:32 am   

Anthe,

It seems that you understand how to apply a brute force method of finding the
individual minimum value to any reasonable degree of precision. You don't give any
reason for why you want an 'exact' value. Personally I would use brute force and get
on to the next problem. But perhaps somebody knows some elegant mathematical trick
to help you.

Nick
--
Nick Holford, Dept Pharmacology & Clinical Pharmacology
University of Auckland, 85 Park Rd, Private Bag 92019, Auckland, New Zealand
email:n.holford@auckland.ac.nz tel:+64(9)373-7599x86730 fax:373-7556
http://www.health.auckland.ac.nz/pharmacology/staff/nholford/
_______________________________________________________

From: "Anthe Zandvliet" Apaza@SLZ.NL
Subject: RE:[NMusers] calculation of time-to-nadir
Date: Fri, July 30, 2004 5:52 am

Nick,

Thank you for your help. You are probably right, that I should not bother any longer
and use brute force. One of the reasons why I would prefer a trick to have nonmem
calculate the value is, that I have about 300 individuals... Furthermore, a code for
this problem would also allow calculation of Tmax or Cmax values in PK models of
orally administered compounds, which may be helpful for me and others in the future.

Anthe
_______________________________________________________

From: "Olofsen, E. (ANST)" 
Subject: RE:[NMusers] calculation of time-to-nadir
Date: Fri, July 30, 2004 6:52 am
 
Dear Anthe,

Perhaps the idea implemented in the control file below can be of help.
It considers the case where the analytical solution exists: TMAXE is
the time where the concentration in compartment 2 attains a maximum.
The derivative will never be exactly zero, but it will become
negative. The higher the value of TOL, the more often $DES will be
called at different time values, and the more accurate the estimate,
available as A(4) (at the end of TIME), will be. So the trick is to
integrate 1 until Tmax. Cmax is also available as A(3).

Best regards,

Erik Olofsen


$PROBLEM CMAX
$INPUT TIME AMT RATE MDV X1 X2 DV
$DATA cmax.d
$SUBROUTINES ADVAN6 TOL=6
$MODEL
 COMP = CENTRAL
 COMP = EFFECT
 COMP = CMAX
 COMP = TMAX

$PK
 K = THETA(1)
 KE0 = THETA(2)

 TMAXE = (LOG(K)-LOG(KE0))/(K-KE0)

$DES
 DADT(1) = -K*A(1)
 D2 = KE0*(A(1)-A(2))
 DADT(2) = D2
 IF (D2.GT.0) THEN
   DADT(3) = D2
   DADT(4) = 1
 ELSE
   DADT(3) = 0
   DADT(4) = 0
 ENDIF

$ERROR
 Y1 = A(1)
 Y2 = A(2)
 Y3 = A(3)
 Y4 = A(4)

 Y = Y2*(1+ERR(1))

$THETA
 0.01
 0.03

$OMEGA
 0.001

$EST

$TABLE FILE=stream NOPRINT NOHEADER TIME AMT RATE MDV Y1 Y2 Y3 Y4 TMAXE

A data file to test this with:

  0.0000E+00  1.0000E+00  0.0000E+00  1.0000E+00  1.0000E+00  0.0000E+00  0.0000E+00
 0.0000E+00  0.0000E+00  0.0000E+00
  0.0000E+00  0.0000E+00  0.0000E+00  1.0000E+00  1.0000E+00  0.0000E+00  0.0000E+00
 0.0000E+00  0.0000E+00  0.0000E+00
  1.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  9.0484E-01  2.4603E-01  2.3131E-01
 2.4603E-01 -1.4716E-02  0.0000E+00
  2.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  8.1873E-01  4.0488E-01  4.1299E-01
 4.0488E-01  8.1097E-03  0.0000E+00
  3.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  7.4082E-01  5.0137E-01  4.9237E-01
 5.0137E-01 -9.0010E-03  0.0000E+00
  4.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  6.7032E-01  5.5369E-01  5.3405E-01
 5.5369E-01 -1.9643E-02  0.0000E+00
  5.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  6.0653E-01  5.7510E-01  5.8321E-01
 5.7510E-01  8.1137E-03  0.0000E+00
  6.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  5.4881E-01  5.7527E-01  5.8127E-01
 5.7527E-01  6.0053E-03  0.0000E+00
  7.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  4.9659E-01  5.6119E-01  5.4722E-01
 5.6119E-01 -1.3975E-02  0.0000E+00
  8.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  4.4933E-01  5.3792E-01  5.4652E-01
 5.3792E-01  8.6028E-03  0.0000E+00
  9.0000E+01  0.0000E+00  0.0000E+00  0.0000E+00  4.0657E-01  5.0905E-01  4.9859E-01
 5.0905E-01 -1.0452E-02  0.0000E+00
  1.0000E+02  0.0000E+00  0.0000E+00  0.0000E+00  3.6788E-01  4.7714E-01  4.9331E-01
 4.7714E-01  1.6172E-02  0.0000E+00
_______________________________________________________

From:"Anthe Zandvliet" Apaza@SLZ.NL
Subject: RE:[NMusers] calculation of time-to-nadir
Date: Fri, July 30, 2004 7:48 am 

Thank you, Eric. This works!
_______________________________________________________

From: Nick Holford    
Subject: RE:[NMusers] calculation of time-to-nadir
Date: Tue, August 3, 2004 3:49 am

Erik,

Thanks very much for suggesting this solution to finding the time of maximum (or
minimum) of a function.

I thought it might be of interest to show the data, code and output for the kind of
problem that Anthe asked about originally i.e. the time to nadir. 

This example implements a linear pharmacodynamic effect inhibiting the input to a
turnover model so that the solution to the time of nadir is known analytically (as
in your Cmax example). It uses the $SIMULATION option to simulate data from a
template data file (nadir.dat). The output table file shows that your clever brute
force method agrees quite closely with the analytical solution for the time of
nadir.

Note that the accuracy of the solution depends on the spacing of the times in the
data set. When the data has only two times, 0 and 100 (time increment 100), then the
predicted time of nadir is 54.884 compared with the analytical value of 54.931.
Interestingly if the time increment is  1 unit then the brute force solution is
somewhat worse (54.965) than with a time increment of 10 (54.933; see below).

By trial and error I looked for the smallest value of TOL that would give a brute
force prediction that is identical (54.931) to the analytical solution.
Paradoxically I found it needed TOL=7 with a time increment of 100, TOL=8 with a
time increment of 10 and TOL=9 with a time increment of 1.

Nick

$PROBLEM Nadir
$INPUT TIME AMT CMT DV
$DATA nadir.dat
$SUBROUTINES ADVAN6 TOL=6
$MODEL
 COMP = CENTRAL
 COMP = EFFECT
 COMP = NADIR
 COMP = TMIN

$PK
 K = THETA(1)
 KOUT = THETA(2)
 C0  = THETA(3)
 SLOPE = THETA(4)
 KIN=KOUT*C0
 F2=C0

$DES
 DCP=A(1)
 DCE=A(2)
 DADT(1) = -K*DCP
 D2 = KIN*(1-SLOPE*DCP) - DCE*KOUT
 DADT(2) = D2 
 IF (D2.LT.0) THEN
   DADT(3) = D2 ; Y(3) is conc 'lost' from effect site
   DADT(4) = 1  ; Y(4) is elapsed time up to nadir
 ELSE
   DADT(3) = 0
   DADT(4) = 0
 ENDIF

$ERROR
 CP    = A(1)
 CE    = A(2)
 NADIR = C0+A(3)
 TNAD  = A(4)
;Theoretical time of nadir for limear PD model
 TMIN = (LOG(K)-LOG(KOUT))/(K-KOUT)

 Y = CE*(1+ERR(1))

$THETA
 0.01 ; k
 0.03 ; keq
 100  ; C0
 0.01 ; Slope

$OMEGA
 0.001 ; cverr

$SIM (123456) SUBPROBLEMS=1 ONLYSIM
$TABLE TIME CP CE NADIR TNAD TMIN
NOPRINT ONEHEADER NOAPPEND FILE=nadir.fit

nadir.dat
#TIME        AMT        CMT        DV
0        1        2        .
0        100        1        .
10        .        .        .
20        .        .        .
30        .        .        .
40        .        .        .
50        .        .        .
60        .        .        .
70        .        .        .
80        .        .        .
90        .        .        .
100        .        .        .

nadir.fit
TIME        CP        CE        NADI        TNAD        TMIN
0        0        100        100        0        54.931
0        100        100        100        0        54.931
10        90.484        75.397        75.397        10        54.931
20        81.873        59.512        59.512        20        54.931
30        74.082        49.863        49.863        30        54.931
40        67.032        44.631        44.631        40        54.931
50        60.653        42.49        42.49        50        54.931
60        54.881        42.473        42.265        54.933        54.931
70        49.659        43.881        42.265        54.933        54.931
80        44.933        46.208        42.265        54.933        54.931
90        40.657        49.095        42.265        54.933        54.931
100        36.788        52.286        42.265        54.933        54.931


--
Nick Holford, Dept Pharmacology & Clinical Pharmacology
University of Auckland, 85 Park Rd, Private Bag 92019, Auckland, New Zealand
email:n.holford@auckland.ac.nz tel:+64(9)373-7599x86730 fax:373-7556
http://www.health.auckland.ac.nz/pharmacology/staff/nholford/
_______________________________________________________

From: "Olofsen, E. (ANST)" E.Olofsen@lumc.nl
Subject: RE:[NMusers] calculation of time-to-nadir
Date: Tue, August 3, 2004 9:15 am

Nick,

I've adapted your example control file (see below) to simulate a set
of cases (9999) with different values of K, to study the performance
of TNAD, which is the estimator of TMIN. Across the set of cases,
there seems to be no significant dependence on TINC, while TOL does
increase precision with an order of magnitude. It must be noted
however, that TMIN is considerably less well estimated than NADIR.

Erik

TINC        mean(TNAD-TMIN)        SD(TNAD-TMIN)

100        0.00897                0.0279                TOL=6
10        0.00707                0.0267
1        0.00728                0.0248

100        0.000716        0.00268                TOL=7
10        0.000760        0.00263
1        0.000728        0.00274

100        6.43E-05        0.000261        TOL=8
10        8.26E-05        0.000264
1        7.29E-05        0.000259

100        7.74E-06        2.65E-05        TOL=9
10        8.05E-06        2.66E-05
1        8.05E-06        2.70E-05

$PROBLEM Nadir
$INPUT ID TIME AMT CMT DV
$DATA nadir.d
$SUBROUTINES ADVAN6 TOL=6
$MODEL
 COMP = CENTRAL
 COMP = EFFECT
 COMP = NADIR
 COMP = TMIN

$PK
 K = THETA(1)*EXP(ETA(1))
 KOUT = THETA(2)
 C0  = THETA(3)
 SLOPE = THETA(4)
 KIN=KOUT*C0
 F2=C0

$DES
 DCP=A(1)
 DCE=A(2)
 DADT(1) = -K*DCP
 D2 = KIN*(1-SLOPE*DCP) - DCE*KOUT
 DADT(2) = D2
 IF (D2.LT.0) THEN
   DADT(3) = D2 ; Y(3) is conc 'lost' from effect site
   DADT(4) = 1  ; Y(4) is elapsed time up to nadir
 ELSE
   DADT(3) = 0
   DADT(4) = 0
 ENDIF

$ERROR
 CP    = A(1)
 CE    = A(2)
 NADIR = C0+A(3)
 TNAD  = A(4)

;Theoretical time of nadir for limear PD model
 TMIN = (LOG(K)-LOG(KOUT))/(K-KOUT)

;Analytical solutions of CP and CE
 CPA = 100*EXP(-K*TIME)
 DM1 = KIN*SLOPE*100
 DM2 = KIN/KOUT
 DM3 = DM1/(K-KOUT)
 CEA = (F2-DM2-DM3)*EXP(-KOUT*TIME)+DM3*EXP(-K*TIME)+DM2

; Analytical minimum of CE
 CEMIN = (F2-DM2-DM3)*EXP(-KOUT*TMIN)+DM3*EXP(-K*TMIN)+DM2

 IF (TIME.EQ.0) THEN
   ERRA = 0
   ERRB = 0
   ERRM = 0
   ERRT = 0
 ELSE
   ERRA = CP-CPA
   ERRE = CE-CEA
   ERRM = NADIR-CEMIN
   ERRT = TNAD-TMIN
 ENDIF

 Y = CE*(1+ERR(1))

$THETA
 0.01 ; k
 0.03 ; keq
 100  ; C0
 0.01 ; Slope

$OMEGA
 0.01

$SIGMA
 0 FIX
 0.001 ; cverr

$SIM (123456) SUBPROBLEMS=1 ONLYSIM
$TABLE ID TIME CP CPA ERRA CE CEA ERRE NADIR CEMIN ERRM TNAD TMIN ERRT
NOPRINT NOHEADER FILE=stream

Awk (-v NID=nid -v TINC=tinc) file to generate a data file:

BEGIN {
        print "#ID    TIME   AMT     CMT     DV"
        for (id=1; id<=NID; id++) {
          print id, "0       1       2       ."
          print id, "0       100     1       ."
          for (t=0; t<=100; t+=TINC) print id, t, ". . .";
        }
}

 

_______________________________________________________