# Modelling with IF()

**URL:** <https://forum.certara.com/t/modelling-with-if/3631>\
**Category:** Modelling and Simulation\
**Created:** [August 1, 2022, 10:54pm UTC](https://forum.certara.com/t/modelling-with-if/3631 "2022-08-01T22:54:39Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![littlepetinga](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@littlepetinga](https://forum.certara.com/u/littlepetinga)\
**Post date:** [August 1, 2022, 10:54pm UTC](https://forum.certara.com/t/modelling-with-if/3631/1 "2022-08-01T22:54:39Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![cradhakr](https://avatars.discourse-cdn.com/v4/letter/c/7feea3/32.png) [@cradhakr](https://forum.certara.com/u/cradhakr)\
**Post date:** [August 1, 2022, 11:53pm UTC](https://forum.certara.com/t/modelling-with-if/3631/2 "2022-08-01T23:53:31Z")

</div>

Hi Sara,

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

Thanks

Mouli

---

<div class="post-metadata">

**Author:** ![littlepetinga](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@littlepetinga](https://forum.certara.com/u/littlepetinga)\
**Post date:** [August 2, 2022, 7:36am UTC](https://forum.certara.com/t/modelling-with-if/3631/3 "2022-08-02T07:36:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bwendt](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@bwendt](https://forum.certara.com/u/bwendt)\
**Post date:** [August 2, 2022, 8:56am UTC](https://forum.certara.com/t/modelling-with-if/3631/4 "2022-08-02T08:56:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![littlepetinga](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@littlepetinga](https://forum.certara.com/u/littlepetinga)\
**Post date:** [August 2, 2022, 10:12am UTC](https://forum.certara.com/t/modelling-with-if/3631/5 "2022-08-02T10:12:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bwendt](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@bwendt](https://forum.certara.com/u/bwendt)\
**Post date:** [August 2, 2022, 12:25pm UTC](https://forum.certara.com/t/modelling-with-if/3631/6 "2022-08-02T12:25:47Z")

</div>

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:

[attachment=3738:diss.png]

Looks a bit ugly, but proves the robustness of the engine!

Bernd

 ![diss.png](https://us1.discourse-cdn.com/certara/original/2X/a/a05e5ca742205351f86a96db0fe14902a94c1c26.png)

---

<div class="post-metadata">

**Author:** ![littlepetinga](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@littlepetinga](https://forum.certara.com/u/littlepetinga)\
**Post date:** [August 3, 2022, 7:54am UTC](https://forum.certara.com/t/modelling-with-if/3631/7 "2022-08-03T07:54:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bwendt](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@bwendt](https://forum.certara.com/u/bwendt)\
**Post date:** [August 3, 2022, 7:58am UTC](https://forum.certara.com/t/modelling-with-if/3631/8 "2022-08-03T07:58:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![littlepetinga](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@littlepetinga](https://forum.certara.com/u/littlepetinga)\
**Post date:** [August 3, 2022, 10:53am UTC](https://forum.certara.com/t/modelling-with-if/3631/9 "2022-08-03T10:53:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bwendt](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@bwendt](https://forum.certara.com/u/bwendt)\
**Post date:** [August 3, 2022, 1:59pm UTC](https://forum.certara.com/t/modelling-with-if/3631/10 "2022-08-03T13:59:02Z")

</div>

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](mailto:support@certara.com)

Bernd

---

<div class="post-metadata">

**Author:** ![littlepetinga](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@littlepetinga](https://forum.certara.com/u/littlepetinga)\
**Post date:** [September 2, 2022, 6:38pm UTC](https://forum.certara.com/t/modelling-with-if/3631/11 "2022-09-02T18:38:28Z")

</div>

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

> [@bwendt\_1](#):
>
> 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](mailto:support@certara.com)
> 
> Bernd

---

<div class="post-metadata">

**Author:** ![bwendt](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@bwendt](https://forum.certara.com/u/bwendt)\
**Post date:** [September 5, 2022, 11:40am UTC](https://forum.certara.com/t/modelling-with-if/3631/12 "2022-09-05T11:40:01Z")

</div>

Hi Sara,

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

Thanks,

Bernd

---

<div class="post-metadata">

**Author:** ![littlepetinga](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@littlepetinga](https://forum.certara.com/u/littlepetinga)\
**Post date:** [September 9, 2022, 4:44pm UTC](https://forum.certara.com/t/modelling-with-if/3631/13 "2022-09-09T16:44:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bwendt](https://avatars.discourse-cdn.com/v4/letter/b/f4b2a3/32.png) [@bwendt](https://forum.certara.com/u/bwendt)\
**Post date:** [September 22, 2022, 3:11pm UTC](https://forum.certara.com/t/modelling-with-if/3631/14 "2022-09-22T15:11:01Z")

</div>

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
