Posterior_vs_prior function for stanfit object

Hello Discourses,

I wanted to overlay the priors of my custom model onto the posterior distributions after running the rstan function. However, I have not found a way to plot the priors of a Stan model (class object stanfit). There are functions for S3 objects generated using rstanarm but I could not apply them to a stanfit object (e.g., posterior_vs_prior()). I have also tried to access prior information in the same manner as for the extraction of the posterior draws (e.g., extract()) but I have not been successful.


  1. Is there a R function that can be used to extract prior distributions and/or plot prior distributions on top of the posteriors of a stanfit object?

  2. If there is not such a function, can I just use the following R code to recreate the beta distribution that I have defined in Stan?

grid = seq(0, 1, .01)
plot(grid,dbeta(grid, shape1 = 6, shape2 = 10), type="l", xlab="x", ylab="f(x)")


The functions in rstanarm such as posterior_vs_prior only work for models fit by rstanarm. You would have to make your own plots if you write a model by hand in Stan. I might start with

curve(dbeta(x, shape1 = 6, shape2 = 10), from = 0, to = 1)

Create a new stan model where you can do prior / prior predictive sampling. (E.g. skip inference parts).

Yes @ahartikainen, this is what I was hoping to get but I am not familiar with the subject of prior predictive sampling. I had a quick look around and I found this and this link.
Am I on the right track?
Would you have a better reference?