# Issue with \`constantcoef\` argument

**URL:** <https://discourse.pumas.ai/t/issue-with-constantcoef-argument/965>\
**Category:** Pumas issues\
**Created:** [December 18, 2023, 9:13am UTC](https://discourse.pumas.ai/t/issue-with-constantcoef-argument/965 "2023-12-18T09:13:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmed.salem](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@ahmed.salem](https://discourse.pumas.ai/u/ahmed.salem)\
**Post date:** [December 18, 2023, 9:13am UTC](https://discourse.pumas.ai/t/issue-with-constantcoef-argument/965/1 "2023-12-18T09:13:47Z")

</div>

Hello,

The following code used to work previously

```auto
mod_comb = @model begin
    @param begin
        tvCLinit ~ LogNormal(log(0.5050), 0.1)
        tvCLss ~ LogNormal(log(0.8250), 0.1)
        tvKTV ~ LogNormal(log(0.0200), 0.1)
        circuit ~ LogNormal(log(1.2109), 0.1) 
        tvVc ~ LogNormal(log(0.9667), 0.1)
        Ω₁ ~ Gamma(100,0.003498)
        Ω₂ ~ Gamma(100,0.001186)
        Ω₃ ~ Gamma(100,0.007853)
        Ω₄ ~ Gamma(100, 0.020588)
        σ₁ ~ Gamma(100,0.000404)
        σ₂ ~ Gamma(100,30.33)
        tvα ~ LogNormal(log(117), 0.1)
        tvβ ~ LogNormal(log(0.2), 1.0)
        #Ω₅ ~ Gamma(1,0.1)
        Ω₆ ~ Gamma(1, 0.4)
        σₚ ~ Gamma(1,0.14)
    end
    @random begin
        η₁ ~ Normal(0, sqrt(Ω₁))
        η₂ ~ Normal(0, sqrt(Ω₂))
        η₃ ~ Normal(0, sqrt(Ω₃))
        η₄ ~ Normal(0, sqrt(Ω₄))
        #η₅ ~ Normal(0, sqrt(Ω₅))
        η₆ ~ Normal(0, sqrt(Ω₆))
    end
    @covariates WT AGE_D ISMALE SCR GFR AGEYRS TYPE_MODELING IS_BLEEDING ECMO_DAYS Occassions IS_BLEEDING_UPDATE T IS_CIRCUIT_CHANGE wtcl wtv AGE_GROUP
    @pre begin
        CL_init = tvCLinit *exp(η₁[1]) *wtcl * circuit^IS_CIRCUIT_CHANGE
        CL_SS = tvCLss * exp(η₂[1]) * wtcl * circuit^IS_CIRCUIT_CHANGE
        KTV = tvKTV * exp(η₃[1])
        Vc = tvVc * exp(η₄[1])*wtv
        CL = (CL_SS - (CL_SS - CL_init)*exp(-t* KTV))
        α = tvα #* exp(η₅[1]) 
        β = tvβ * exp(η₆[1]) 
    end

    @dynamics begin
        Central' = - (CL/Vc) * Central
    end
  
    @derived begin
        CP = @. Central / Vc
        E = @. α + β * CP
        CONC ~ @. Normal(CP, sqrt(CP^2*σ₁ + σ₂))
        dv ~ @. Normal(log(E),σₚ)
    end
end

param = (tvCLinit = 0.5049966622948888,
 tvCLss = 0.8250271545772833,
 tvKTV = 0.01997827365729714,
 circuit = 1.2108501441005142,
 tvVc = 0.966746428178601,
 Ω₁ = 0.3498065430622864,
 Ω₂ = 0.11860146947565187,
 Ω₃ = 0.7853131316097821,
 Ω₄ = 2.058839120815329,
 σ₁ = 0.040356031162363054,
 σ₂ = 3033.7781961463684,)

one_cmt_ACT_ecmo_UTAH = @time fit(mod_comb, estimation, init_params(mod_comb), constantcoef = param, Pumas.BayesMCMC(nsamples=2000, 
                                        nadapts=1000,nchains =4,target_accept =0.6, ensemblealg = EnsembleThreads()))

```

This new error appears:

```auto
julia> one_cmt_ACT_ecmo_UTAH = @time fit(mod_comb, estimation, init_params(mod_comb), constantcoef = param, Pumas.BayesMCMC(nsamples=2000, 
                                               nadapts=1000,nchains =4,target_accept =0.6, ensemblealg = EnsembleThreads()))
ERROR: TypeError: in keyword argument constantcoef, expected Tuple{Vararg{Symbol, var"#s97"}} where var"#s97", got a value of type NamedTuple{(:tvCLinit, :tvCLss, :tvKTV, :circuit, :tvVc, :Ω₁, :Ω₂, :Ω₃, :Ω₄, :σ₁, :σ₂), NTuple{11, Float64}}
Stacktrace:
 [1] top-level scope
   @ ./timing.jl:273 [inlined]
 [2] top-level scope
   @ ~/data/code/ECMO_UMMC/BAYESIAN_THESIS.jl:0

```

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![andreasnoack](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/andreasnoack/32/22_2.png) [@andreasnoack](https://discourse.pumas.ai/u/andreasnoack)\
**Post date:** [December 18, 2023, 12:49pm UTC](https://discourse.pumas.ai/t/issue-with-constantcoef-argument/965/2 "2023-12-18T12:49:10Z")

</div>

Hello Ahmed,

This is an unanticipated regression. In version 2.5.0, we introduced a different way to specify parameters to be kept constant during estimation, but the intention was to still allow the old way. However, for Bayesian inference we allowed two different ways of passing `constantcoef`: it could either be passed as an argument to `fit` (like you are doing) and as an argument to `BayesMCMC`. The latter is tested so it should work but unfortunately we didn’t have a test case for the former way of passing the argument. Hence, you should be able to get things working again by writing

```julia
fit(
    mod_comb,
    estimation,
    init_params(mod_comb),
    BayesMCMC(
        nsamples = 2000, 
        nadapts = 1000,
        nchains = 4,
        target_accept = 0.6,
        ensemblealg = EnsembleThreads(),
        constantcoef = param
     )
)

```

Alternatively, you could also use the new way of specifying `constantcoef` via just the parameter name, i.e. by setting `constantcoef = keys(param)`. This version should work both if passed to `fit` and `BayesMCMC`.
