From 3db5324be0b055952a7da5ba4984b245745cb33b Mon Sep 17 00:00:00 2001 From: ishaan-arora-1 Date: Wed, 11 Mar 2026 03:07:50 +0530 Subject: [PATCH 1/3] Add prior predictive checking section to PPC vignette Added a section explaining that the same ppc_* functions can be used for prior predictive checks by passing draws from the prior predictive distribution. Includes a rstanarm example with prior_PD = TRUE and mentions the ppd_* functions for cases where you don't want to compare to observed data. Advances #196 --- tests/vdiffr.Rout.fail | 96 ++++++++++++++++++++++++++++++++++++ vignettes/graphical-ppcs.Rmd | 39 +++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 tests/vdiffr.Rout.fail diff --git a/tests/vdiffr.Rout.fail b/tests/vdiffr.Rout.fail new file mode 100644 index 00000000..42cf6e86 --- /dev/null +++ b/tests/vdiffr.Rout.fail @@ -0,0 +1,96 @@ +Environment: +- vdiffr-svg-engine: 2.0 +- vdiffr: 1.0.9 + + +Failed doppelganger: mcmc-rhat-default (/Users/ashish/bayesplot/tests/testthat/_snaps/mcmc-diagnostics/mcmc-rhat-default.svg) + +< before +> after +@@ 46,6 / 46,6 @@ + + +< +> +< +> + + + + +Failed doppelganger: mcmc-rhat-sized (/Users/ashish/bayesplot/tests/testthat/_snaps/mcmc-diagnostics/mcmc-rhat-sized.svg) + +< before +> after +@@ 46,6 / 46,6 @@ + + +< +> +< +> + + + + +Failed doppelganger: mcmc-neff-default (/Users/ashish/bayesplot/tests/testthat/_snaps/mcmc-diagnostics/mcmc-neff-default.svg) + +< before +> after +@@ 66,7 / 66,7 @@ + + +< +> +< +> +< +> + + + + +Failed doppelganger: mcmc-neff-missing-levels (/Users/ashish/bayesplot/tests/testthat/_snaps/mcmc-diagnostics/mcmc-neff-missing-levels.svg) + +< before +> after +@@ 34,7 / 34,7 @@ + + +< +> +< +> +< +> + + + diff --git a/vignettes/graphical-ppcs.Rmd b/vignettes/graphical-ppcs.Rmd index db649f42..eb73b385 100644 --- a/vignettes/graphical-ppcs.Rmd +++ b/vignettes/graphical-ppcs.Rmd @@ -314,6 +314,45 @@ See Figure 8 in [Gabry et al. (2019)](#gabry2019) for another example of using
+## Using PPC plots for prior predictive checking + +Although this vignette focuses on *posterior* predictive checking, the same +`ppc_*` functions can be used for **prior** predictive checking as well. The +idea is the same: instead of passing draws from the posterior predictive +distribution as `yrep`, you pass draws from the **prior** predictive +distribution. This can be useful for understanding the implications of your +priors before conditioning on the data (see Gabry et al. (2019) for more on +when prior predictive checks are useful). + +For example, with **rstanarm** you can obtain prior predictive draws using +`posterior_predict()` on a model fit with `prior_PD = TRUE`: + +```{r prior-pd, eval=FALSE} +fit_prior <- stan_glm( + y ~ roach100 + treatment + senior, + offset = log(exposure2), + family = poisson, + data = roaches, + prior_PD = TRUE # sample from prior predictive only +) +yrep_prior <- posterior_predict(fit_prior) + +# use the same ppc_ functions with prior predictive draws +ppc_dens_overlay(y, yrep_prior[1:50, ]) +ppc_stat(y, yrep_prior, stat = "mean") +``` + +If you want to examine the prior predictive distribution *without* comparing to +observed data, you can use the `ppd_*` functions (PPD = prior/posterior +predictive distribution) instead: + +```{r ppd-example, eval=FALSE} +ppd_dens_overlay(yrep_prior[1:50, ]) +ppd_stat(yrep_prior, stat = "mean") +``` + +
+ ## Providing an interface to bayesplot PPCs from another package The **bayesplot** package provides the S3 generic function `pp_check`. Authors of From 15bdd4d70787b3730f41ff54b1fec0a3f9568377 Mon Sep 17 00:00:00 2001 From: ishaan-arora-1 Date: Wed, 11 Mar 2026 03:07:58 +0530 Subject: [PATCH 2/3] Remove stale test artifact --- tests/vdiffr.Rout.fail | 96 ------------------------------------------ 1 file changed, 96 deletions(-) delete mode 100644 tests/vdiffr.Rout.fail diff --git a/tests/vdiffr.Rout.fail b/tests/vdiffr.Rout.fail deleted file mode 100644 index 42cf6e86..00000000 --- a/tests/vdiffr.Rout.fail +++ /dev/null @@ -1,96 +0,0 @@ -Environment: -- vdiffr-svg-engine: 2.0 -- vdiffr: 1.0.9 - - -Failed doppelganger: mcmc-rhat-default (/Users/ashish/bayesplot/tests/testthat/_snaps/mcmc-diagnostics/mcmc-rhat-default.svg) - -< before -> after -@@ 46,6 / 46,6 @@ - - -< -> -< -> -
- - - -Failed doppelganger: mcmc-rhat-sized (/Users/ashish/bayesplot/tests/testthat/_snaps/mcmc-diagnostics/mcmc-rhat-sized.svg) - -< before -> after -@@ 46,6 / 46,6 @@ - - -< -> -< -> - - - - -Failed doppelganger: mcmc-neff-default (/Users/ashish/bayesplot/tests/testthat/_snaps/mcmc-diagnostics/mcmc-neff-default.svg) - -< before -> after -@@ 66,7 / 66,7 @@ - - -< -> -< -> -< -> - - - - -Failed doppelganger: mcmc-neff-missing-levels (/Users/ashish/bayesplot/tests/testthat/_snaps/mcmc-diagnostics/mcmc-neff-missing-levels.svg) - -< before -> after -@@ 34,7 / 34,7 @@ - - -< -> -< -> -< -> - - - From 3fc3acfbc524fa708171d1516e8debc03618f04a Mon Sep 17 00:00:00 2001 From: ishaan-arora-1 Date: Wed, 11 Mar 2026 03:11:50 +0530 Subject: [PATCH 3/3] Move prior predictive section to avoid conflict with PR #439 Placed the section after "Providing an interface" and before "References" so it doesn't conflict with the *_data() section that PR #439 adds at line 315. --- vignettes/graphical-ppcs.Rmd | 78 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/vignettes/graphical-ppcs.Rmd b/vignettes/graphical-ppcs.Rmd index eb73b385..116bba6b 100644 --- a/vignettes/graphical-ppcs.Rmd +++ b/vignettes/graphical-ppcs.Rmd @@ -314,45 +314,6 @@ See Figure 8 in [Gabry et al. (2019)](#gabry2019) for another example of using
-## Using PPC plots for prior predictive checking - -Although this vignette focuses on *posterior* predictive checking, the same -`ppc_*` functions can be used for **prior** predictive checking as well. The -idea is the same: instead of passing draws from the posterior predictive -distribution as `yrep`, you pass draws from the **prior** predictive -distribution. This can be useful for understanding the implications of your -priors before conditioning on the data (see Gabry et al. (2019) for more on -when prior predictive checks are useful). - -For example, with **rstanarm** you can obtain prior predictive draws using -`posterior_predict()` on a model fit with `prior_PD = TRUE`: - -```{r prior-pd, eval=FALSE} -fit_prior <- stan_glm( - y ~ roach100 + treatment + senior, - offset = log(exposure2), - family = poisson, - data = roaches, - prior_PD = TRUE # sample from prior predictive only -) -yrep_prior <- posterior_predict(fit_prior) - -# use the same ppc_ functions with prior predictive draws -ppc_dens_overlay(y, yrep_prior[1:50, ]) -ppc_stat(y, yrep_prior, stat = "mean") -``` - -If you want to examine the prior predictive distribution *without* comparing to -observed data, you can use the `ppd_*` functions (PPD = prior/posterior -predictive distribution) instead: - -```{r ppd-example, eval=FALSE} -ppd_dens_overlay(yrep_prior[1:50, ]) -ppd_stat(yrep_prior, stat = "mean") -``` - -
- ## Providing an interface to bayesplot PPCs from another package The **bayesplot** package provides the S3 generic function `pp_check`. Authors of @@ -423,6 +384,45 @@ Several packages currently use this approach to provide an interface to and [**brms**](https://CRAN.R-project.org/package=brms) packages. +
+ +## Using PPC plots for prior predictive checking + +Although this vignette focuses on *posterior* predictive checking, the same +`ppc_*` functions can be used for **prior** predictive checking as well. The +idea is the same: instead of passing draws from the posterior predictive +distribution as `yrep`, you pass draws from the **prior** predictive +distribution. This can be useful for understanding the implications of your +priors before conditioning on the data (see Gabry et al. (2019) for more on +when prior predictive checks are useful). + +For example, with **rstanarm** you can obtain prior predictive draws using +`posterior_predict()` on a model fit with `prior_PD = TRUE`: + +```{r prior-pd, eval=FALSE} +fit_prior <- stan_glm( + y ~ roach100 + treatment + senior, + offset = log(exposure2), + family = poisson, + data = roaches, + prior_PD = TRUE # sample from prior predictive only +) +yrep_prior <- posterior_predict(fit_prior) + +# use the same ppc_ functions with prior predictive draws +ppc_dens_overlay(y, yrep_prior[1:50, ]) +ppc_stat(y, yrep_prior, stat = "mean") +``` + +If you want to examine the prior predictive distribution *without* comparing to +observed data, you can use the `ppd_*` functions (PPD = prior/posterior +predictive distribution) instead: + +```{r ppd-example, eval=FALSE} +ppd_dens_overlay(yrep_prior[1:50, ]) +ppd_stat(yrep_prior, stat = "mean") +``` +
## References