Jump to content


Photo

sequence statement


  • Please log in to reply
13 replies to this topic

#1 Rosa Luo

Rosa Luo

    Member

  • Members
  • PipPip
  • 10 posts

Posted 25 April 2013 - 05:38 AM

I don't quite understand the purpose and how to use sequence{...}. The example in the modeling language guide shown using this statement to set initial value of a compartment. Is it possible to show some other examples? The description in the guide is very general. Thanks!



#2 Ana Henry

Ana Henry

    Advanced Member

  • Val_Members
  • PipPipPip
  • 232 posts

Posted 25 April 2013 - 06:53 PM

Hello,
At Pharsight, we realize that the documentation on this statement needs to be expanded and this will be done in the next release of Phoenix. Below is some information from our developers that might help you understand this better. Thank you for asking the question.

Hope this is helpful,

Ana Henry


In a PML model, the statements are not sequential, they are descriptive of the problem. They do not take action at a point in time. Rather they apply "all the time". So if one says
deriv( Aa = -Aa*Ka ) # Read as "the time derivative of Aa is minus Aa times Ka"
and
deriv ( A1 = Aa*Ka - A1*Ke ) # we call any variable appearing first inside a deriv statement an "integrator" variable, because it will be integrated over time.
the order of those statements does not matter because they are true all the time.
Other statements are also descriptive, such as
dosepoint( Aa ) # declares that Aa will receive doses from a dataset outside the PML model
error( eps = 1 ) # declares that eps is an error variable whose initial standard deviation is 1 and is assumed to be normally distributed
observe( CObs = C * exp(eps) ) # declares that observations of "C" can occur, they are called "CObs", and they have the error model "time exp(eps)"
fixev( tvV ) # declares that tvV (read "typical value of V") is a population-wide fixed effect.
ranef( diag(nV) = c(1) ) # declares that nV (read "eta V") is a random-effect parameter, assumed to be different for each individual, and assumed to be normally distributed
stparm( V = tvV * exp(nV) ) # declares that "V" is a structural parameter, and its value is the typical value tvV times exp(nV) For all these statements, order does not matter, because they not sequential. They are just declaring things.
NOW, what is "C"? Here's the statement that defines C:
C = A1 / V # which says concentration C equals amount in central compartment A1 divided by volume of central compartment V This kind of statement is called an "assignment statement". It is any statement in the PML model of the form lone_variable = some_expression.
Unfortunately, for assignment statements, we can no longer say that order doesn't matter. The reason is we need to guard against stuff like this:
X = Y
Y = X + 1
So in PML code, outside of sequence blocks, relative order of statements does not matter EXCEPT for relative order of assignment statements.

Back to sequence blocks. What good are they?

Initializing state:
In a sequence block, you can say
sequence {
Aa = some_expression
A1 = some_other_expression
}
What does this do? It sets the two state variables Aa and A1 to initial values, because the sequence block starts executing immediately when the subject begins.

Take some action after some time has passed:
For example, if we want to put in an extra dose at three time units after the subject has begun, and then yet another three time units later, we could say:
sequence {
sleep(3)
Aa = Aa + some_dose_amount
sleep(3)
Aa = Aa + some_dose_amount
}
The sequence block starts when the subject starts, but the first thing it does is hit the "sleep(3)" statement, which means "wake up again after three time units".
When the three time units have passed, then it does the next thing, which is to add a dose to Aa. Notice we can only modify an integrator variable like Aa at particular points in time, so we can only do it inside a sequence block.
Then it sleeps for 3 more time units, gives another dose, and does nothing more.

What if there is more than one sequence block? They run on parallel tracks, that's all. Do not depend on the relative order in which they do things. For example, if they both initialize things, don't expect to be able to depend on which one does it first.

Do different things depending on different conditions:
sequence {
sleep(3) # sleep for 3 time units
if (Aa < 2){ # if the amount in compartment Aa is less than 2
Aa = Aa + some_dose_amount # poke an additional dose into compartment Aa
} else { # otherwise
# do something else or nothing
}
}

Do things repeatedly:
sequence {
# this says as long as t is less than 10, sleep three time units and put in a dose
while(t < 10){
sleep(3)
Aa = Aa + some_dose_amount
}
}
or
real(i) # this declares there is a variable named "i" that we can set to different values
sequence {
# this says repeat the sleep+dose cycle ten times
for (i in [1:10]){
sleep(3)
Aa = Aa + some_dose_amount
}
}

The original reason for putting in sequence blocks was so we could handle models like entero-hepatic reflux in a general way.

#3 Teresa Collins

Teresa Collins

    Member

  • Members
  • PipPip
  • 12 posts

Posted 24 October 2014 - 01:21 PM

Hi,

 

I've coded a square wave function which uses sequence with sleep statements,  however I wanted to use the repeat function as you show above.  When I replace with for (i in [1:10]) I get an error message and can't execute:

 

