# Onion method into function?

**URL:** <https://discourse.mc-stan.org/t/onion-method-into-function/30683>\
**Category:** Modeling\
**Created:** [March 9, 2023, 9:18pm UTC](https://discourse.mc-stan.org/t/onion-method-into-function/30683 "2023-03-09T21:18:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Erickson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/richard_erickson/32/5705_2.png) [@Richard\_Erickson](https://discourse.mc-stan.org/u/Richard_Erickson)\
**Post date:** [March 9, 2023, 9:18pm UTC](https://discourse.mc-stan.org/t/onion-method-into-function/30683/1 "2023-03-09T21:18:21Z")

</div>

I am using the Onion method for a problem I’ve previously posted about (e.g., [Using the onion method in occupancy model hierarchical model - Modeling - The Stan Forums (mc-stan.org)](https://discourse.mc-stan.org/t/using-the-onion-method-in-occupancy-model-hierarchical-model/24901)).

Is it possible to encapsulate the “function” to be like the `lkj_corr_cholesky()` function? I have created a simple function (here: [stan\_files/scale\_cholesky\_factor.stan · main · UMESC / quant-ecology / occStan\_hm · GitLab (usgs.gov)](https://code.usgs.gov/umesc/quant-ecology/occstan_hm/-/blob/main/stan_files/scale_cholesky_factor.stan)) but there are still several calls outside of the function.

I would be willing to take a stab, but I cannot find the current `lkj_corr_cholesky()` function in the GitHub page ( e.g., [Search · lkj\_corr\_cholesky (github.com)](https://github.com/stan-dev/stan/search?q=lkj_corr_cholesky)). I am curious about how `lkj_corr_cholesky()` handles probabilities.

In summary my two main questions:

1. Where is the source code for `lkj_corr_cholesky()`?
2. How hard would it be to put the onion method into a function like `lkj_corr_cholesky()`?

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [March 9, 2023, 9:33pm UTC](https://discourse.mc-stan.org/t/onion-method-into-function/30683/2 "2023-03-09T21:33:38Z")

</div>

The source code for the lkj\_corr\_cholkesky distribution lives in the Math library [here](https://github.com/stan-dev/math/blob/b34a81b4ed3a8946ea618e845356cfd49444e382/stan/math/prim/prob/lkj_corr_cholesky_lpdf.hpp)
