# Hierarchical model hyperparameter for sampling the covariance matrix per site from the LKJ distribution

**URL:** <https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560>\
**Category:** Modeling\
**Created:** [March 29, 2021, 6:35am UTC](https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560 "2021-03-29T06:35:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonis\_Mav](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@Antonis\_Mav](https://discourse.mc-stan.org/u/Antonis_Mav)\
**Post date:** [March 29, 2021, 6:35am UTC](https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560/1 "2021-03-29T06:35:20Z")

</div>

Hi all

I am trying to set up a hierarchical model. My model needs to sample the site-specific mean and covariance between two variables at N different sites, while the mean and covariance also adhere to the global pattern between sites.

I am using the LKJ prior to sample the covariance matrix per site. However, the hyperparameter of the LKJ prior, eta, is only used to define the shape of the marginal distribution of Ri,j, which is always centered around 0 (R is the correlation matrix between my two variables). How can I implement a global hyperparameter, so that the center of the marginal distribution of Ri,j changes, according to the pattern met across sites?

---

<div class="post-metadata">

**Author:** ![Dirk\_Nachbar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dirk_nachbar/32/4271_2.png) [@Dirk\_Nachbar](https://discourse.mc-stan.org/u/Dirk_Nachbar)\
**Post date:** [March 29, 2021, 12:57pm UTC](https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560/2 "2021-03-29T12:57:24Z")

</div>

Maybe you actually want a spatial/GP type model where the cov matrix is informed by the distances between the sites.

eg [https://mc-stan.org/events/stancon2017-notebooks/stancon2017-trangucci-hierarchical-gps.pdf](https://mc-stan.org/events/stancon2017-notebooks/stancon2017-trangucci-hierarchical-gps.pdf)

---

<div class="post-metadata">

**Author:** ![Antonis\_Mav](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@Antonis\_Mav](https://discourse.mc-stan.org/u/Antonis_Mav)\
**Post date:** [March 29, 2021, 1:23pm UTC](https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560/3 "2021-03-29T13:23:04Z")

</div>

Thanks a lot for your response. Unfortnately, I dont see how the GP can be applied in my problem. Essentially, what I need is an LKJ prior that is informative on the centering of the distribution of correlation coefficients in the range of [-1,1].

---

<div class="post-metadata">

**Author:** ![mike-lawrence](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mike-lawrence/32/59_2.png) [@mike-lawrence](https://discourse.mc-stan.org/u/mike-lawrence)\
**Post date:** [March 29, 2021, 5:41pm UTC](https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560/4 "2021-03-29T17:41:50Z")

</div>

See: [Hierarchical Correlation? - #2 by Charles\_Driver](https://discourse.mc-stan.org/t/hierarchical-correlation/8268/2)

---

<div class="post-metadata">

**Author:** ![Charles\_Driver](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/charles_driver/32/6524_2.png) [@Charles\_Driver](https://discourse.mc-stan.org/u/Charles_Driver)\
**Post date:** [March 29, 2021, 5:52pm UTC](https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560/5 "2021-03-29T17:52:53Z")

</div>

But note also that I recently found it can have multimodality issues in higher dim cases and haven’t found a solution :/

---

<div class="post-metadata">

**Author:** ![Antonis\_Mav](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@Antonis\_Mav](https://discourse.mc-stan.org/u/Antonis_Mav)\
**Post date:** [March 30, 2021, 8:23pm UTC](https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560/6 "2021-03-30T20:23:50Z")

</div>

Thank you for your responses.

Following your suggestions, I found this: [Hierarchical prior (for partial pooling) on correlation matrices? - #9 by bgoodri](https://discourse.mc-stan.org/t/hierarchical-prior-for-partial-pooling-on-correlation-matrices/4852/9)  
I believe that this is the best way forward, even though it can be quite time consuming ( I am sampling a 5x5 covariance matrix per unit, and I have 10-200 units).

---

<div class="post-metadata">

**Author:** ![mike-lawrence](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mike-lawrence/32/59_2.png) [@mike-lawrence](https://discourse.mc-stan.org/u/mike-lawrence)\
**Post date:** [March 30, 2021, 8:28pm UTC](https://discourse.mc-stan.org/t/hierarchical-model-hyperparameter-for-sampling-the-covariance-matrix-per-site-from-the-lkj-distribution/21560/7 "2021-03-30T20:28:21Z")

</div>

Take a look at [my explorations of multivariate normal and an alternative here](https://discourse.mc-stan.org/t/feedback-requested-on-possible-subtle-pathology-of-typical-multivariate-specification-or-maybe-bug/21388). I wonder if it could make sense for your application to abandon modelling the correlation matrix as a whole hierarchically, but nonetheless model each individual correlation hierarchically (presumably on the Fisher’s-Z scale).
