Fix data error,

hi all
i tried the below codes and not able to fit the data at end

DR1 = DosageRegimen(50,time=0,cmt=2)

#DR2 = DosageRegimen(100,time=0,cmt=2)

#DR3 = DosageRegimen(200,time=0,cmt=2)

#s1 = Subject(id=1,evs = DR1, cvs = (wt=70,))

#s2 = Subject(id=2, evs = DR2, cvs= (wt=60,))

#s3 = Subject(id=3,evs=DR3, cvs = (wt=65,))

choose_covariates() = (WT = rand(55:80),)

#pop = Population([s1,s2,s3])


pop = Population(map(i -> Subject(id = i,evs = DR1, cvs =  choose_covariates()),1:24))

pop




##############################

mymodel = @model begin
  @param   begin
    tvcl ∈ RealDomain(lower=0, init = 1.0)
    tvv ∈ RealDomain(lower=0, init = 5)
    tvQ ∈ RealDomain(lower = 0, init= 1)
    tvv2 ∈ RealDomain(lower = 0, init = 10)
    Ω ∈ PDiagDomain(init=[0.09])
    σ_prop ∈ RealDomain(lower=0,init=0.04)
  end
#end
  @random begin
    η ~ MvNormal(Ω)
  end
#end
  @pre begin
    CL = tvcl * exp(η[1])
    V  = tvv 
    V2 = tvv2
    Q = tvQ
  end
#end
 #@covariates WT
#end
  #@dynamics ImmediateAbsorptionModel
    @dynamics begin
        #    Depot' =  -Ka*Depot
            Central' =  Q*(Peripheral-Central) - (CL/V)*Central
        
         Peripheral' =   Q*(Central-Peripheral)
    end
#end

  @derived begin
      cp = @. 1000*(Central / V)
      DV ~ @. Normal(cp,sqrt(cp^2*σ_prop))
    end
end
#####

  
param = init_param(mymodel)

obs = simobs(mymodel, pop, param, obstimes=0:1:72)
plot(obs)


simdf = DataFrame(obs)
first(simdf, 6)

simdf.route = "IV"

timeu = u"hr"
concu = u"mg/L"
amtu  = u"mg"

ncadf = read_nca(simdf, id=:id, time=:time, conc=:cp, amt=:amt,
    route=:route,timeu=timeu, concu=concu, amtu=amtu, lloq=0.4concu)

plot(ncadf)

simdf.cmt = ifelse.(ismissing.(simdf.cmt), 2, simdf.cmt)
est_df = simdf[.!((simdf.DV .== 0.0) .& (simdf.cmt .==2)),:]
first(est_df,6)

data = read_pumas(est_df ,cvs = [:WT], dvs=[:DV])

res = fit(mymodel,data,param,Pumas.FOCEI())

error is
Typeerror: in type assert, expected forward diff.dual … and many things

@sai_matcha I see two immediate reasons why this did not run.

  1. DR1 doses the drug into the peripheral compartment in a 2 compartment IV bolus model that is written up. This is incorrect. it should be DR1 = DosageRegimen(50,time=0,cmt=1)
  2. It is preferred to use all lower case variable names in Pumas (dv as opposed to DV)
  @derived begin
      cp = @. 1000*(Central / V)
      dv ~ @. Normal(cp,sqrt(cp^2*σ_prop))
    end

Fixing these two, gives me a successful run. Please try it out and let us know.

Best,
Vijay

1 Like

Hi.
i tried running the same codes after changing to cmt=1, DV to dv…
but this time im stuck at nca itself…

DR1 = DosageRegimen(50,time=0,cmt=1)

#DR2 = DosageRegimen(100,time=0,cmt=2)

#DR3 = DosageRegimen(200,time=0,cmt=2)

#s1 = Subject(id=1,evs = DR1, cvs = (wt=70,))

#s2 = Subject(id=2, evs = DR2, cvs= (wt=60,))

#s3 = Subject(id=3,evs=DR3, cvs = (wt=65,))

choose_covariates() = (wt = rand(55:80),)

#pop = Population([s1,s2,s3])


pop = Population(map(i -> Subject(id = i,evs = DR1, cvs =  choose_covariates()),1:24))

pop




##############################

mymodel = @model begin
  @param   begin
    tvcl ∈ RealDomain(lower=0, init = 1.0)
    tvv ∈ RealDomain(lower=0, init = 5)
    tvQ ∈ RealDomain(lower = 0, init= 1)
    tvv2 ∈ RealDomain(lower = 0, init = 10)
    Ω ∈ PDiagDomain(init=[0.09])
    σ_prop ∈ RealDomain(lower=0,init=0.04)
  end
#end
  @random begin
    η ~ MvNormal(Ω)
  end
#end
  @pre begin
    CL = tvcl * exp(η[1])
    V  = tvv 
    V2 = tvv2
    Q = tvQ
  end
#end
 #@covariates WT
#end
  #@dynamics ImmediateAbsorptionModel
    @dynamics begin
        #    Depot' =  -Ka*Depot
            Central' =  Q*(Peripheral-Central) - (CL/V)*Central
        
         Peripheral' =   Q*(Central-Peripheral)
    end
#end

  @derived begin
      cp = @. 1000*(Central / V)
      dv ~ @. Normal(cp,sqrt(cp^2*σ_prop))
    end
end
#####

  
param = init_param(mymodel)

obs = simobs(mymodel, pop, param, obstimes=0:1:72)
plot(obs)


simdf = DataFrame(obs)
first(simdf, 6)

simdf.route = "IV"

timeu = u"hr"
concu = u"mg/L"
amtu  = u"mg"

ncadf = read_nca(simdf, id=:id, time=:time, conc=:cp, amt=:amt,
    route=:route,timeu=timeu, concu=concu, amtu=amtu, lloq=0.4concu)