# Fixing random effect

**URL:** https://discourse.pumas.ai/t/fixing-random-effect/754
**Category:** maximum-likelihood
**Created:** [September 15, 2022, 4:22pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754 "2022-09-15T16:22:49Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 15, 2022, 4:22pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/1 "2022-09-15T16:22:49Z")

</div>

Hello,

pkfit\_v1\_focei2 = fit(pk\_v1,  
rat\_male\_lowerdose\_dt,  
param\_v1\_newinitial,  
constantcoef=(η[1]=0,),),  
Pumas.FOCEI())

I would like to fix one of the random effects for the FOCEI estimation fitting, and I would receive an following error:  
ERROR: syntax: invalid named tuple field name “η[1]” around /home/jrun/data/code/Rat\_testmod/Version1.jmd:196

I even tried the following using Ω:

```
       fit(pk_v1,
                  rat_male_lowerdose_dt,
                  param_v1_newinitial, 
                  constantcoef=(Ω[1,1]=0,),),
                  Pumas.FOCEI())

```

Hope to hear the response soon. Thank you so much.

---

<div class="post-metadata">

### Author: ![Dawoon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/dawoon/32/179_2.png) [@Dawoon](https://discourse.pumas.ai/u/Dawoon)
#### Post date: [September 15, 2022, 5:45pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/2 "2022-09-15T17:45:13Z")

</div>

Hello,  
I think you can fix your omega by defining all random effects individually rather than using `PDiagDomain` in param block and `MvNormal` in random block.  
I am not sure if we can fix the subset of parameters when we use `PDiagDomain`.  
You can define the random effects in this way.

> @param begin  
> Ω\_cl ∈ RealDomain(lower=0.0001)  
> Ω\_vc ∈ RealDomain(lower=0.0001)

> @random begin  
> η\_cl ~ Normal(0, sqrt(Ω\_cl))  
> η\_vc ~ Normal(0, sqrt(Ω\_vc))

```auto

```

---

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 16, 2022, 2:23pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/3 "2022-09-16T14:23:00Z")

</div>

Hi,

Thank you so much for your response. I would still like to know whether it is feasible to fix the ETA parameters to 0 (removing the random effect for that parameter) I would like to compare the models without defining the model domain.

---

<div class="post-metadata">

### Author: ![Dawoon](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/dawoon/32/179_2.png) [@Dawoon](https://discourse.pumas.ai/u/Dawoon)
#### Post date: [September 16, 2022, 3:41pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/4 "2022-09-16T15:41:02Z")

</div>

Hello,  
Please refer to this link. [Estimating Parameters of Pumas Models · Pumas](https://docs.pumas.ai/stable/basics/estimation/)

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/1cb8e7c36378c698fc841379e30935d88cf6be31.png)

Hope it helps.

---

<div class="post-metadata">

### Author: ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)
#### Post date: [September 16, 2022, 4:18pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/5 "2022-09-16T16:18:31Z")

</div>

@pleasetellme welcome to the community.

1. to fix individual elements, your omegas should be written as Dawoon suggested. i.e. you cannot fix `Ω[1]` when you specified the `random` block as `PDDiagDomain`. (not you don’t fix the ETA, you fix the variance of that ETA distribution)
2. Once you write individual `Normal()` for each Omega via a `RealDomain`, then you can choose to fix parameters directly in the `fit` function using the `constantcoef`, documentation for which you can find [here](https://docs.pumas.ai/stable/basics/estimation/#Maximum-Likelihood-Estimation)  
e.g.

```julia
myfit = fit(mymodel, drug_x_population, drug_x_parameters, Pumas.FOCE(),
            constantcoef = (Ωcl = 0.04, ),
            optimize_fn=DefaultOptimizeFN(show_trace=false,))

```

---

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 16, 2022, 5:42pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/6 "2022-09-16T17:42:04Z")

</div>

Hi,

I did how Dawoon suggested as following. How can I specify the variance covariance matrix when using naive pooled method as it is specified individually? I tried to align all of them and it would not work as wel.

@param begin  
tvka ∈ RealDomain(lower=0)  
tvcl ∈ RealDomain(lower=0)  
tvvc ∈ RealDomain(lower=0)  
tvvp ∈ RealDomain(lower=0)  
tvq ∈ RealDomain(lower=0)  
tvF ∈ RealDomain(lower=0)  
Ω ∈ PDiagDomain(6)  
Ω\_ka ∈ RealDomain(lower=0.0001)  
Ω\_cl ∈ RealDomain(lower=0.0001)  
Ω\_vc ∈ RealDomain(lower=0.0001)  
Ω\_vp ∈ RealDomain(lower=0.0001)  
Ω\_q ∈ RealDomain(lower=0.0001)  
Ω\_F ∈ RealDomain(lower=0.0001)  
σ²\_prop ∈ RealDomain(lower=0)  
end

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/3164ccd8eff60c2c4fc3f30bcaf185f96ac0bab2.png)