Error line 15: Unrecognized primitive expression
for (i in [1:10]){

 

This is what I have inserted in the sequence statement.

 

double(g)

real(i)
sequence {
for (i in [1:10]){
g=0
sleep(12)
g=1
sleep(12)
}
}

 

I am using 6.4.  I've also had issues with else not being recognised in a while statement so examples of this would also be good.  Project attached.

 

Thanks

Teresa

Attached Files


Edited by Teresa Collins, 24 October 2014 - 01:51 PM.


#4 Simon Davis

Simon Davis

    Advanced Member

  • Administrators
  • 1,318 posts

Posted 24 October 2014 - 01:53 PM

Hi Teresa - project is not attached, perhaps you forgot to click the confirm button.

 

You should be able to edit the post to attach it. or you can email it to me and I will attach it for you.

 

 Simon


Edited by Simon Davis, 24 October 2014 - 01:54 PM.


#5 serge guzy

serge guzy

    Advanced Member

  • Members
  • PipPipPip
  • 485 posts

Posted 27 October 2014 - 05:30 AM

Dear Teresa

May be you should use the while statement. I will look into it and will come back to you.

best

Serge



#6 serge guzy

serge guzy

    Advanced Member

  • Members
  • PipPipPip
  • 485 posts

Posted 27 October 2014 - 06:28 AM

I am trying again to attach the project

Attached Files



#7 Teresa Collins

Teresa Collins

    Member

  • Members
  • PipPip
  • 12 posts

Posted 27 October 2014 - 01:14 PM

Thanks Serge, this works well.

 

For others info:

sequence{i=1
while(i<11){g=0
sleep(12)
g=1
sleep(12)
i=i+1}
}

 

I've realised now that this only works on the IVAR (time) axis and nothing else, and can not be dependent on another variable. I had hoped to use something like this to describe a conc-effect relationship where below a certain concentration the effect was equal to baseline, and above it was equal to baseline plus a conc-dependent effect. But I now see this is not what the code was intended for.

 

Teresa



#8 serge guzy

serge guzy

    Advanced Member

  • Members
  • PipPipPip
  • 485 posts

Posted 27 October 2014 - 01:48 PM

Thanks Serge, this works well.

 

For others info:

sequence{i=1
while(i<11){g=0
sleep(12)
g=1
sleep(12)
i=i+1}
}

 

I've realised now that this only works on the IVAR (time) axis and nothing else, and can not be dependent on another variable. I had hoped to use something like this to describe a conc-effect relationship where below a certain concentration the effect was equal to baseline, and above it was equal to baseline plus a conc-dependent effect. But I now see this is not what the code was intended for.

 

Teresa

Dear Teresa

I think the condition you want to put in your code can be done at the deriv statement level.

Can you share the data or anything that can help writing the relevant code.

Best

Serge



#9 Teresa Collins

Teresa Collins

    Member

  • Members
  • PipPip
  • 12 posts

Posted 27 October 2014 - 01:58 PM

In essence I wanted to use the following effect model directly linked to the concentrations observed

 

When C<=Ct

E=B

When C>Ct

E=B+s*(C-Ct)

 

Where Ct is a positive threshold, B is baseline, C is concentration, E is effect, s is slope or drug effect.

 

Many Thanks

 

Teresa



#10 serge guzy

serge guzy

    Advanced Member

  • Members
  • PipPipPip
  • 485 posts

Posted 27 October 2014 - 02:02 PM

Can you just code that way

# read the observed concentration

covariate©

 

# you must define Ct value, let say

Ct=10

E=(C<=Ct?B:B+s*(C-Ct))

 

something like that.

best

Serge



#11 Teresa Collins

Teresa Collins

    Member

  • Members
  • PipPip
  • 12 posts

Posted 27 October 2014 - 02:09 PM

Thanks, that looks really useful. i will post once I've done it.

 

Teresa



#12 Shu-Pei Wu

Shu-Pei Wu

    Member

  • Members
  • PipPip
  • 26 posts

Posted 04 April 2015 - 02:39 AM

Hi, I have similar question, 

 

I am trying to set different growth rate for tumor depending on the tumor size. 

Below is my script:

test(){
double(Kg)
sequence{
    T = 100
    if (T<1000){
    Kg = 0.1
    } else {Kg = 0.01}
  }
deriv(T = Kg*T)
}
It give me an error message that the program stop running.
How do I do this, and is there similar syntax like if, else, else if in PML?
Thanks,
 
Shu-Pei

Edited by Shu-Pei Wu, 04 April 2015 - 02:41 AM.


#13 smouksassi1

smouksassi1

    Advanced Member

  • Members
  • PipPipPip
  • 231 posts
  • LocationMontreal

Posted 06 April 2015 - 04:03 PM

Last ACOP I did a poster with Serge showing a simeoni model in PML shown below:
This gives you ideas how you can write conditions in your ODE
 

your problem solution is within ODE not within a sequence statement.

# this works try to add a dummy worksheet with ID and TIME and you will get the attached prediction

 

test(){
 
sequence{
    Tumor = 100 # initialize tumor at the value you want
  }
 
deriv(Tumor  = (Tumor <1000 ? Kghigh :Kglow)*Tumor) # conditional ode also you can define Kg 
 
error(TEps = 1)
observe(TObs = Tumor + TEps)
stparm(Kglow = tvKglow )
fixef(tvKglow = c(, 0.01, ))
stparm(Kghigh = tvKghigh )
fixef(tvKghigh = c(,0.1, ))
 
}

 

tumorconditionalode.png

# Poster code is below

 

test(){
cfMicro(A1, Cl / V, first = (Aa = Ka)) ;dosepoint(Aa) ; C = A1 / V
deriv(Ce = ke0*(C-Ce))
deriv(E = (lam0 * E * ((Et-wt)<=0) + lam1*((Et-wt)>0))-k2*Ht*E) # conditional ODE
deriv(E2 = k2*Ht*E - (1/tau)*E2)
deriv(E3 = (1/tau)*(E2-E3))
deriv(E4 = (1/tau)*(E3-E4))
Et = E + E2 + E3 + E4

Ht = Ce
sequence{E =
tumbase} # initialize the tumor compartment which is the sum of four ODE’s

stparm(tumbase = tvtumbase * exp(ntumbase))
fixef(tvtumbase = c(0, 79.0442, ))

secondary(TSC0 = tvlam0/tvk2,TSC1 = tvlam1/(tvtumbase*tvk2)) # important secondary parameter
ranef(diag( nlam1, ntumbase) = c(  1, 1))
covariate(DOSE,TINOC,BASET) }


stparm(tumbase = tvtumbase * exp(ntumbase))
fixef(tvtumbase = c(0, 79.0442, ))



ranef(diag( nlam1, ntumbase) = c(  1, 1))
covariate(DOSE,TINOC,BASET) }



