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:
library(rstanarm)
#> 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().
library(bayestestR)
library(ggplot2)
#> 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)
prior_summary(fit)
#> 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