Thank you so much in advance.

---

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 16, 2022, 8:46pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/7 "2022-09-16T20:46:56Z")

</div>

I have also tried listing the omegas in such way, and got an error.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/bb78877ff4e9b8ff1f11d91cea1320d6afc57914.png)

---

<div class="post-metadata">

### Author: ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)
#### Post date: [September 16, 2022, 11:24pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/8 "2022-09-16T23:24:22Z")

</div>

I still don’t understand what are you trying to do

---

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 17, 2022, 6:29pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/9 "2022-09-17T18:29:24Z")

</div>

My apologies for not being clear. I am having a hard time figuring out how to specify the omegas after writing the individual Normal() for each omega via RealDomain.

tvka ∈ RealDomain(lower=0)  
tvcl ∈ RealDomain(lower=0)  
tvvc ∈ RealDomain(lower=0)  
tvvp ∈ RealDomain(lower=0)  
tvq ∈ RealDomain(lower=0)  
tvF ∈ RealDomain(lower=0)  
Ω ∈ PDiagDomain(6)  
Ω\_ka ∈ RealDomain(lower=0.0001)  
Ω\_cl ∈ RealDomain(lower=0.0001)  
Ω\_vc ∈ RealDomain(lower=0.0001)  
Ω\_vp ∈ RealDomain(lower=0.0001)  
Ω\_q ∈ RealDomain(lower=0.0001)  
Ω\_F ∈ RealDomain(lower=0.0001)  
σ²\_prop ∈ RealDomain(lower=0)  
end

---

<div class="post-metadata">

### Author: ![bobbrown](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@bobbrown](https://discourse.pumas.ai/u/bobbrown)
#### Post date: [September 17, 2022, 10:08pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/10 "2022-09-17T22:08:36Z")

</div>

@pleasetellme Perhaps this is what you are seeking?

```
@param begin
   ...
    ωcl ∈ RealDomain(lower=0.0)
    ωvc ∈ RealDomain(lower=0.0)

```

…  
end

```
@random begin
    ηcl ~ Normal(0.0, ωcl)
    ηvc ~ Normal(0.0, ωvc)
end

@pre begin
    CL = tvcl * exp(ηcl)
    Vc = tvvc * exp(ηvc)
    ...
 end

```

---

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 17, 2022, 11:56pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/11 "2022-09-17T23:56:19Z")

</div>

> [@pleasetellme](#):
>
> am having a hard time figuring out how to specify the omegas

Thank you for your response. I am having a hard time figuring out how to specify the omegas when using naive.pooled(). How should I specify after omegas= ?

---

<div class="post-metadata">

### Author: ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)
#### Post date: [September 18, 2022, 1:09am UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/12 "2022-09-18T01:09:39Z")

</div>

Naivepooled(NP) algorithms don’t need Omegas. So are you trying to see how to specify which omega to fix in NP?

---

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 18, 2022, 1:24am UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/13 "2022-09-18T01:24:07Z")

</div>

Yes NP algorithm doesn’t need omegas but I believe we need to specify omegas in the code when using fit( , Pumas.NaivePooled(), omegas= HERE ).

---

<div class="post-metadata">

### Author: ![vijay](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pumas.ai/vijay/32/96_2.png) [@vijay](https://discourse.pumas.ai/u/vijay)
#### Post date: [September 18, 2022, 1:45am UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/14 "2022-09-18T01:45:55Z")

</div>

oh… in that case, you just do

```julia
fit(...., omegas = (ωcl , ωvc))

```

---

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 18, 2022, 3:38pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/15 "2022-09-18T15:38:23Z")

</div>

Thank you for your response. I wonder why that method is not working. FOCE is working just fine, but I’m still having trouble trying to run Naivepooled method. Omegas are all defined but I am not sure why it is still giving me that it is not defined. 😢

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/pumas/original/1X/e5d9d92f45da602ec5989c40a3ab870aaeb6f827.png)

---

<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: [September 18, 2022, 3:57pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/16 "2022-09-18T15:57:56Z")

</div>

I am not sure what are you trying to do but why do you need to define omegas in your model?  
Naivepooled analysis considers that all the data comes from one subject so there is no between subject variability to be accounted for in that case. Please let me know if you are trying to do something else

---

<div class="post-metadata">

### Author: ![pleasetellme](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@pleasetellme](https://discourse.pumas.ai/u/pleasetellme)
#### Post date: [September 19, 2022, 4:20pm UTC](https://discourse.pumas.ai/t/fixing-random-effect/754/17 "2022-09-19T16:20:29Z")

</div>

Yes, here is no between subject variability. Yet I believe to use Pumas.NaivePooled() function there is a omegas= condition to must add.  
I am trying to figure out how to specify the omegas condition.
