# Dual absorption 2 CMT model fitting error

**URL:** https://discourse.pumas.ai/t/dual-absorption-2-cmt-model-fitting-error/956
**Category:** Uncategorized
**Created:** [November 16, 2023, 4:29pm UTC](https://discourse.pumas.ai/t/dual-absorption-2-cmt-model-fitting-error/956 "2023-11-16T16:29:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![chrisv](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@chrisv](https://discourse.pumas.ai/u/chrisv)
#### Post date: [November 16, 2023, 4:29pm UTC](https://discourse.pumas.ai/t/dual-absorption-2-cmt-model-fitting-error/956/1 "2023-11-16T16:29:21Z")

</div>

Hello. I have been working on another model, with double absorption (KA1 and KA2) and two compartments. However, I get an error that has caused me problems before. The classic error of gradient = 0 and that a certain parameter is not identified.

OUTPUT: [ Info: Checking the initial parameter values.  
[ Info: The initial negative log likelihood and its gradient are finite. Check passed.  
Iter Function value Gradient norm  
0 1.568802e+03 3.380961e+03

- time: 0.0010001659393310547  
ERROR: gradient is exactly zero in tvlag. This indicates that tvlag isn’t identified.

MY MODEL:  
mymodel = @model begin

```
@param begin
    tvcl ∈ RealDomain(lower=0)
    tvv ∈ RealDomain(lower=0)
    tvka1 ∈ RealDomain(lower=0.001)
    tvka2 ∈ RealDomain(lower=0)
    tvq ∈ RealDomain(lower=0)
    tvvp ∈ RealDomain(lower=0)
    tvlag ∈ RealDomain(lower=0)
    tvbio ∈ RealDomain(lower=0)
    Ω ∈ PDiagDomain(5)
    σ ∈ RealDomain(lower = 0.0001)
end

@random begin
    η ~ MvNormal(Ω)
end

@pre begin
    CL = tvcl*exp(η[1])
    Vc = tvv*exp(η[2])
    Ka1 = tvka1*exp(η[3])
    Ka2 = tvka2*exp(η[4])
    lags = (SR = tvlag,)
    bioav = (IR = tvbio*exp(η[5]), SR = 1-tvbio*exp(η[5]))
    Q = tvq
    Vp = tvvp
end

@dynamics begin
    IR' = -Ka1*IR
    SR' = -Ka2*SR
    Central' = Ka1*IR + Ka2*SR - Central*CL/Vc - (Q/Vc)*Central + (Q/Vp)*Peripheral
    Peripheral' = (Q/Vc)*Central - (Q/Vp)*Peripheral
end

@derived begin
conc := @. Central/Vc
dv ~ @. Normal(conc, σ*abs(conc))
end

```

end

param = (  
tvcl = 5, tvv = 50, tvka1 = 0.8, tvka2 = 0.6, tvlag = 1000, tvbio = 0.5,tvq=10,tvvp=100,  
Ω = Diagonal([0.1,0.1,0.4,0.4,0.1]),  
σ = 0.1  
)

fit\_results = fit(mymodel, pop, param, Pumas.FOCE())

---

<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: [November 20, 2023, 4:28am UTC](https://discourse.pumas.ai/t/dual-absorption-2-cmt-model-fitting-error/956/2 "2023-11-20T04:28:43Z")

</div>

Dear @chrisv

`lags` and `bioav` should go into the `@dosecontrol` block. So, please re-write your code this way

```julia

@pre begin
    CL = tvcl*exp(η[1])
    Vc = tvv*exp(η[2])
    Ka1 = tvka1*exp(η[3])
    Ka2 = tvka2*exp(η[4])
    Q = tvq
    Vp = tvvp
end

@dosecontrol begin
    lags = (SR = tvlag,)
    bioav = (IR = tvbio*exp(η[5]), SR = 1-tvbio*exp(η[5]))
end

```

you can read more in the documentation [here](https://docs.pumas.ai/stable/basics/models/#@dosecontrol:-Dose-Control-Parameters)

---

<div class="post-metadata">

### Author: ![chrisv](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@chrisv](https://discourse.pumas.ai/u/chrisv)
#### Post date: [November 27, 2023, 11:12pm UTC](https://discourse.pumas.ai/t/dual-absorption-2-cmt-model-fitting-error/956/3 "2023-11-27T23:12:15Z")

</div>

Thank you for your help! I have changed the code as I show below:

mymodel = @model begin

```
@param begin
    tvcl ∈ RealDomain(lower=0)
    tvv ∈ RealDomain(lower=0)
    tvka1 ∈ RealDomain(lower=0)
    tvka2 ∈ RealDomain(lower=0)
    tvq ∈ RealDomain(lower=0)
    tvvp ∈ RealDomain(lower=0)
    tvlag ∈ RealDomain(lower=0)
    tvbio ∈ RealDomain(lower=0)
    Ω ∈ PDiagDomain(5)
    σ ∈ RealDomain(lower = 0.0001)
end

@random begin
    η ~ MvNormal(Ω)
end

@pre begin
    CL = tvcl*exp(η[1])
    Vc = tvv*exp(η[2])
    Ka1 = tvka1*exp(η[3])
    Ka2 = tvka2*exp(η[4])
    Q = tvq
    Vp = tvvp
end

@dosecontrol begin
    lags = (SR = tvlag,)
    bioav = (IR = tvbio*exp(η[5]), SR = 1-tvbio*exp(η[5]))
end

@dynamics begin
    IR' = -Ka1*IR
    SR' = -Ka2*SR
    Central' = Ka1*IR + Ka2*SR - Central*CL/Vc - (Q/Vc)*Central + (Q/Vp)*Peripheral
    Peripheral' = (Q/Vc)*Central - (Q/Vp)*Peripheral
end

@derived begin
conc := @. Central/Vc
dv ~ @. Normal(conc, σ*abs(conc))
end

```

end

Then I used my model, population and parameters to fit:  
param = (  
tvcl = 5, tvv = 50, tvka1 = 0.8, tvka2 = 0.6, tvlag = 1000, tvbio = 0.5,tvq=10,tvvp=100,  
Ω = Diagonal([0.1,0.1,0.4,0.4,0.1]),  
σ = 0.1  
)

fit\_results = fit(mymodel, pop, param, Pumas.FOCE())

Finally, I get the same error but now in KA2:  
gradient is exactly zero in tvka2. This indicates that tvka2 isn’t identified.

---

<div class="post-metadata">

### Author: ![storopoli](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/storopoli/32/190_2.png) [@storopoli](https://discourse.pumas.ai/u/storopoli)
#### Post date: [November 28, 2023, 12:10pm UTC](https://discourse.pumas.ai/t/dual-absorption-2-cmt-model-fitting-error/956/4 "2023-11-28T12:10:32Z")

</div>

> [@chrisv](#):
>
> ```julia
> param = (
> tvcl = 5, tvv = 50, tvka1 = 0.8, tvka2 = 0.6, tvlag = 1000, tvbio = 0.5,tvq=10,tvvp=100,
> Ω = Diagonal([0.1,0.1,0.4,0.4,0.1]),
> σ = 0.1
> )
> 
> ```

Isn’t this particular initial value of `tvlag` too big?  
What happens if you fit with something lower, e.g. `5`?
