# R package based on rstan -- user-defined prior distributions

**URL:** <https://discourse.mc-stan.org/t/r-package-based-on-rstan-user-defined-prior-distributions/31274>\
**Category:** General\
**Tags:** rstanarm, rstan\
**Created:** [May 2, 2023, 7:51am UTC](https://discourse.mc-stan.org/t/r-package-based-on-rstan-user-defined-prior-distributions/31274 "2023-05-02T07:51:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bourlam](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bourlam/32/15659_2.png) [@Bourlam](https://discourse.mc-stan.org/u/Bourlam)\
**Post date:** [May 2, 2023, 7:51am UTC](https://discourse.mc-stan.org/t/r-package-based-on-rstan-user-defined-prior-distributions/31274/1 "2023-05-02T07:51:20Z")

</div>

I am currently working on an [R package](https://github.com/bernadette-eu/Bernadette) that internally uses rstan with the intention to submit it to CRAN. The package implements the Bayesian hierarchical models for epidemics presented [here](https://aps.arxiv.org/pdf/2211.15229.pdf).

I would like to allow for user-defined prior distributions on the volatility parameters \sigma\_x [Eq. (4)] of multiple diffusions and the dispersion parameter \phi of the Negative Binomial observation model [Eq. (8)].

For instance, I would like to allow for:

- Half-Normal(location, scale)
- Half-Student\_t(df, location, scale)
- Half-Cauchy(location, scale)
- Gamma(shape, rate)
- Exp(1/rate).

I am currently looking at the [stan-dev](https://github.com/stan-dev)/[rstanarm](https://github.com/stan-dev/rstanarm) github repository to understand how to achieve this. In particular, I tried to understand the structure of the [stan\_betareg.R](https://github.com/stan-dev/rstanarm/blob/master/R/stan_betareg.R) functionality, whose internal structure appears to be the following (focusing on the files seemingly appropriate for what I have in mind):

- [stan\_betareg.R](https://github.com/stan-dev/rstanarm/blob/master/R/stan_betareg.R)
  - [rstanarm/priors.R at master · stan-dev/rstanarm · GitHub](https://github.com/stan-dev/rstanarm/blob/master/R/priors.R)
  - [rstanarm/stan\_betareg.fit.R at master · stan-dev/rstanarm · GitHub](https://github.com/stan-dev/rstanarm/blob/master/R/stan_betareg.fit.R)
    - [rstanarm/priors\_betareg.stan at master · stan-dev/rstanarm · GitHub](https://github.com/stan-dev/rstanarm/blob/master/src/stan_files/model/priors_betareg.stan)

Am I right in my understanding? Is this the appropriate functionality to be looking at? I see that [rstanarm/stan\_biglm.R at master · stan-dev/rstanarm · GitHub](https://github.com/stan-dev/rstanarm/blob/master/R/stan_biglm.R) is working at the same way, for instance.

Tagging a few developers for visibility @jgabry, @bgoodri, @andrjohns, @jonah.

Thanks for the awesome work,  
Lampros
