Visualizing priors in R

When selecting my prior distributions, and especially determining their distributional parameters, I find it helpful to visualize and compare several options. I was wondering if people have any tips on doing this. Since I use brms, it would be ideal to be able to use the same or similar syntax for specifying the priors.

Toward this goal, I reimplemented many of stan’s univariate distribution functions from this link in R and saved them in a barebones package. This package allows me to visualize and compare distributions quickly:

However, I ran into several questions that I was hoping this community could help me answer:

  1. Is it possible to directly access stan functions and their output from R?
    It was a good learning experience for me to reimplement the stan functions, but this isn’t an ideal solution because its output will mismatch stan’s if updates are made to stan and not to mine.

  2. Can you think of a way to intelligently guess the appropriate range limits for the prior?
    I currently force the user to specify xlim to display or else an uninformative range is defaulted. However, I figure someone smarter than me might know how to look at the function and its arguments itself and intelligently guess at an appropriate range that would capture most of its density. For example, could you automatically (and efficiently) identify the 1st and 99th percentile values?

8 Likes

You would need to write a Stan program with a functions block that wraps a call to the Stan function in order to expose it to R. Make sure that your wrapper functions end with a _rng suffix in order for them to work.

5 Likes

If you map the distribution names to distribution names in R, then you could use quantile function such qnorm in base R (more distributions, e.g. in CRAN Task View: Probability Distributions)

1 Like