What does `prior_PD` sample?

In the documentation of stanreg functions, prior_PD is defined as:

A logical scalar (defaulting to FALSE) indicating whether to draw from the prior predictive distribution instead of conditioning on the outcome.

However, the documentation of posterior_vs_prior describes it as:

Plot medians and central intervals comparing parameter draws from the prior and posterior distributions. …

Internally, it seems that posterior_vs_prior simply uses update(object, prior_PD = TRUE), so I am not sure if the prior distribution and the prior predictive distribution are one and the same?

They seem to be:

#> Loading required package: Rcpp
#> Warning: package 'Rcpp' was built under R version 3.6.1
#> Registered S3 method overwritten by 'xts':
#>   method     from
#>   as.zoo.xts zoo
#> rstanarm (Version 2.18.2, packaged: 2018-11-08 22:19:38 UTC)
#> - Do not expect the default priors to remain the same in future rstanarm versions.
#> Thus, R scripts should specify priors explicitly, even if they are just the defaults.
#> - For execution on a local, multicore CPU with excess RAM we recommend calling
#> options(mc.cores = parallel::detectCores())
#> - Plotting theme set to bayesplot::theme_default().
#> Warning: package 'ggplot2' was built under R version 3.6.1
fit <- stan_lmer(extra ~ group + (1 | ID),
                 data = sleep,
                 prior_PD = TRUE,
                 refresh = 0)
#> Priors for model 'fit' 
#> ------
#> Intercept (after predictors centered)
#>  ~ normal(location = 0, scale = 10)
#>      **adjusted scale = 20.18
#> Coefficients
#>  ~ normal(location = 0, scale = 2.5)
#>      **adjusted scale = 5.04
#> Auxiliary (sigma)
#>  ~ exponential(rate = 1)
#>      **adjusted scale = 2.02 (adjusted rate = 1/adjusted scale)
#> Covariance
#>  ~ decov(reg. = 1, conc. = 1, shape = 1, scale = 1)
#> ------
#> See help('prior_summary.stanreg') for more details
x <- insight::get_parameters(fit)
ggplot(x, aes(group2)) + 
  geom_density() +
  stat_function(fun = function(x) dnorm(x,0, 5.044799), color = "red")

Created on 2019-10-14 by the reprex package (v0.3.0)

  • Running Win10
  • rstanarm 2.18.2
1 Like

If prior_PD is TRUE, then it draws from the prior distribution, primarily in order to use those realizations to draw from the prior predictive distribution and verify that the priors are reasonable. The Stan programs in rstanarm actually do draw from the predictive distribution in the generated quantities block, but it wasn’t a great choice of argument name.

My take home is: when prior_PD = TRUE, the produced draws are from the prior distribution (and not from the prior predictive distribution).

Thanks Ben!

Yeah, except for the column in the output labeled PPD.

1 Like

I agree the name prior_PD wasn’t the best choice. We can always deprecate it and change the name without breaking backwards compatibility. Any ideas for a better one? I forget what brms uses but we could just change to that name for consistency.

brms uses sample_prior = c("no", "yes", "only").