The ggdist
package is very useful for conveying prior assumptions and what those assumptions mean. The vignette here has some examples Slab + interval stats and geoms • ggdist and here’s some example code from a project I just presented
# required libraries: tidyverse, tidybayes, brms, palettetown, latex2exp
main_model_priors <-
prior(student_t(4, 0, 3), class = "b", coef = "Intercept") +
prior(normal(0, 2), class = "b") +
prior(normal(0, 2), class = "gamma") +
prior(cauchy(0, 2.5), class = "sd") +
prior(exponential(0.8), class = "phi") +
prior(lkj(4), class = "cor") +
prior(normal(0, 1), class = "z")
priors_plot <- main_model_priors %>%
parse_dist() %>%
marginalize_lkjcorr(K = 2) %>%
mutate(
distrib = case_when(
prior == "student_t(4, 0, 3)" ~ TeX(r'($\alpha\, \sim \, Student\, T(4, 0, 3)$)', output = "character", italic = T),
prior == "normal(0, 2)" ~ TeX(r'($\gamma_{k} \sim N(0, 2),\, \beta_{k} \, \sim \, N(0, 2)$)', output = "character"),
prior == "exponential(0.8)" ~ TeX(r'($\phi \sim Exponential(0.8)$)', output = "character"),
prior == "cauchy(0, 2.5)" ~ TeX(r'($\sigma_{j} \sim Cauchy_{+}(0, 2.5)$)', output = "character"),
prior == "lkj(4)" ~ TeX(r'($\Omega_{j}\, \sim \, LKJ(4)$)', output = "character"),
prior == "normal(0, 1)" ~ TeX(r'($z_{j} \, \sim \, Normal(0, 1)$)', output = "character")
)
) %>%
ggplot(., aes(dist = .dist, args = .args)) +
facet_wrap(vars(distrib), scales = "free", labeller = label_parsed) +
stat_dist_halfeye(
aes(fill = prior),
n = 10e2,
fill_type = "gradient",
show.legend = F
) +
coord_flip() +
# Set the fill parameter for each group
scale_fill_manual(values = palettetown::pokepal("Suicune", spread = 10)) +
theme_bw(
plot.margin = margin(5, 5, 5, 5, "mm"),
strip.background = element_rect(fill = NA),
strip.text = element_text(family = "serif", size = 14),
axis.text.y = element_blank(),
axis.ticks = element_blank()
)+
labs(
x = "",
title = "",
y = "Log Odds"
)
# Render the priors plot to a file
ggsave(
filename = "Main_Prior_Plot.png",
plot = priors_plot,
device = "png",
path = getwd(),
width = 15,
height = 15,
units = "in",
dpi = "retina",
type = "cairo",
limitsize = FALSE
)
I’ve had some success using visualization to communicate priors to non-statistical/frequentist audiences in terms of assumptions about the universe of possible effect sizes (i.e., in the social sciences we can usually assume a priori that \beta_{k} < |5| and small effects are more likely than large ones).