# Size of sd\_dist in LKJCholeskyCov is ambiguous

**URL:** <https://discourse.pymc.io/t/size-of-sd-dist-in-lkjcholeskycov-is-ambiguous/2126>\
**Category:** Questions\
**Created:** [October 30, 2018, 7:01pm UTC](https://discourse.pymc.io/t/size-of-sd-dist-in-lkjcholeskycov-is-ambiguous/2126 "2018-10-30T19:01:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FedericoV](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/federicov/32/3060_2.png) [@FedericoV](https://discourse.pymc.io/u/FedericoV)\
**Post date:** [October 30, 2018, 7:01pm UTC](https://discourse.pymc.io/t/size-of-sd-dist-in-lkjcholeskycov-is-ambiguous/2126/1 "2018-10-30T19:01:00Z")

</div>

Hi everyone,

I looked at the source code and the existing examples for setting the sd\_dist parameter in LKJCholeskyCov and it seems ambiguous.

Here: [https://docs.pymc.io/api/distributions/multivariate.html#pymc3.distributions.multivariate.LKJCholeskyCov](https://docs.pymc.io/api/distributions/multivariate.html#pymc3.distributions.multivariate.LKJCholeskyCov)

```auto
sd_dist = pm.HalfCauchy.dist(beta=2.5)
packed_chol = pm.LKJCholeskyCov('chol_cov', eta=2, n=10, sd_dist=sd_dist)

```

sd\_dist shape is left empty, but n is equal to 10.

Here, however: [https://docs.pymc.io/api/distributions/multivariate.html](https://docs.pymc.io/api/distributions/multivariate.html)

```auto
sd_dist = pm.HalfCauchy.dist(beta=2.5, shape=3)
chol_packed = pm.LKJCholeskyCov('chol_packed',
    n=3, eta=2, sd_dist=sd_dist)

```

It’s slightly unclear to me why shape is 3: assuming this represents a more flexible model where each entry gets its own random variable, then surely the shape shouldn’t be 3 but it should be 3+2+1 (ie, the number of entries for a lower triangular matrix).

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [October 31, 2018, 6:10am UTC](https://discourse.pymc.io/t/size-of-sd-dist-in-lkjcholeskycov-is-ambiguous/2126/2 "2018-10-31T06:10:22Z")

</div>

Actually sd\_dist is only apply to the diagonal (since LKJ is a correlation matrix, we need to add variance parameter to the diagonal), that’s why in the second case it has `shape=3`. But you are right the doc should be more clear - PR welcome 😉

---

<div class="post-metadata">

**Author:** ![FedericoV](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/federicov/32/3060_2.png) [@FedericoV](https://discourse.pymc.io/u/FedericoV)\
**Post date:** [October 31, 2018, 4:20pm UTC](https://discourse.pymc.io/t/size-of-sd-dist-in-lkjcholeskycov-is-ambiguous/2126/3 "2018-10-31T16:20:53Z")

</div>

I’d be glad to do a PR, but I guess I didn’t understand exactly the LKJ formulation then. In the example above, my impression was that sd\_dist was the distribution over the individual entries of the cholesky (which is of dimension 3+2+1).

If sd\_dist is only applied to the diagonal, what’s the prior over the distribution of the off diagonal elements? Is that what is determined by eta?

Finally - am I right in my intuition that sd\_dist = pm.HalfCauchy.dist(beta=2.5, shape=3) corresponds to parametrizing each element of the diagonal with its own value, while sd\_dist = pm.HalfCauchy.dist(beta=2.5) corresponds to tying together the elements of the diagonal to a shared value?

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [October 31, 2018, 8:05pm UTC](https://discourse.pymc.io/t/size-of-sd-dist-in-lkjcholeskycov-is-ambiguous/2126/4 "2018-10-31T20:05:19Z")

</div>

> [@FedericoV](#):
>
> Is that what is determined by eta?

Yes, C∼LKJCorr(η)

> [@FedericoV](#):
>
> am I right in my intuition that sd\_dist = pm.HalfCauchy.dist(beta=2.5, shape=3) corresponds to parametrizing each element of the diagonal with its own value, while sd\_dist = pm.HalfCauchy.dist(beta=2.5) corresponds to tying together the elements of the diagonal to a shared value?

Yes.
