# time-varying residual error model

**URL:** <https://forum.certara.com/t/time-varying-residual-error-model/3010>\
**Category:** Modelling and Simulation\
**Created:** [August 28, 2016, 7:34pm UTC](https://forum.certara.com/t/time-varying-residual-error-model/3010 "2016-08-28T19:34:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![niujing23\_1](https://avatars.discourse-cdn.com/v4/letter/n/8c91f0/32.png) [@niujing23\_1](https://forum.certara.com/u/niujing23_1)\
**Post date:** [August 28, 2016, 7:34pm UTC](https://forum.certara.com/t/time-varying-residual-error-model/3010/1 "2016-08-28T19:34:21Z")

</div>

Dear Certara Forum users,

I am modeling a long-acting release form and my absorption model can’t fit very well. I am trying to use time-varying residual error model to fix my absorption phase.

My approach is like below: first create a categorical variable using absTime = if(Time\_\_hr\_\<=24,1,0), then using two seperate proportional error terms for the absorption and distribution phase:

stparm(CMultStdev = tvCMultStdev\*(absTime==0)+tvCMultStdev\_absTime\*(absTime==1))

This approach works, I am wondering is there a way that I can code directly in PML (without creating the dummy variable absTime), maybe use if else statement?

Thanks in advance,

Jing Niu

CTM, University of Maryland

---

<div class="post-metadata">

**Author:** ![minhaj](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@minhaj](https://forum.certara.com/u/minhaj)\
**Post date:** [August 28, 2016, 8:55pm UTC](https://forum.certara.com/t/time-varying-residual-error-model/3010/2 "2016-08-28T20:55:33Z")

</div>

Dear colleague

I am attaching a project I just made that answers your question.

You need to use the group statement to define the conditions on the time and then you can write the condition into the stparm.

If you want to use QRPEM, you need to put the if condition outside the stparm.

I tested my code by simulation and then fitting and it works.

Hope it helps.

best

Serge

[newbie.phxproj](https://forum.certara.com/uploads/short-url/9t9CUn4XVt3ZjDcBq6ATrHr8DHP.phxproj) (1.87 MB)

---

<div class="post-metadata">

**Author:** ![mittyright](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@mittyright](https://forum.certara.com/u/mittyright)\
**Post date:** [August 29, 2016, 10:29am UTC](https://forum.certara.com/t/time-varying-residual-error-model/3010/3 "2016-08-29T10:29:44Z")

</div>

Dear Jing Niu,

you can even simplify it to  
_stparm(CMultStdev = t\<=24?tvCMultStdev:tvCMultStdev\_absTime)_

So you can use ternary operator as a substitution of ifelse statement. In this case you don’t need group() statement.

But Serge’s code is better because you can add index to Variables in output table for tracking.

Dear Serge,

I suppose this line in your project

_stparm(CMultStdev = tvCMultStdev)_

is superfluous

Have a good day!

Mittyright

---

<div class="post-metadata">

**Author:** ![minhaj](https://avatars.discourse-cdn.com/v4/letter/m/a698b9/32.png) [@minhaj](https://forum.certara.com/u/minhaj)\
**Post date:** [August 29, 2016, 10:33am UTC](https://forum.certara.com/t/time-varying-residual-error-model/3010/4 "2016-08-29T10:33:54Z")

</div>

> [@mittyright](#):
>
> Dear Jing Niu,
> 
> you can even simplify it to  
> _stparm(CMultStdev = t\<=24?tvCMultStdev:tvCMultStdev\_absTime)_
> 
> So you can use ternary operator as a substitution of ifelse statement. In this case you don’t need group() statement.
> 
> But Serge’s code is better because you can add index to Variables in output table for tracking.
> 
> Dear Serge,
> 
> I suppose this line in your project
> 
> _stparm(CMultStdev = tvCMultStdev)_
> 
> is superfluous
> 
> Have a good day!
> 
> Mittyright

Yes, it was the original stparm but you are right, no use of the original Cmultstdev.

What is interesting is that Phoenix did not complaint but you did and you were right.

Best

Serge

---

<div class="post-metadata">

**Author:** ![niujing23\_1](https://avatars.discourse-cdn.com/v4/letter/n/8c91f0/32.png) [@niujing23\_1](https://forum.certara.com/u/niujing23_1)\
**Post date:** [August 29, 2016, 2:23pm UTC](https://forum.certara.com/t/time-varying-residual-error-model/3010/5 "2016-08-29T14:23:11Z")

</div>

Dear Serge and Mittyright,

Thanks for your reply and it’s really helpful.

I guess if two lines of code were used to define the same variable, the latter one will cover the first one. Like in our case, _stparm(CMultStdev = tvCMultStdev)_ _was ignored._

Jing Niu

---

<div class="post-metadata">

**Author:** ![mittyright](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@mittyright](https://forum.certara.com/u/mittyright)\
**Post date:** [August 29, 2016, 2:31pm UTC](https://forum.certara.com/t/time-varying-residual-error-model/3010/6 "2016-08-29T14:31:40Z")

</div>

Dear Jing Niu,

you are right, the latter one will cover the first one, but this could be confusing for the users. Moreover, some reference from PML User’s guide:

_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 in PML code, outside of_  
_sequence blocks (and assignment statements), relative order of statements does not matter._

so I would not bet about right stparm statement in case of multiple usage.

BR,  
Mittyright
