venpopov / bmm

An R package for easy and flexible Bayesian Measurement Modeling
https://venpopov.github.io/bmm/
GNU General Public License v2.0
12 stars 3 forks source link

Add `plot` method for `default_priors` #194

Open GidonFrischkorn opened 6 months ago

GidonFrischkorn commented 6 months ago

Discussed in https://github.com/venpopov/bmm/discussions/191

Originally posted by **GidonFrischkorn** March 28, 2024 When I was thinking about the `default_priors` for the `m3`, I thought having an easy way of plotting the `default_priors` on the parameters and native scale would be nice. I was thinking about something similar to the plots you generated for the "extract info" vignette. What do you think about this?

Create a plot method for the default_priors generated for bmmodel. Potentially see if the plot method can be generalized to the output class of default_priors and also work for brms models

venpopov commented 6 months ago

When I was thinking about this some time ago, I thought that this package will be very useful: https://pkg.mitchelloharawild.com/distributional/index.html

venpopov commented 6 months ago

Yes, I think that package will be super useful. Here's a super basic example of how we could use it for this:

library(distributional)
library(ggdist)
library(ggplot2)
library(brms)

# basic functionality with distributional explicit functions
dist <- dist_normal()
dist2 <- exp(dist).  # you can apply transformations!

# visualize both distributions
ggplot() +
  stat_slabinterval(aes(dist = dist), orientation = "horizontal")
ggplot() +
  stat_slabinterval(aes(dist = dist2), orientation = "horizontal")

# can extract the distribution from the prior and do the same
prior <- set_prior("normal(2, 1)", class = "Intercept")
dprior <- prior$prior
dprior <- paste0("distributional::dist_", dprior)

dist_prior <- eval(parse(text = dprior))

ggplot() +
  stat_slabinterval(aes(dist = dist_prior), orientation = "horizontal")

image

venpopov commented 6 months ago

I have a prototype ready, but it needs polishing. I'll open a draft pr so you can take a look at what it looks like right now

GidonFrischkorn commented 6 months ago

Looking forward to checking this out! I saw that you also were in contact with the developers of the distributions package ☺️

venpopov commented 6 months ago

yeah, I had the prototype working on the weekend, but then noticed some problems related to transformations of priors to the native scale, so I've been working with them to fix them :)