# Fixing parameters using ConstDomain

**URL:** <https://discourse.pumas.ai/t/fixing-parameters-using-constdomain/68>\
**Category:** Estimation\
**Created:** [November 14, 2019, 5:13am UTC](https://discourse.pumas.ai/t/fixing-parameters-using-constdomain/68 "2019-11-14T05:13:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.pumas.ai/u/madhu)\
**Post date:** [November 14, 2019, 5:13am UTC](https://discourse.pumas.ai/t/fixing-parameters-using-constdomain/68/1 "2019-11-14T05:13:46Z")

</div>

hi -  
My first post here 🙂 I understand from the documentation that `ConstDomain()` is equivalent to fixing a parameter during estimation. I am confused on how to use it, especially if I follow the example in the Readme of the github page. Let’s say I would like to fix `pmoncl` in that example model [here](https://github.com/PumasAI/Pumas.jl) . So, instead of

```auto
  @param begin
    tvcl ∈ RealDomain(lower=0)
    tvv ∈ RealDomain(lower=0)
    pmoncl ∈ RealDomain(lower = -0.99)
    Ω ∈ PDiagDomain(2)
    σ_prop ∈ RealDomain(lower=0)
  end

```

I would do this

```auto
  @param begin
    tvcl ∈ RealDomain(lower=0)
    tvv ∈ RealDomain(lower=0)
    pmoncl ∈ ConstDomain(-0.6)
    Ω ∈ PDiagDomain(2)
    σ_prop ∈ RealDomain(lower=0)
  end

```

note that I fixed the value to -0.6. My main question is how to specify the parameter for `pmoncl` in the parameter vector that is used outside the model.

```auto
param = (
  tvcl = 4.0,
  tvv = 70,
  pmoncl = -0.6,
  Ω = Diagonal([0.09,0.09]),
  σ_prop = 0.04
  )

```

During simulation, this should not matter. But what do I specify for `pmoncl` (or should I specify anything at all) when passing this parameter vector into a `fit` object? Should I use `ConstDomain` here too? What will take precedence?

Hope I am clear!

Madhu.

---

<div class="post-metadata">

**Author:** ![pkofod](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/pkofod/32/59_2.png) [@pkofod](https://discourse.pumas.ai/u/pkofod)\
**Post date:** [November 14, 2019, 4:06pm UTC](https://discourse.pumas.ai/t/fixing-parameters-using-constdomain/68/2 "2019-11-14T16:06:20Z")

</div>

I think that you should just avoid ConstDomain to be completely honest. Here is a simple example where I simulate using a value of 1 for the volume of distribution estimate. Then I estimate using no restrictions, and after that I restrict the parameter for volume of distribution to be 4.0 instead. I use NaivePooled() because there are no random effects.

I hope it helps!

```auto
using Pumas, Query
model = @model begin
    @param begin
        θCL ∈ RealDomain(lower=0.01, upper=10.0)
        θV ∈ RealDomain(lower=0.01, upper=10.0)
        σ ∈ RealDomain(init= 0.10, lower=0.01, upper = 1.0)
    end
    @pre begin
        CL = θCL
        V = θV
    end
    @dynamics ImmediateAbsorptionModel
    @derived begin
        cp = @. (Central / (V/1000))
        dv ~ @. Normal(cp, sqrt(σ))
    end
end
param = (θCL=1.0, θV = 1.0, σ = 0.06)
D = DosageRegimen(40, cmt=1, time=0, ii=12, addl=0, rate=0)
pop = Population(map(i -> Subject(id=i, evs=D),1:15))
_simobs = simobs(model, pop, param)
simdf = DataFrame(_simobs) |> @filter(!(_.evid == 0 &&_.time==0)) |> DataFrame
data = read_pumas(simdf)

fpm = fit(model, data, param, Pumas.NaivePooled())
fpm = fit(model, data, param, Pumas.NaivePooled(); constantcoef=(θV=4.0,))

```

It should output something like:

```auto
julia> fpm = fit(model, data, param, Pumas.NaivePooled())
FittedPumasModel

Successful minimization: true

Likelihood approximation: Pumas.NaivePooled
Objective function value: 11.050267
Total number of observation records: 360
Number of active observation records: 360
Number of subjects: 15

------------------
        Estimate
------------------
θCL 1.0
θV 0.99999
σ 0.062257
------------------

julia> fpm = fit(model, data, param, Pumas.NaivePooled(); constantcoef=(θV=4.0,))
FittedPumasModel

Successful minimization: true

Likelihood approximation: Pumas.NaivePooled
Objective function value: 5.1780445e8
Total number of observation records: 360
Number of active observation records: 360
Number of subjects: 15

-----------------
        Estimate
-----------------
θCL 1.4347
θV 4.0
σ 1.0
-----------------

```

---

<div class="post-metadata">

**Author:** ![madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@madhu](https://discourse.pumas.ai/u/madhu)\
**Post date:** [November 14, 2019, 4:20pm UTC](https://discourse.pumas.ai/t/fixing-parameters-using-constdomain/68/3 "2019-11-14T16:20:01Z")

</div>

Thanks for the response,@pkofod! I am using JuliaPro with Pumas at v0.5 I think. Is this `constantcoef` feature available? From what I am reading, I see that there is no way to assign the value of a variable to be a constant in the model? e.g. can I set the value of `Vc` to be `1` in the `@pre` block as `Vc=1` and use it downstream in the model and never worry about using `constantcoef` or `ConstantDomain`?

---

<div class="post-metadata">

**Author:** ![pkofod](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/pkofod/32/59_2.png) [@pkofod](https://discourse.pumas.ai/u/pkofod)\
**Post date:** [November 14, 2019, 7:05pm UTC](https://discourse.pumas.ai/t/fixing-parameters-using-constdomain/68/4 "2019-11-14T19:05:40Z")

</div>

Okay, then you’d want to use ConstDomain, but if you do that, then you cannot use another value later, that sort of goes with the name 🙂 And maybe this is what you’re asking: yes you have to include it in param with the same value (also slightly annoying imo, that’s why I prefer the constantcoef).

I’d just put it in pre then I guess

```auto
model = @model begin
    @param begin
        θCL ∈ RealDomain(lower=0.01, upper=10.0)
        σ ∈ RealDomain(init= 0.10, lower=0.01, upper = 1.0)
    end
    @pre begin
        CL = θCL
        V = 1.0
    end
    @dynamics ImmediateAbsorptionModel
    @derived begin
        cp = @. (Central / (V/1000))
        dv ~ @. Normal(cp, sqrt(σ))
    end
end
param = (θCL=1.0, θV = 1.0, σ = 0.06)
D = DosageRegimen(40, cmt=1, time=0, ii=12, addl=0, rate=0)
pop = Population(map(i -> Subject(id=i, evs=D),1:15))
_simobs = simobs(model, pop, param)
simdf = DataFrame(_simobs) |> @filter(!(_.evid == 0 &&_.time==0)) |> DataFrame
data = read_pumas(simdf)

fpm = fit(model, data, param, Pumas.NaivePooled())

```
