# Usage of dosecontrol block

**URL:** <https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572>\
**Category:** Estimation\
**Created:** [January 3, 2022, 9:31pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572 "2022-01-03T21:31:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dawoon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/dawoon/32/179_2.png) [@Dawoon](https://discourse.pumas.ai/u/Dawoon)\
**Post date:** [January 3, 2022, 9:31pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/1 "2022-01-03T21:31:26Z")

</div>

Hello,

I am trying to use ifelse statement at dosecontrol block but am not sure if it is supported. Here is my model.

```auto
ecmo_cov_model = @model begin

      @param begin
          POPCL ∈ RealDomain(lower=0.0)
          θscr ∈ RealDomain(lower=0.0)
          θpma ∈ RealDomain(lower=-100)
          POPVc ∈ RealDomain(lower=0.0)
          θage ∈ RealDomain(lower=0.0)
          POPKa ∈ RealDomain(lower=0.0)
          POPBioav ∈ RealDomain(lower=0.001)
          ω²κF ∈ RealDomain(lower=0)
          Ω1 ∈ PDiagDomain(2) #BSV for CL and Vc
          σ_prop ∈ RealDomain(lower=0.0)
      end

      @random begin
          η ~ MvNormal(Ω1)
          κF ~ MvNormal(7, sqrt(ω²κF))
      end

    @covariates FFM AGEYRS PMA SCR PSF isECMO OCC
    #FFM:Fat free mass(kg), AGEYRS:Age(PNA,yr), PMA:Postmenstrual age(wk), SCR:Serum creatinine(mg/dL)

    @pre begin
      TVCL = POPCL * (FFM/70)^0.75 * (0.3/SCR)^θscr * (1/(1 + (PMA/41)^θpma))
      TVVc = POPVc * (FFM/70) * θage^log(AGEYRS/0.28)

      CL = TVCL * exp(η[1])
      Vc = TVVc * exp(η[2])
      Ka = POPKa
    end

    @dosecontrol begin
        bioav = ifelse.(isECMO .== 0, (Depot .= POPBioav, Central .= 1), (Depot .= POPBioav * exp(κF[OCC]), Central .= 1 * exp(κF[OCC])))
    end

    @dynamics begin
        # 1cmt
        Depot' = -Ka * Depot
        Central' = Ka * Depot - Central * (CL/Vc)

    end

    @derived begin
        CP = @. Central/Vc
        DV ~ @. Normal(CP, abs(CP) * σ_prop)
    end
end

```

I would like to estimate BOV when isECMO is true. In other words, bioav will keep changing in the time course of ECMO.  
The error says `Depot` is not defined and I was wondering if the dosecontrol block makes sense.  
Thank you in advance for your help!

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [January 4, 2022, 5:40pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/2 "2022-01-04T17:40:08Z")

</div>

> [@Dawoon](#):
>
> ```auto
> @dosecontrol begin
> bioav = ifelse.(isECMO .== 0, (Depot .= POPBioav, Central .= 1), (Depot .= POPBioav * exp(κF[OCC]), Central .= 1 * exp(κF[OCC])))
> end
> 
> ```

Can you try and rewrite like this below?

```julia
@dosecontrol begin
bioav = (Depot = POPBioav * (exp(κF[OCC]) * isECMO == 1), 
            Central = 1 * (exp(κF[OCC])) * isECMO == 1))
end

```

---

<div class="post-metadata">

**Author:** ![Dawoon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/dawoon/32/179_2.png) [@Dawoon](https://discourse.pumas.ai/u/Dawoon)\
**Post date:** [January 12, 2022, 8:14pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/3 "2022-01-12T20:14:04Z")

</div>

Thank you, Dr. Ivaturi

I was able to resolve the previous issue thanks to your suggestion but am facing another error during fitting. I tried both bayesian post hoc estimation and fitting but they showed the same type of error. It worked before adding BOV and I suspect that OCC is causing the problem. Could you please look at them? Thank you for your help!

```auto
ecmo_cov_model = @model begin

      @param begin
          POPCL ∈ RealDomain(lower=0.001)
          θscr ∈ RealDomain(lower=0.001)
          θpma ∈ RealDomain(lower=-10, upper=-0.001)
          POPVc ∈ RealDomain(lower=0.001)
          θage ∈ RealDomain(lower=0.001)
          POPKa ∈ RealDomain(lower=0.001, upper = 1.0)
          POPBioav ∈ RealDomain(lower=0.001, upper = 0.95)
          ω²κF ∈ RealDomain(lower=0.001)
          Ω1 ∈ PDiagDomain(2) #BSV for CL and Vc
          σ_prop ∈ RealDomain(lower=0.001)
      end

      @random begin
          η ~ MvNormal(Ω1)
          κF ~ MvNormal(8, sqrt(ω²κF))
      end

    @covariates FFM AGEYRS PMA SCR PSF isECMO OCC

    @pre begin
      TVCL = POPCL * (FFM/70)^0.75 * (0.3/SCR)^θscr * (1/(1 + (PMA/41)^θpma))
      TVVc = POPVc * (FFM/70) * θage^log(AGEYRS/0.28)

      CL = TVCL * exp(η[1])
      Vc = TVVc * exp(η[2])
      Ka = POPKa
    end

    @dosecontrol begin
        bioav = (Depot = POPBioav * (exp(κF[OCC]) * isECMO == 1), Central = 1 * (exp(κF[OCC]) * isECMO == 1))
    end

    @dynamics begin
        # 1cmt
        Depot' = -Ka * Depot
        Central' = Ka * Depot - Central * (CL/Vc)

    end

    @derived begin
        CP = @. Central/Vc
        DV ~ @. Normal(CP, abs(CP) * σ_prop)
    end
end

# initial parameters
ecmo_cov_param = (POPCL = 0.372, #CL(l/h)
                  θscr = 0.265, #SCR effect on CL
                  θpma = -4.22, #PMA effect on CL
                  POPVc = 62.5, #Vc(L)
                  θage = 0.981, #AGEYRS effect on Vc
                  POPKa = 0.8, #θabsorption rate(1/hr)
                  POPBioav = 0.89, #θbioavailability
                  ω²κF = 0.3,
                  Ω1 = Diagonal([0.1814, 0.1052]), #varCL, varVc
                  σ_prop = 0.148)

baysian_post = predict(ecmo_cov_model, ecmo_data, ecmo_cov_param)              

fit_result= fit(ecmo_cov_model,
                 ecmo_data,
                 ecmo_cov_param,
                 Pumas.FOCEI())

```

The below screenshot was a part of the error during the fitting.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/98675771e15aaa970a4fc392c880fa9d02eaef9f.png)

---

<div class="post-metadata">

**Author:** ![Dawoon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/dawoon/32/179_2.png) [@Dawoon](https://discourse.pumas.ai/u/Dawoon)\
**Post date:** [January 14, 2022, 10:36pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/4 "2022-01-14T22:36:35Z")

</div>

I modified the `dosecontrol` block like the below.

```auto
bioav = (Depot = (isECMO == 1) ? POPBioav * exp(κF[OCC]) : POPBioav, Central = (isECMO == 1) ? 1 * exp(κF[OCC]) : 1)

```

This code made it possible to start iteration but it stopped during iteration. I don’t have any EVID=2. Could you please advise how I can fix this? Thank you!

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/f786bb2292b288a4af22b2b652cfb55c5fc6cbbf.png)

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [January 14, 2022, 11:05pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/5 "2022-01-14T23:05:13Z")

</div>

This happens when bioavailability is driven to zero. Let me suggest a way to protect this.

---

<div class="post-metadata">

**Author:** ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)\
**Post date:** [January 29, 2022, 7:16pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/6 "2022-01-29T19:16:23Z")

</div>

Drs Vijay and Dawoon - Very interesting problem to solve. Pleased to see some talented scientists are tackling this topic. I have some clinical experience with ECMO. Dosing in ECMO patients is so challenging in the ICU.

The principal cause for the loss of ‘dose’ is due to the sticking of drug to the tubing. While this is not physiologic; I see you are trying to alter the bioavailability to account for this loss. Doesn’t bioavailability affect the dose only during ‘active dosing’? Which means for an oral dose, it is instantaneous. Probably this approach may not be viable for your problem. Have you considered an irreversible loss via an additional route ? It is also possible that this loss has a brief time course (kind of first-order). You might want to take some inspiration from how enterohepatic circulation is modeled.  
Bob

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [January 29, 2022, 8:03pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/7 "2022-01-29T20:03:40Z")

</div>

Good point, Bob! Loss of drug through adhesion to the tube is usually modeled this way. I guess the OP was trying different modalities of handling this, but you are right that `bioav` is only applied to the time of the active dose and not after the dose is administered.

---

<div class="post-metadata">

**Author:** ![Dawoon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/dawoon/32/179_2.png) [@Dawoon](https://discourse.pumas.ai/u/Dawoon)\
**Post date:** [January 30, 2022, 10:04pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/8 "2022-01-30T22:04:03Z")

</div>

Thank you for your comments @bobbrown, @vijay .  
I have been trying different models to deal with loss of drug in ECMO circuit and was wondering if I could employ this bioav concept into the model but it seems not a viable option. I will also look at enterohepatic circulation model and see if I can get an idea from it. Thank you so much for your suggestion and advice!

---

<div class="post-metadata">

**Author:** ![donaldlee3](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/donaldlee3/32/165_2.png) [@donaldlee3](https://discourse.pumas.ai/u/donaldlee3)\
**Post date:** [March 25, 2024, 11:41pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/9 "2024-03-25T23:41:07Z")

</div>

Hi @vijay,

I’m getting this error with evid=2. I wrapping what’s in bioav in abs() + 0.001, but the error still remains. Do you have any other potential fix for this?

---

<div class="post-metadata">

**Author:** ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)\
**Post date:** [March 26, 2024, 12:14am UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/10 "2024-03-26T00:14:42Z")

</div>

Can you tell us a little bit in detail, what’s the model and what’s the exact error you are getting @donaldlee3

---

<div class="post-metadata">

**Author:** ![donaldlee3](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/donaldlee3/32/165_2.png) [@donaldlee3](https://discourse.pumas.ai/u/donaldlee3)\
**Post date:** [March 26, 2024, 6:52pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/11 "2024-03-26T18:52:07Z")

</div>

I’m getting the following error:

```auto
PumasDataError: Dose-related data items must be zero or missing when evid is 2

```

The dose control block for my simulations is as follows:

```auto
    @dosecontrol begin
        duration = (Central = tvdur * exp(ηdur),)

        Ffast = logistic(logit(tvFfast) + ηFfast_logit + κFfast_logit[period])
        Fslow = 1 - Ffast

        Ffast_ = abs(Ffast * exp(κF[period])) + 0.01 # abs + adding small number to prevent biov from reaching 0
        Fslow_ = abs(Fslow * exp(κF[period])) + 0.01 # abs + adding small number to prevent biov from reaching 0

        bioav = (Central = (isT == 1) ? tvtr_F * Ffast_ : Ffast_,
                                Depot = (isT == 1) ? tvtr_F * Fslow_ : Fslow_
                                )
    end

```

I don’t have the `abs` or `+ 0.01` in the estimation model.

The absorption model is parallel zero-order and transit compartment model. I have BOV on bioavailability through `Ffast_` and `Fslow_`, which is where I think the problem could be coming from.

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/andreasnoack/32/22_2.png) [@andreasnoack](https://discourse.pumas.ai/u/andreasnoack)\
**Post date:** [March 26, 2024, 8:55pm UTC](https://discourse.pumas.ai/t/usage-of-dosecontrol-block/572/12 "2024-03-26T20:55:34Z")

</div>

Please share the complete stacktrace. Also, how did you construct you population? Via `read_pumas` or by calling the `Subject` constructor directory?
