Ppc_dens_overlay: how can I get rid of the thick blue line?

Hi
I would like to use “ppc_dens_overlay()” to display prior predictive distributions, but it requires the user to add a vector y along with the matrix with draws yrep. Is there a way to run ppc_dens_overlay without having to display y? Or maybe make it invisible? If there is a better alternative to ppc_dens_overlay() I’m also happy to try it

This is the code I’m using right now:

yrep<-as.matrix(ppd,"prior_draws")
y<-data$y
ppc_dens_overlay(y,yrep[1:500,])

and this is the result

I would like to get rid of the thick blue line

Thanks

This is a bit of a hack, but you can use ppc_data and build the density plot yourself:

library(bayesplot)
#> This is bayesplot version 1.7.2.9000
#> - Online documentation and vignettes at mc-stan.org/bayesplot
#> - bayesplot theme set to bayesplot::theme_default()
#>    * Does _not_ affect other ggplot2 plots
#>    * See ?bayesplot_theme_set for details on theme setting
library(ggplot2)

y <- example_y_data()
y_rep <- example_yrep_draws()

ppc_data <- ppc_data(
  y, 
  y_rep
)

ggplot(ppc_data, aes(x = value, group = rep_id)) +
  geom_density(col = alpha(color_scheme_get()[3], 0.2)) +
  bayesplot_theme_get()

Created on 2020-11-09 by the reprex package (v0.3.0)

Good question @fsdias and thanks @hhau for the nice solution. There’s actually a branch of bayesplot on GitHub that adds versions of many of the bayesplot functions but without taking a y argument. These functions start with prefix ppd_ instead of ppc_ since they’re just plots of the predictive distribution with no “checking” against data:

If you want to try using that branch then you can install it with

devtools::install_github("stan-dev/bayesplot", ref = "ppd-functions")

I’m not entirely sure if/when this will make it into a bayesplot release since it’s a huge PR that still needs to be reviewed, but I think it should be working properly if you try it out.

1 Like

Thanks @jonah. Fully functional as far as I can tell. I hope this branch is merged soon!

1 Like