Covariates in SAEM

I’ve been trying to diagnose the error I’m getting with this SAEM model and can’t seem to figure it out. Would somebody mind taking a look to see if I am missing something? The following model runs without issue:

saem_nocov = @emmodel begin

    @random begin
        # parent
        CL        ~ 1 | LogNormal
        Vc        ~ 1 | LogNormal
        Q1        ~ 1 | LogNormal
        Vp1       ~ 1 | LogNormal
        Q2        ~ 1 | LogNormal
        Vp2       ~ 1 | LogNormal
        # metabolites 
        Q_gluc    ~ 1 | LogNormal
        CL_gluc   ~ 1 | LogNormal
        V_gluc    ~ 1 | LogNormal
        Q_methyl  ~ 1 | LogNormal
        CL_methyl ~ 1 | LogNormal
        V_methyl  ~ 1 | LogNormal
    end

    
    @dynamics begin 
        Central'     = -(CL/Vc)*Central + (Q1/Vp1)*Peripheral1 - (Q1/Vc)*Central + (Q2/Vp2)*Peripheral2 - (Q2/Vc)*Central - (Q_gluc/Vc)*Central - (Q_methyl/Vc)*Central 
        Peripheral1' =                  - (Q1/Vp1)*Peripheral1 + (Q1/Vc)*Central 
        Peripheral2' =                                                           - (Q2/Vp2)*Peripheral2 + (Q2/Vc)*Central 
        Gluc'        =  (Q_gluc/Vc)*Central   - (CL_gluc/V_gluc)*Gluc
        Methyl'      =  (Q_methyl/Vc)*Central - (CL_methyl/V_methyl)*Methyl
    end 
    
    @post begin
        CONC        = Central/Vc
        CONC_GLUC   = Gluc/V_gluc 
        CONC_METHYL = Methyl/V_methyl 
    end
  
    @error begin
      DV        ~ Normal(CONC)
      DV_GLUC   ~ Normal(CONC_GLUC)
      DV_METHYL ~ Normal(CONC_METHYL)
    end
end

But when I try to scale central clearance for weight with the model below - I get an error that states " ERROR: UndefVarError: Vc not defined
Stacktrace:
[1] top-level scope
@ /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/HDuXQ/src/dsl/emmodel_macro.jl:47"


saem_cov = @emmodel begin

    @random begin
        # parent
        _CL       ~ 1 | LogNormal
        Vc        ~ 1 | LogNormal
        Q1        ~ 1 | LogNormal
        Vp1       ~ 1 | LogNormal
        Q2        ~ 1 | LogNormal
        Vp2       ~ 1 | LogNormal
        # metabolites 
        Q_gluc    ~ 1 | LogNormal
        CL_gluc   ~ 1 | LogNormal
        V_gluc    ~ 1 | LogNormal
        Q_methyl  ~ 1 | LogNormal
        CL_methyl ~ 1 | LogNormal
        V_methyl  ~ 1 | LogNormal
    end

    @covariates WT

    @pre begin
        CL = _CL*(WT/70)^0.75
    end

    @dynamics begin 
        Central'     = -(CL/Vc)*Central + (Q1/Vp1)*Peripheral1 - (Q1/Vc)*Central + (Q2/Vp2)*Peripheral2 - (Q2/Vc)*Central - (Q_gluc/Vc)*Central - (Q_methyl/Vc)*Central 
        Peripheral1' =                  - (Q1/Vp1)*Peripheral1 + (Q1/Vc)*Central 
        Peripheral2' =                                                           - (Q2/Vp2)*Peripheral2 + (Q2/Vc)*Central 
        Gluc'        =  (Q_gluc/Vc)*Central   - (CL_gluc/V_gluc)*Gluc
        Methyl'      =  (Q_methyl/Vc)*Central - (CL_methyl/V_methyl)*Methyl
    end 
    
    @post begin
        CONC        = Central/Vc
        CONC_GLUC   = Gluc/V_gluc 
        CONC_METHYL = Methyl/V_methyl 
    end
  
    @error begin
      DV        ~ CombinedNormal(CONC)
      DV_GLUC   ~ CombinedNormal(CONC_GLUC)
      DV_METHYL ~ CombinedNormal(CONC_METHYL)
    end
end

If it helps, this more simple model (without metabolites) is also scaled for weight and DOES run without error:

demo_saem_cov = @emmodel begin

    @random begin
        Ka  ~ 1 | LogNormal
        _CL ~ 1 | LogNormal
        Vc  ~ 1 | LogNormal
    end

    @covariates WT

    @pre begin
        CL = _CL*(WT/70)
    end

    @dynamics Depots1Central1

    @post begin
        μ = Central/Vc
    end

    @error begin
        dv ~ CombinedNormal(μ)
    end
end

@adunn34 this seems to be a bug (@vijay - please note). I just tried to define two models and I am getting an error for mod2. The only difference between mod1 and mod2 is only the @dynamics block.

mod1 = @emmodel begin
    @random begin
        cl ~ 1  | LogNormal
        Vc  ~ 1 | LogNormal
    end
    @covariates WT
    @pre begin
        CL = cl * (WT/70)
    end
    @dynamics Central1
    @post begin
        CONC_        = Central/Vc
    end
    @error begin
        CONC        ~ CombinedNormal(CONC_)
    end
end

mod2 = @emmodel begin
    @random begin
        cl  ~ 1  | LogNormal
        Vc  ~ 1 | LogNormal
    end
    @covariates WT
    @pre begin
        CL = cl * (WT/70)
    end
    @dynamics begin 
        Central'     = -(CL/Vc)*Central
    end 
    @post begin
        CONC_        = Central/Vc
    end
    @error begin
        CONC        ~ CombinedNormal(CONC_)
    end
end

This was indeed a bug in the Pumas 2.0.x versions but, fortunately, the bug has been fixed in Pumas version 2.1.0. I believe the upgrade of your JuliaHub instance is right around the corner so you should soon be able to run these models.

1 Like