Incorporating Inter-Occassion Variability in Bayesian Model

I am trying to incorporate between-occasion variability in Bayesian Model as following

model_bayes_IOV = @model begin
  @param begin
    θ ~ Constrained(
        [2.68, 5.47],
        [1.0 0.0; 0.0 1.0]
      lower = [0.0; 0.0],
      upper = [5.0; 15.0],
      init  = [2.68,5.47])
    Ω ~ InverseWishart(2, [0.345812 -0.490682; -0.490682 4.391050])
    ωκCL ~ Gamma(1.0, 0.3)
    ωκV ~ Gamma(1.0, 0.3)
    σ ~ Gamma(1.0, 0.4459944)

  @random begin
    η ~ MvNormal(Ω)
    κCL ~ MvNormal(4, ωκCL)
    κV ~ MvNormal(4, ωκV)

  @pre begin
    CL = θ[1]*(WT/50)^0.75*exp(η[1]+ κCL[Occassions])
    Vc = θ[2]*(WT/50)*exp(η[2]+ κV[Occassions])*(1 + (0.614*exp(-PNA*(log(2)/9.65)))) 

  @covariates WT PNA Occassions

  @dynamics Central1

  @derived begin
    μ := @. Central / Vc
    CONC ~ @. Normal(μ, μ*σ)

However, I am receiving the following error.

ERROR: ArgumentError: keys(transformations) == keys(y) must hold. Got
keys(transformations) => (:θ, :Ω, :ωκCL, :ωκV, :σ)
keys(y) => (:θ, :Ω, :σ, :ωκCL, :ωκV)
 [1] macro expansion
   @ /builds/PumasAI/PumasSystemImages-jl/.julia/packages/ArgCheck/3oH4Y/src/checks.jl:180 [inlined]
 [2] inverse_eltype
   @ /builds/PumasAI/PumasSystemImages-jl/.julia/packages/TransformVariables/a4AMY/src/aggregation.jl:229 [inlined]
 [3] inverse(t::TransformVariables.TransformTuple{NamedTuple{(:θ, :Ω, :ωκCL, :ωκV, :σ), Tuple{Pumas.ElementArrayTransform{TransformVariables.ScaledShiftedLogistic{Float64}, 1}, Pumas.PSDTransform, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}, TransformVariables.ShiftedExp{true, Float64}}}}, y::NamedTuple{(:θ, :Ω, :σ, :ωκCL, :ωκV), Tuple{Vector{Float64}, Matrix{Float64}, Float64, Float64, Float64}})
   @ TransformVariables /builds/PumasAI/PumasSystemImages-jl/.julia/packages/TransformVariables/a4AMY/src/generic.jl:206
 [4] fit(model::PumasModel{ParamSet{NamedTuple{(:θ, :Ω, :ωκCL, :ωκV, :σ), Tuple{Constrained{FullNormal, VectorDomain{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, InverseWishart{Float64, PDMats.PDMat{Float64, Matrix{Float64}}}, Gamma{Float64}, Gamma{Float64}, Gamma{Float64}}}}, var"#5#17", var"#6#18", var"#8#20", var"#10#22", Central1, var"#11#23", var"#14#26", Nothing}, data::Vector{Subject{NamedTuple{(:CONC,), Tuple{Vector{Union{Missing, Float64}}}}, T2, Vector{Pumas.Event{Float64, Float64, Float64, Float64, Float64, Float64, Int64}}, Vector{Float64}} where T2}, param::NamedTuple{(:θ, :Ω, :σ, :ωκCL, :ωκV), Tuple{Vector{Float64}, Matrix{Float64}, Float64, Float64, Float64}}, ::Pumas.BayesMCMC; target_accept::Float64, nadapts::Int64, nsamples::Int64, progress::Bool, nchains::Int64, rng::Random.MersenneTwister, diffeq_options::NamedTuple{(), Tuple{}})
   @ Pumas /builds/PumasAI/PumasSystemImages-jl/.julia/packages/Pumas/HDuXQ/src/estimation/bayes.jl:127
 [5] top-level scope
   @ REPL[7]:1

It seems that the model is not able to identify sigma. Any suggestion how to modify the code to let it work?


Hi Ahmed,

The sequence of defining the parameters should be same in the param block in the model and when you define the parameter values. In your model the sequence for the param block is (:θ, :Ω, :ωκCL, :ωκV, :σ) and in your set of initial parameter it might be (:θ, :Ω, :σ, :ωκCL, :ωκV) If you rearrange the sequence for the initial parameters. it should work.

Please let me know if it works.

1 Like

Where are you running Pumas? This issue is fixed in Pumas 2.1.

@nikksramwani1, thanks for the suggestion, the fit function works now. I thought that the order does not matter.

@andreasnoack I am using juliahub. Is Pumas 2.1 released ?