# Hierarchical prior for the regression coefficients

**URL:** <https://discourse.mc-stan.org/t/hierarchical-prior-for-the-regression-coefficients/4582>\
**Category:** brms\
**Created:** [June 20, 2018, 2:26pm UTC](https://discourse.mc-stan.org/t/hierarchical-prior-for-the-regression-coefficients/4582 "2018-06-20T14:26:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpiironen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jpiironen/32/9626_2.png) [@jpiironen](https://discourse.mc-stan.org/u/jpiironen)\
**Post date:** [June 20, 2018, 2:26pm UTC](https://discourse.mc-stan.org/t/hierarchical-prior-for-the-regression-coefficients/4582/1 "2018-06-20T14:26:53Z")

</div>

Hi, I tried to specify a simple hierarchical prior for my model in brms but couldn’t figure out how to do it. Suppose I want to regress y onto x1 and x2 (simple linear regression, no group-level effects or anything). Denote the regression coefficients by b1 and b2. I would like to set prior N(0,tau) for both b1 and b2, so that also tau is treated as unknown (hyper)parameter for which I would like to place a prior (say half-t or half-Cauchy) and which should then be inferred.

Is this possible and how should I do it? I tried using the stanvar function but as far as I understood it cannot be used to declare new parameters, only variables that are passed in as data.

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [June 20, 2018, 6:40pm UTC](https://discourse.mc-stan.org/t/hierarchical-prior-for-the-regression-coefficients/4582/2 "2018-06-20T18:40:34Z")

</div>

With the exception of some specific cases (b1 and b2 relating to the same categoricl variable), I don’t see any build in option for this. But maybe there should be one? Feel free to open an issue on github if you like.

---

<div class="post-metadata">

**Author:** ![jpiironen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jpiironen/32/9626_2.png) [@jpiironen](https://discourse.mc-stan.org/u/jpiironen)\
**Post date:** [June 21, 2018, 6:20am UTC](https://discourse.mc-stan.org/t/hierarchical-prior-for-the-regression-coefficients/4582/3 "2018-06-21T06:20:33Z")

</div>

Thanks for a prompt answer! I now created an issue in Github, as I think this would be a useful feature.

---

<div class="post-metadata">

**Author:** ![jsocolar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jsocolar/32/2486_2.png) [@jsocolar](https://discourse.mc-stan.org/u/jsocolar)\
**Post date:** [November 2, 2021, 8:01pm UTC](https://discourse.mc-stan.org/t/hierarchical-prior-for-the-regression-coefficients/4582/4 "2021-11-02T20:01:48Z")

</div>

Just came across this topic while searching for the answer to a related question. To make the solution discoverable, here is the github issue (now closed; there is a solution!):

> <https://github.com/paul-buerkner/brms/issues/459>
>
> This is a feature suggestion based on my question on discourse (http://discourse….mc-stan.org/t/hierarchical-prior-for-the-regression-coefficients/4582).
> 
> I would like to be able to place a prior on the regression coefficients so that the prior has one or more hyperparameters that will also be given priors and will be inferred. I'm thinking something like allowing user to specify new parameters via function \`\`\`stanvar\`\`\` instead of only declearing variables that will be passed in as data (you will of course know better what is the best way to implement this).
> 
> If it is difficult to implement this in such a generic way as I described above (meaning that virtually any parameters and priors could be formulated), I think it would already be useful to have the normal prior N(0,tau) for which user could specify a hyperprior for tau.
