if else statement

Hello Everyone,

I am trying to code ifelse statements in Phoenix.

I would like to have a statement like this:

deriv(C= -(CL/V)*C-(CL2/V)*C)

variable= if C<treshold then CL2= 0 else CL2 = 0.1

treshold=100

(this is just an example, the real model is a little bit more complicated)

I hope you can help me!

Best Regards,

Joao

Hi Joao, I think you need to look at Sequence statements, there is quite a bit of discussion in this thread;

http://www.certara.com/forums/topic/421-sequence-statement/?p=2658

with perhaps a switch, something like;

threshold=100 # define threshhold

CL2 =0.1 # define CL2 (maybe a freeze in Param statement woud be better

adding a Switch for CL2

SW which is turned on when C >threshold then CL2= 0 else CL2 = 0.1

double(SW)

sequence{
SW=0;
sleep(C<threshold) # might have to tweak this line, not tried setting it by conc before
SW=1
}

deriv(C= -(CL/V)C-(SWCL2/V)*C)

Simon

Hi Simon,

Thank you for the quick answer! I will look into that. Does this switch also work if I simulate a multiple dosing? The switch would be going on and off, depending if the concentration is above, or below the treshold.

Best,

Joao

D​ear Joa

The code as follows:

threshold=100

variable=(C<threshold?0:0.1)

? means than and : means else

You need to put threshold value before the if statement as here the order counts.

BEST

SERGE

Joao,

The basic structure of an if-then-else statement in PML is as follows:

x==0? option1 : option 2

You can read this as “If x is equal to zero, then option 1, else option 2”. You can also nest if-then statements as follows:

x==0? option1 : x==1? option 2 : option 3

This would read as follows “if x is equal to zero, then option 1, else if x is equal to 1 then option 2, else option 3”.

The exact implementation would be different for your use. These can be embedded into statements like you proposed … although I have never tried it before. Your mileage may vary, but I think that the following would work:

deriv(C= -((CL/V)*C-((C<threshold?0:0.1)/V)*C)

Good luck!

Thank you Nathan and Serge.

For the above code, this serves the purpose of mixture models in NONMEM.

Additionally, when using the non-parametric function in NLME, it would provide two tv values and their associated eta, correct? Thank you very much!

This worked perfectly! Thank you very much everyone.

Best,
Joao