NONMEM Users Network Archive

Hosted by Cognigen

Re: RE: Implementing a Kalman Filter based optimization in NONMEM

From: Alison Boeckmann <alisonboeckmann>
Date: Wed, 16 Sep 2015 14:28:27 -0700

John and nmusers:

I think something more needs to be said about this topic.
(1) The concept of "state variables ai" exists in PREDPP (along

with $MODEL, $PK, $ERROR).  With a user-written $PRED, there are

no reserved variables other than Y.  The user defines all the

variables explicitly.

(2) The help entry for abbreviated discusses the difference between

random and non-random variables when it comes to retaining their

values.

Consider  two  cases  in which the following statements are =
the only

ones defining TVK and K, respectively:

IF (WT.GT.0) TVK=THETA(1)*WT

If the condition is false, the non-random variable TVK  retains  =
the

value set with the previous data record.

IF (WT.GT.0) K=THETA(1)*WT*EXP(ETA(1))

If the condition is false, the value of the random variable K is set

to zero.

NM-TRAN prints a warning message when it detects such code.   In =
$PK,
$ERROR, and $PRED records, recursion code may be used in  an

explicit manner, so that with:      IF (WT.GT.0) THEN

K=THETA(1)*WT*EXP(ETA(1))

ELSE

K=K

ENDIF   if the condition is false, K retains its value set with
the previous

data record.
-------

Here is an example with a $PRED control stream.

Recursive code is needed to retain a variable (and its eta partials)

from one record to the next.
-------

var.dat

------

1  .

1  .
-------

var.ctl

-------

$PROB  variables in $PRED

; illustrates the difference between non-random and random variables

$INPUT      ID DV

$DATA       var.dat

$PRED

IF (NEWIND.LE.1) THEN

VAR1=THETA(1)  ; a non-random variable

VAR2=THETA(2)*EXP(ETA(2)) ; a non-recursive random variable.

ENDIF

IF (NEWIND.LE.1) THEN

VAR3=THETA(3)*EXP(ETA(3)) ; a random variable that is defined
recursively

ELSE

VAR3=VAR3

ENDIF

Y=VAR1+VAR2+VAR3+EPS(1) $THETA  1 2 3

$OMEGA  1 2 3

$SIGMA  1

$TABLE VAR1 VAR2 VAR3 PRED G21 G31 NOAPPEND NOPRINT FILE=var.tbl
------

var.tbl

-------

VAR1        VAR2        VAR3  =
      PRED        G21     =
  G31

1.0000E+00  2.0000E+00  3.0000E+00  6.0000E+00  2.0000E=
+00  3.0000E+00

1.0000E+00  0.0000E+00  3.0000E+00  4.0000E+00  0.0000E=
+00  3.0000E+00

------------
Note that all three are set with the first record.

VAR2 is 0 with subsequent records.

VAR1 (non-random) and VAR3 (random, defined recursively)

retain their values (and eta partials) with subsequent records.

(G21=partial of F w.r.t. eta(2))

(G31=partial of F w.r.t. eta(3)) I hope this makes the situation
more clear.

On Mon, Sep 14, 2015, at 08:36 AM, John Warner wrote:
> Thanks Again Erik

> I think your solution solves the problem.  I just did a quick
> experiment and, at least in the simple case that I tried, pred-defined
> variables do seem to be persistent between calls. So I am not even
> sure that saving the state variables to ai’s is necessary as long=
 as I
> do all my work in user defined code  as opposed to subroutine calls.

>

> So all of this may have been a tempest in a tea pot.

>

> Nonetheless your advice was right on and I thank you for it.

>

> Also thanks to all Kevin and Jason for their helpful comments.

> Best

> John

>

> John H. Warner, PhD, MBA

> Director, Biostatistics

> CHDI Management / CHDI Foundation

> 155 Village Boulevard, Suite 200

> Princeton, NJ, 08540

> (609) 945-9644: office

> (609) 751-7345: cell

> (609) 452-2160: fax

> john.warner

>

> From: E.Olofsen
> September 14, 2015 11:21 AM To: John Warner; nmusers
> Subject: RE: Implementing a Kalman Filter based optimization in NONMEM

>

> John,
>
>
My understanding is that the variables to be used recursively should be
referenced, so the simplest form is Ai = Ai. (Note that if ETAs are
involved, also the derivatives of the Ai with respect to the ETAs need
to be tracked, but NM-TRAN does this for you).
>
>
Best regards,
>
>
Erik

