# How to get a summary of the prior distributions from a fitted Stan model

**URL:** <https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856>\
**Category:** Interfaces\
**Tags:** rstan\
**Created:** [January 29, 2020, 12:53am UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856 "2020-01-29T00:53:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yanlingli1](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yanlingli1/32/5694_2.png) [@yanlingli1](https://discourse.mc-stan.org/u/yanlingli1)\
**Post date:** [January 29, 2020, 12:53am UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/1 "2020-01-29T00:53:12Z")

</div>

Operating System: Windows 10  
Interface Version: rstan 2.19.2  
Compiler/Toolkit: Rtools 3.4

Is there a way to retrieve the prior distributions from a fitted Stan model as returned by the function stan() in rstan package? In rstanarm, functions such as prior\_summary() and posterior\_vs\_prior() can provide a summary of user-specified priors or priors used internally by rstanarm. Can we also do it in rstan?

Thanks!

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [January 29, 2020, 5:03am UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/2 "2020-01-29T05:03:41Z")

</div>

No. If you write your own Stan program, then the interface (R in this case) has no idea what the Stan program is doing when it draws from the implied posterior distribution. In rstanarm and brms, the maintainers know what the models are and can write an R representation of them. Nevertheless, `posterior_vs_prior` and whatnot utilize draws from the prior distribution, which is easy to obtain either by drawing from known distributions or by running a similar Stan program where the likelihood contribution has been commented out or wrapped in a construct such as

```
if (prior_only = 0) { // prior_only is a flag defined in the data block
  target += ...; // the log-likelihood
}

```

---

<div class="post-metadata">

**Author:** ![Zita\_Oravecz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zita_oravecz/32/7034_2.png) [@Zita\_Oravecz](https://discourse.mc-stan.org/u/Zita_Oravecz)\
**Post date:** [January 30, 2020, 5:38pm UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/3 "2020-01-30T17:38:06Z")

</div>

Thank you so much Ben! To be a bit more specific, in our code we do not assign a prior distribution to one of the parameters but let Stan set a (what we assume is) some kind of default prior. Is there any information on what that is in the Stan object or in the Stan documentation? Or could you give us a quick idea how that is decided about? We were not able to find information about that other than it is -infinity to + infinity, but we do not think this is what is happening in our model.

---

<div class="post-metadata">

**Author:** ![mcol](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mcol/32/5598_2.png) [@mcol](https://discourse.mc-stan.org/u/mcol)\
**Post date:** [January 30, 2020, 5:49pm UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/4 "2020-01-30T17:49:26Z")

</div>

If you don’t assign a prior to a parameter, it will be given a uniform prior. This is OK as long as it leads to a proper posterior, but it’s not guaranteed.

---

<div class="post-metadata">

**Author:** ![Zita\_Oravecz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zita_oravecz/32/7034_2.png) [@Zita\_Oravecz](https://discourse.mc-stan.org/u/Zita_Oravecz)\
**Post date:** [January 30, 2020, 5:57pm UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/5 "2020-01-30T17:57:19Z")

</div>

Thank you – uniform on what range? -infinity to + infinity?

---

<div class="post-metadata">

**Author:** ![mcol](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mcol/32/5598_2.png) [@mcol](https://discourse.mc-stan.org/u/mcol)\
**Post date:** [January 30, 2020, 6:02pm UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/6 "2020-01-30T18:02:57Z")

</div>

If you don’t have bounds on that parameter, it will be from -inf to +inf.

---

<div class="post-metadata">

**Author:** ![Zita\_Oravecz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zita_oravecz/32/7034_2.png) [@Zita\_Oravecz](https://discourse.mc-stan.org/u/Zita_Oravecz)\
**Post date:** [January 30, 2020, 6:18pm UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/7 "2020-01-30T18:18:12Z")

</div>

Thanks - we don’t set bounds. It’s actually a parameter we are using to fill out missing data entries. And this default prior worked very well in our simulation studies actually (better than what we had originally), so my initial guess was that it was a weakly informative one, since the Stan community generally recommends those.

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [January 30, 2020, 6:52pm UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/8 "2020-01-30T18:52:43Z")

</div>

> [@Zita\_Oravecz](#):
>
> my initial guess was that it was a weakly informative one, since the Stan community generally recommends those.

Even weakly informative needs some information and thus by default there is no prior, but we recommend that you should assign some proper prior (integrates to finite value) for every parameter, as the dangers of not doing that are bigger than the effort to choose some priors.

---

<div class="post-metadata">

**Author:** ![Zita\_Oravecz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/zita_oravecz/32/7034_2.png) [@Zita\_Oravecz](https://discourse.mc-stan.org/u/Zita_Oravecz)\
**Post date:** [January 30, 2020, 8:28pm UTC](https://discourse.mc-stan.org/t/how-to-get-a-summary-of-the-prior-distributions-from-a-fitted-stan-model/12856/9 "2020-01-30T20:28:02Z")

</div>

Thanks!
