Adding covariates and simulation

I am doing a pop pk to understand the effect of different doing regimen of the drug. I have a model developed and all the dosing regimens. Can someone please help me to add weight as covariate in it and do simulation . I’m pasting my codes here.

daramdl = @model begin
    @param begin
       tvcl   ∈ RealDomain(lower = 0, init = 0.00714)
       tvvc   ∈ RealDomain(lower = 0, init = 4.72)
       tvvp   ∈ RealDomain(lower = 0, init = 2.44)
       tvq    ∈ RealDomain(lower = 0, init = 0.0267)
       tvvmax ∈ RealDomain(lower = 0, init = 1.1)
       tvkdes ∈ RealDomain(lower = 0, init = 0.000228)
       tvkm   ∈ RealDomain(lower = 0, init = 2.38)
       σ_add  ∈ RealDomain(lower = 0, init = 32.7)
    end
  
    @pre begin
       Cl   = tvcl
       Vc   = tvvc
       Vp   = tvvp
       Q    = tvq
       Vmax = tvvmax
       Kdes = tvkdes
       Km   = tvkm
       tdvm = Vmax * exp(-Kdes * t) #time-dependent maximum capacity
    end
   
    @dynamics begin
        Central'     = -(Cl / Vc) * Central -(tdvm / (Km + (Central / Vc))) -(Q / Vc) * Central +(Q / Vp) * Peripheral
    Peripheral' = (Q / Vc) * Central -(Q / Vp) * Peripheral
    end
    @derived begin
        cp = @. Central / Vc
        dv ~ @. Normal(cp, sqrt(σ_add^2))
    end
end
ev1 = DosageRegimen(16*70; time = 0, addl =7 , ii = 168, rate= 125) 
ev2 = DosageRegimen(16*70; time = 168*8, addl =7 , ii = 336, rate= 125)
ev_norm = DosageRegimen(ev1, ev2)

s1 = Subject(; id=1, events= ev_norm)
 Random.seed!(123)
 sim_s1 = simobs(
    daramdl,
    s1,
    init_params(daramdl),
    obstimes = 0:24:168*24
) 
simdf = DataFrame(sim_s1) 
lines(simdf.time./ 168, simdf.cp)

Hi Anupama,

Here is an example of how you can add covariates to a model.

pk_model           = @model begin
  @metadata begin
    desc        = "Two Compartment Model"
    timeu       = u"hr"
    amtu        = "mg"
  end

  @param begin
    "Volume of Central Compartment (L)"
    tvvc        ∈ RealDomain(lower=0)
    "Volume of Peripheral Compartment (L)"
    tvvp        ∈ RealDomain(lower=0)
    "InterCompartmental Clearance (L/hour)"
    tvq         ∈ RealDomain(lower=0)
    "Clearance (L/hour)"
    tvcl        ∈ RealDomain(lower=0)
    "Absorption Rate Constant (hour⁻¹)"
    tvka        ∈ RealDomain(lower=0)
    "Fraction of drug absorbed"
    tvfa        ∈ RealDomain(lower=0)
    "Effect of wt on clearance"
    dwtdcl  ∈ RealDomain(lower=0.00001)
    "Effect of wt on volume of distribution"
    dwtdvc  ∈ RealDomain(lower=0.00001)
    Ω           ∈ PDiagDomain(6)
    "Proportional RUV"
    σ_prop     ∈ RealDomain(lower=0)
    "Additive RUV"
    σ_add      ∈ RealDomain(lower=0)
  end

  @random begin
    η           ~ MvNormal(Ω)
  end

  @covariates WT infdur

  @pre begin
    Vc          = tvvc * (WT/70)^dwtdvc * exp(η[1])
    Vp          = tvvp * exp(η[2])
    Q           = tvq  
    CL          = tvcl * (WT/70)^dwtdcl * exp(η[3])
    Ka          = tvka * exp(η[4])
  end

  @dosecontrol begin
    bioav       = (Depot=tvfa * exp(η[5]), Central = 1,)
    duration    = (Central=infdur,) 

  end

  @dynamics Depots1Central1Periph1

  @derived begin
    cp          = @. Central/Vc
    """
    Observed Concentration (mg/L)
    """
    Conc      ~ @. Normal(cp, sqrt((cp*σ_prop)^2 + σ_add^2)) 
  end
end



param1 = ( tvvc    = 17.76,
              tvvp    = 21.54,
              tvq     = 25.04,
              tvcl    = 6.08,
              tvka    = 1.03,
              tvfa    = 0.88,

              dwtdcl  = 0.86,
              dwtdvc  = 1.82,
              Ω       = Diagonal([0.09,0.037,0.015,0.2,0.02,0.066]), 
              σ_prop = 0.105,
              σ_add  = 0.153)

Subject(id = 20, events = DosageRegimen(200, ii = 24, addl = 2), covariates = (WT = 14.2))

Thank you so much. :smiley: