# LKJCholeskyCov with different standard deviation distributions

**URL:** <https://discourse.pymc.io/t/lkjcholeskycov-with-different-standard-deviation-distributions/9617>\
**Category:** v5\
**Created:** [June 11, 2022, 9:31am UTC](https://discourse.pymc.io/t/lkjcholeskycov-with-different-standard-deviation-distributions/9617 "2022-06-11T09:31:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![j\_catulo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/j_catulo/32/4892_2.png) [@j\_catulo](https://discourse.pymc.io/u/j_catulo)\
**Post date:** [June 11, 2022, 9:31am UTC](https://discourse.pymc.io/t/lkjcholeskycov-with-different-standard-deviation-distributions/9617/1 "2022-06-11T09:31:02Z")

</div>

Hi!

I am trying to implement a model with a Multivariate Normal likelihood and I am estimating the covariance matrix using the LKJCholeskyCov prior. However, I would like to define a different distribution for each one of the standard deviations. I read in the [documentation](https://docs.pymc.io/en/latest/api/distributions/generated/pymc.LKJCholeskyCov.html#pymc.LKJCholeskyCov) that the `sd_dist` parameter must be a positive scalar or vector distribution for the standard deviations. So, I am defining a different distribution for each one and I am combining them using `at.stack`.

Here is the code:

```auto
with pm.Model() as model:
  sigmas_dists= [pm.InverseGamma.dist(alpha= 40, beta=80), pm.InverseGamma.dist(alpha= 100, beta=500)]
  stds = at.stack( sigmas_dists )  
    
  
  packed_L = pm.LKJCholeskyCov('packed_L', n=2, eta=2., sd_dist= stds , compute_corr=False)
  L = pm.expand_packed_triangular(2, packed_L)
  cov = L.dot(L.T) 
  
  ...

```

But I am getting the following error

```auto
TypeError: sd_dist must be a scalar or vector distribution variable

```

What am I doing wrong?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [June 11, 2022, 11:14am UTC](https://discourse.pymc.io/t/lkjcholeskycov-with-different-standard-deviation-distributions/9617/2 "2022-06-11T11:14:00Z")

</div>

Try

```python
stds= pm.InverseGamma.dist(alpha= [40, 100], beta=[80, 500]) 
    

```

---

<div class="post-metadata">

**Author:** ![j\_catulo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/j_catulo/32/4892_2.png) [@j\_catulo](https://discourse.pymc.io/u/j_catulo)\
**Post date:** [June 11, 2022, 11:31am UTC](https://discourse.pymc.io/t/lkjcholeskycov-with-different-standard-deviation-distributions/9617/3 "2022-06-11T11:31:15Z")

</div>

It works! Thanks!

---

<div class="post-metadata">

**Author:** ![j\_catulo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/j_catulo/32/4892_2.png) [@j\_catulo](https://discourse.pymc.io/u/j_catulo)\
**Post date:** [July 6, 2022, 5:36pm UTC](https://discourse.pymc.io/t/lkjcholeskycov-with-different-standard-deviation-distributions/9617/4 "2022-07-06T17:36:10Z")

</div>

This works if want do define the same type of distribution for the standard deviations. How do I define the `LKJCholeskyCov` input if I want a different type of distribution for each sigma?

Here is an example:

```auto
with pm.Model() as model:
  sigmas_dists= [pm.InverseGamma.dist(alpha= 40, beta=80), pm.HalfNormal.dist(sigma = 5)]
  stds = at.stack( sigmas_dists )  
    
  
  packed_L = pm.LKJCholeskyCov('packed_L', n=2, eta=2., sd_dist= stds , compute_corr=False)
  L = pm.expand_packed_triangular(2, packed_L)
  cov = L.dot(L.T) 
  
  ...

```

If I do this, I get the following error

```auto
TypeError: sd_dist must be a scalar or vector distribution variable

```

How can I implement this?

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [July 6, 2022, 5:54pm UTC](https://discourse.pymc.io/t/lkjcholeskycov-with-different-standard-deviation-distributions/9617/5 "2022-07-06T17:54:56Z")

</div>

That is currently not allowed, because PyMC needs to be able to resize the `sd_dist` and evaluate it’s logp directly. If you were to pass a stack of distributions as the `sd_dist`, PyMC would not know how to do either of these two things.