> From: John Warner [John.Warner
> September 14, 2015 4:38 PM To: Olofsen, E. (ANST);
> nmusers
> based optimization in NONMEM

> Thanks again Erik

> I think my code would work with the Ai’s alone provided that they
> persist unchanged between calls to $pred.  Do they?

>

> I guess the general question for me is when do user-defined variables
> persist unchanged between calls to $pred?  If the answer is =
always”
> they I am in good shape.

> Best

> John

>

> John H. Warner, PhD, MBA

> Director, Biostatistics

> CHDI Management / CHDI Foundation

> 155 Village Boulevard, Suite 200

> Princeton, NJ, 08540

> (609) 945-9644: office

> (609) 751-7345: cell

> (609) 452-2160: fax

> john.warner

>

> From: E.Olofsen
> September 14, 2015 10:31 AM To: John Warner; nmusers
> Subject: RE: Implementing a Kalman Filter based optimization in NONMEM

>

> John,
>
>
Would your Kalman filter implementation work with just a $PRED, so
without a $MODEL? While the A(i) are the amounts in compartments defined
in $MODEL, the Ai are user-defined variables.
>
>
Best regards,
>
>
Erik

> From: John Warner [John.Warner
> September 14, 2015 4:09 PM To: Olofsen, E. (ANST);
> nmusers
> based optimization in NONMEM

> Thanks Eric

> Yours seems like a very straight-forward and complete solution.
> However, if I am not mistaken, the Ai variables are created by $model
> and I am not sure that $model can be used by a user supplied $pred.
> If it can, there remains the problem of calling the model subroutine.
> I assume that this would be done with verbatim code but I am not sure
> where to put such a call in my control stream.  The documentation
> (html help files) states that $model is called only once by the PREDPP
> subroutines that use it.  Perhaps I could put such a call in the
> $input or $pk records?  $PK would seem more logical but it is not
> clear that this record is available outside of predPP.

>

> I am very interested to hear any additional responses to this.

>

> Thanks again.

>

> John

> John H. Warner, PhD, MBA

> Director, Biostatistics

> CHDI Management / CHDI Foundation

> 155 Village Boulevard, Suite 200

> Princeton, NJ, 08540

> (609) 945-9644: office

> (609) 751-7345: cell

> (609) 452-2160: fax

> john.warner

>

> From: E.Olofsen
> September 14, 2015 4:40 AM To: John Warner; nmusers
> Subject: RE: Implementing a Kalman Filter based optimization in NONMEM

>

> Dear John,
>
>
In the code by Tornoe et al., state variables A(i) are stored in the Ai
variables, and retrieved by statements Ai = Ai. Such recursive code is
described in NONMEM's help on abbreviated code. Although the A(i) are
associated with differential equations, you could perhaps still use such
recursive statements, indicating that you want to store and retrieve
information?
>
>
Best regards,
>
>
Erik

> From: owner-nmusers
> behalf of John Warner [John.Warner
> September 13, 2015 11:24 PM To: nonmem usersgroup Subject: [NMusers]
> Implementing a Kalman Filter based optimization in NONMEM

> Dear NONMEM users

> I am attempting to implement a Kalman Filter based optimization in
> NONMEM using $PRED directly.  The method I am attempting to implement
> is similar in spirit to that presented in Tornoe et. al. (2005) (and
> the NONMEM 7.3 manual)  except that I have no need for a differential
> equations solver.  In effect I can solve the differential equations
> analytically but I still need to estimate a random walk error term.
> Adapting the procedure of Tornoe et. al. 2005 seems straight-forward
> except that, it seems to me, I need to find a way to store the state
> vector and associated partial derivatives at the end of a call to
> $PRED and to retrieve them at the beginning of the next call for the
> same subject.  I assume that something like this must be done by
> ADVAN6 when differential equations are solved.

>

> I would be very grateful for any advice on this.

>

> Best

> John

>

>

> Tornoe et. al.   Stochastic Differential Equations in NONMEM=
:
> Implementation, Application,  and Comparison with Ordinary
> Differential Equations  Pharmaceutical Research, Vol. 22, No. 8,
> August 2005 2005)

>

>

>

> John H. Warner, PhD, MBA

> Director, Biostatistics

> CHDI Management / CHDI Foundation

> 155 Village Boulevard, Suite 200

> Princeton, NJ, 08540

> (609) 945-9644: office

> (609) 751-7345: cell

> (609) 452-2160: fax

> john.warner

>
--
  Alison Boeckmann
  alisonboeckmann


Received on Wed Sep 16 2015 - 17:28:27 EDT

The NONMEM Users Network is maintained by ICON plc. Requests to subscribe to the network should be sent to: nmusers-request@iconplc.com.

Once subscribed, you may contribute to the discussion by emailing: nmusers@globomaxnm.com.