How to estimate parameters for data

Hi, i have used the below code i think i have gone wrong somewhere. can anyone help me to find out where i have gone wrong and how to forward

    @param begin
        tvcl ∈ RealDomain(lower=0, init = 0.6)
        tvv2 ∈ RealDomain(lower=0, init = 40)
        tvQ ∈ RealDomain(lower=0, init = 3)
        #tvk23 ∈ RealDomain(lower=0, init = 3)
        #tvk32 ∈ RealDomain(lower=0, init = 2)
        #tvk20 ∈ RealDomain(lower=0, init = 2.5)
        tvv3 ∈ RealDomain(lower=0, init = 130)
        tvka ∈ RealDomain(lower = 0, init= 0.02)
        Ω ∈ PDiagDomain(init=[0.2])
        σ1 ∈ ConstDomain(1)
        σ2 ∈ RealDomain(lower = 0, init = 0.2)
      end
      @random begin
         η ~ MvNormal(Ω)
      end
      @pre begin
          Ka     = tvka
          CL      = tvcl*exp(η[1])
          Vc      = tvv2
          Q       = tvQ
          #k23     = tvk23
          #k32     = tvk32
          #k20     = tvk20
          Vp      = tvv3
      end
     # @dynamics ImmediateAbsorptionModel
        @dynamics begin
            Depot' =  -Ka*Depot
            Central' =  Ka*Depot - ((Vc/CL)+Q)*Central + Q*(Peripheral)
            #Central' =  Ka*Depot - (k2o+k23)*Central + k32*(Peripheral)
            #Peripheral' = k23*Central - k32*(Peripheral)
            Peripheral' = Q*Central - Q*(Peripheral)
        end
        @derived begin
            depot = Depot
            cp = Central/Vc
            perip = Peripheral
            dv ~ @. Normal(cp, cp*(1+σ2)+σ1)
        end
    end
param = init_param(model)

ylo = CSV.read("D:\\NONMEMnights\\mould\\julia\\yloedited.csv")

data = read_pumas(ylo, dvs=[:dv])

res = fit(model,data,param,Pumas.FOCE())```

```DATA
![image|258x500](upload://ldkBiIK2tIHU24tTfAklhzS03Iw.png) CID	TIME	AMT	DV	MDV
1	0	50	.	1
1	2.5	.	0.41602	0
1	5	.	0.40408	0
1	10	.	0.32019	0
1	15	.	0.36337	0
1	30	.	0.091612	0
1	60	.	0.072907	0
1	90	.	0.056053	0
1	120	.	0.065449	0
1	180	.	0.053612	0
1	240	.	.	1
1	300	.	0.052835	0
1	360	.	0.061585	0
1	480	.	.	1
1	600	.	.	1
2	0	50	.	1
2	2.5	.	0.22745	0
2	5	.	0.48887	0
2	10	.	0.34948	0
2	15	.	0.19076	0
2	30	.	0.17412	0
2	60	.	0.11533	0
2	90	.	0.10667	0
2	120	.	0.088994	0
2	180	.	0.068695	0
2	240	.	.	1
2	300	.	0.065073	0
2	360	.	0.078097	0
2	480	.	0.066583	0
2	600	.	0.051223	0

Hi sai_matcha

The code snippet looks incomplete. Could you please link to the complete example and post the error message.

Thanks
Andreas Noack

model = @model begin
    @param begin
        tvcl ∈ RealDomain(lower=0, init = 0.6)
        tvv2 ∈ RealDomain(lower=0, init = 40)
        tvQ ∈ RealDomain(lower=0, init = 3)
        #tvk23 ∈ RealDomain(lower=0, init = 3)
        #tvk32 ∈ RealDomain(lower=0, init = 2)
        #tvk20 ∈ RealDomain(lower=0, init = 2.5)
        tvv3 ∈ RealDomain(lower=0, init = 130)
        tvka ∈ RealDomain(lower = 0, init= 0.02)
        Ω ∈ PDiagDomain(init=[0.2])
        σ1 ∈ ConstDomain(1)
        σ2 ∈ RealDomain(lower = 0, init = 0.2)
      end
      @random begin
         η ~ MvNormal(Ω)
      end
      @pre begin
          Ka     = tvka
          CL      = tvcl*exp(η[1])
          Vc      = tvv2
          Q       = tvQ
          #k23     = tvk23
          #k32     = tvk32
          #k20     = tvk20
          Vp      = tvv3
      end
     # @dynamics ImmediateAbsorptionModel
        @dynamics begin
            Depot' =  -Ka*Depot
            Central' =  Ka*Depot - ((Vc/CL)+Q)*Central + Q*(Peripheral)
            #Central' =  Ka*Depot - (k2o+k23)*Central + k32*(Peripheral)
            #Peripheral' = k23*Central - k32*(Peripheral)
            Peripheral' = Q*Central - Q*(Peripheral)
        end
        @derived begin
            depot = Depot
            cp = Central/Vc
            perip = Peripheral
            dv ~ @. Normal(cp, cp*(1+σ2)+σ1)
        end
    end
param = init_param(model)

ylo = CSV.read("D:\\NONMEMnights\\mould\\julia\\yloedited.csv")

data = read_pumas(ylo, dvs=[:dv])

res = fit(model,data,param,Pumas.FOCE())

this is total code i run. i expected this code will give parameters but it gave same initial estimates value as parameters

I edited your text; you need to put the last three back-ticks on a new line :slight_smile:

Can you show us the output of res.optim?

result after res.optim

You are trying to overwrite what’s in res.optim with that command. Could you try to just write res.optim at the command prompt in the window below the script?

res.optim gives status:success
optim

Please type res.optim in the prompt window instead of the script window.

sorry,

res.optim
 * Status: success

 * Candidate solution
    Minimizer: [-5.11e-01, 3.69e+00, 1.10e+00,  ...]
    Minimum:   2.629817e+01

 * Found with
    Algorithm:     BFGS
    Initial Point: [-5.11e-01, 3.69e+00, 1.10e+00,  ...]

 * Convergence measures
    |x - x'|               = 0.00e+00 ≤ 0.0e+00
    |x - x'|/|x'|          = 0.00e+00 ≤ 0.0e+00
    |f(x) - f(x')|         = NaN ≰ 0.0e+00
    |f(x) - f(x')|/|f(x')| = NaN ≰ 0.0e+00
    |g(x)|                 = 1.40e-05 ≤ 1.0e-03

 * Work counters
    Seconds run:   0  (vs limit Inf)
    Iterations:    0
    f(x) calls:    1
    ∇f(x) calls:   1

It looks like the likelihood becomes NaN and that is the reason why the optimization stops. I’m not sure why but your error model looks wrong. I assume that you are trying to write an error model with a proportional and additive component. See https://github.com/PumasAI/Pumas.jl/blob/b16c09c6d609ab766a13f79ad65fa711c0125a40/test/nlme/theophylline.jl#L525 for an example of how to do that in Pumas.

1 Like

i tried to write both proportional and additive error. ill go through the link, thank you.