#14 Shu-Pei Wu

Shu-Pei Wu

    Member

  • Members
  • PipPip
  • 26 posts

Posted 29 April 2015 - 02:40 PM

Last ACOP I did a poster with Serge showing a simeoni model in PML shown below:
This gives you ideas how you can write conditions in your ODE
 

your problem solution is within ODE not within a sequence statement.

# this works try to add a dummy worksheet with ID and TIME and you will get the attached prediction

 

test(){
 
sequence{
    Tumor = 100 # initialize tumor at the value you want
  }
 
deriv(Tumor  = (Tumor <1000 ? Kghigh :Kglow)*Tumor) # conditional ode also you can define Kg 
 
error(TEps = 1)
observe(TObs = Tumor + TEps)
stparm(Kglow = tvKglow )
fixef(tvKglow = c(, 0.01, ))
stparm(Kghigh = tvKghigh )
fixef(tvKghigh = c(,0.1, ))
 
}

 

attachicon.giftumorconditionalode.png

# Poster code is below

 

test(){
cfMicro(A1, Cl / V, first = (Aa = Ka)) ;dosepoint(Aa) ; C = A1 / V
deriv(Ce = ke0*(C-Ce))
deriv(E = (lam0 * E * ((Et-wt)<=0) + lam1*((Et-wt)>0))-k2*Ht*E) # conditional ODE
deriv(E2 = k2*Ht*E - (1/tau)*E2)
deriv(E3 = (1/tau)*(E2-E3))
deriv(E4 = (1/tau)*(E3-E4))
Et = E + E2 + E3 + E4

Ht = Ce
sequence{E =
tumbase} # initialize the tumor compartment which is the sum of four ODE’s

stparm(tumbase = tvtumbase * exp(ntumbase))
fixef(tvtumbase = c(0, 79.0442, ))

secondary(TSC0 = tvlam0/tvk2,TSC1 = tvlam1/(tvtumbase*tvk2)) # important secondary parameter
ranef(diag( nlam1, ntumbase) = c(  1, 1))
covariate(DOSE,TINOC,BASET) }


stparm(tumbase = tvtumbase * exp(ntumbase))
fixef(tvtumbase = c(0, 79.0442, ))



ranef(diag( nlam1, ntumbase) = c(  1, 1))
covariate(DOSE,TINOC,BASET) }

Thanks!!

Very helpful!.

BTW, for this line of code

deriv(E = (lam0 * E * ((Et-wt)<=0) + lam1*((Et-wt)>0))-k2*Ht*E) # conditional ODE

 

"(Et-Wt)<=0 "will constrain this term to be less then zero or the opposite?

Thanks,

Shu-Pei


Edited by Shu-Pei Wu, 29 April 2015 - 02:52 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users