Jump to content


Photo

Modelling with IF()

modelling ifelse

  • Please log in to reply
13 replies to this topic

#1 littlepetinga

littlepetinga

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationPortugal

Posted 01 August 2022 - 10:54 PM

Hello everyone,

 

I am using a very simple custom model to fit some dissolution data.

I plan to fit the data to two different equations:

(1) when time<3, Fdiss=kd*(Time^n)

(2) when time>=3, Fdiss=A^(Time)

 

I am using the following PML model:

test(){
covariate(Time)

sequence{
if (Time<3){
Fdiss=kd*(Time^n)
} else {
    Fdiss=A^(Time)
}
}

error(FdissEps = 1)
observe(FdissObs(Time) = Fdiss+ FdissEps)

fixef(kd = c(, 1, ))
fixef(n = c(, 1, ))
fixef(A = c(, 1, ))
}

However, the following warning message appears: 'Variable 'Fdiss' undefined'

 

Can anyone help me?

 

Many thanks in advance

 

Best regards

Sara



#2 cradhakr

cradhakr

    Advanced Member

  • Administrators
  • 78 posts

Posted 01 August 2022 - 11:53 PM

Hi Sara,

 

Are you trying to fit any specific dissolution model? like hill or Weibull?

 

 

Thanks

Mouli



#3 littlepetinga

littlepetinga

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationPortugal

Posted 02 August 2022 - 07:36 AM

Hi Mouli

 

Thank you for your reply.

 

At the time, I am not trying a specific dissolution model. I tested several, but they were not a good fit for the data.

 

I am trying to fit the data to two different equations depending on time. 

 

Thank you

Sara



#4 bwendt@certara.com

bwendt@certara.com

    Advanced Member

  • Administrators
  • 282 posts

Posted 02 August 2022 - 08:56 AM

Hi Sara,

 

you should not use sequence-loop for these conditional statements. Please use stparm statement:

 

test(){
covariate(Time)
 
stparm(Fdiss = Time<3? kd*(Time^n): A^(Time))
 
error(FdissEps = 1)
observe(FdissObs(Time) = Fdiss + FdissEps)
 
fixef(kd = c(, 1, ))
fixef(n = c(, 1, ))
fixef(A = c(, 1, ))
}
 
Best regards,
Bernd


#5 littlepetinga

littlepetinga

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationPortugal

Posted 02 August 2022 - 10:12 AM

Hi Bernd,

 

Thank you very much!

 

I tried as you said, but a new error message appeared after running:

Initial parameter values result in -LL = NaN
Restart from new values
Error: Model Exception: Fortran Exception
NlmeErrorExit: close files and exit(0)
 
Model execution failed.
 
I tried different initial estimates, but the error message persisted. 
 
Do I need an NLME license to run this code?
 
Thank you once again
 
Best regards
Sara


#6 bwendt@certara.com

bwendt@certara.com

    Advanced Member

  • Administrators
  • 282 posts

Posted 02 August 2022 - 12:25 PM

Hi Sara,

 

you might need to give it better initial estimates, also you may want to let the program estimate when it should switch the function, e.g. 

 

test(){
covariate(Time)
 
stparm(Fdiss = Time<tx? kd*(Time^n): A^(Time))
 
error(FdissEps = 1)
observe(FdissObs(Time) = Fdiss + FdissEps)
 
fixef(tx = c(,1,))
fixef(kd = c(, 1, ))
fixef(n = c(, 1, ))
fixef(A = c(, 1, ))
}
 
I do even get a result with bad initial estimates for a standard data set:
 
diss.png
 
Looks a bit ugly, but proves the robustness of the engine!
 
Bernd

  • littlepetinga and linda like this

#7 littlepetinga

littlepetinga

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationPortugal

Posted 03 August 2022 - 07:54 AM

Hi Bernd,

 

Thank you very much.

 

I gave different initial estimates and let the program decide when to switch the function.

 

It worked perfectly!

 

Just another question, is it possible to place more than one condition with stparm?

 

Thank you for your precious help.

 

Best regards

Sara



#8 bwendt@certara.com

bwendt@certara.com

    Advanced Member

  • Administrators
  • 282 posts

Posted 03 August 2022 - 07:58 AM

Hi Sara,

 

glad, it worked for you!

 

As you see, PML is highly flexible, what else do you have in mind? You can have nested conditions. Please describe what you need and we may come up with a suggestion.

 

Cheers,

Bernd


  • littlepetinga likes this

#9 littlepetinga

littlepetinga

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationPortugal

Posted 03 August 2022 - 10:53 AM

Hi Bernd,

 

Yes, I can see it is!

 

For example, can you define different dissolution models for 3 different formulations?

 

Thank you very much once again

 

Best regards

Sara 



#10 bwendt@certara.com

bwendt@certara.com

    Advanced Member

  • Administrators
  • 282 posts

Posted 03 August 2022 - 01:59 PM

Hi Sara,

 

as mentioned, you can define nested conditions like:

 

form1=a+b
form2= a+b+c
form3=a+b+c+d

stparm(Fdiss = ( Time<tx? form1 : Time<ty ? form2 :form3))

 

Not sure this will help. Perhaps you can share your project file. If it is confidential you may want to send this to support@certara.com

 

Bernd



#11 littlepetinga

littlepetinga

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationPortugal

Posted 02 September 2022 - 06:38 PM

Hi Bernd

 

Thank you very much for your help once again.

 

Is it possible to do so with differential equations? i.e., to use different differential equations depending on the value of a categorical covariate?

 

Thank you!

Sara

 

 

Hi Sara,

 

as mentioned, you can define nested conditions like:

 

form1=a+b
form2= a+b+c
form3=a+b+c+d

stparm(Fdiss = ( Time<tx? form1 : Time<ty ? form2 :form3))

 

Not sure this will help. Perhaps you can share your project file. If it is confidential you may want to send this to support@certara.com

 

Bernd



#12 bwendt@certara.com

bwendt@certara.com

    Advanced Member

  • Administrators
  • 282 posts

Posted 05 September 2022 - 11:40 AM

Hi Sara,

 

sorry, but you can please give us a more detailed example.

 

Thanks,

Bernd



#13 littlepetinga

littlepetinga

    Member

  • Members
  • PipPip
  • 19 posts
  • LocationPortugal

Posted 09 September 2022 - 04:44 PM

Hi Bernd,

 

I am sorry, I was not clear.

 

My question is, if we can model different dissolution differential equations, depending on the formulation (categorical covariate).

For example, for 'Formulation 1', use a Weibull model, and for Formulation 2 use an Hill. Is it possible to do?

 

Thank you very much for all the help!

Sara



#14 bwendt@certara.com

bwendt@certara.com

    Advanced Member

  • Administrators
  • 282 posts

Posted 22 September 2022 - 03:11 PM

Hi Sara,

 

yes, this is possible. But I am not sure what you want to achieve by this. You will end up with different models and different parameters for each formulation. What would be the value of putting those into the same model object?

 

Bernd







Also tagged with one or more of these keywords: modelling, ifelse

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users