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

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!

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
}
2 Likes

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.

1 Like

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.

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

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

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.

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.

5 Likes

Thanks!

1 Like