Dual absorption 2 CMT model fitting error

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())

Dear @chrisv

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


@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

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.

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