Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_model_diag_stan: Global priors are not plotted #623

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 8 additions & 15 deletions R/plot_diag_stan.R
Expand Up @@ -9,31 +9,16 @@ plot_diag_stan <- function(model, geom.colors, axis.lim, facets, axis.labels, ..
alpha <- .3
scale <- .9


if (inherits(model, "brmsfit")) {

# check if brms can be loaded

if (!requireNamespace("brms", quietly = TRUE))
stop("Package `brms` needs to be loaded first!", call. = F)

# check if prior sample are available

d2 <- brms::prior_samples(model)

if (is.null(d2))
stop("No prior-samples found. Please use option `sample_prior = TRUE` when fitting the model.", call. = FALSE)


# get samples from posterior and prior

d2 <- dplyr::select(
d2,
string_starts_with("b_", colnames(d2)),
-string_starts_with("b_Intercept", colnames(d2))
)


d1 <- brms::posterior_samples(model)

d1 <- dplyr::select(
Expand All @@ -42,6 +27,14 @@ plot_diag_stan <- function(model, geom.colors, axis.lim, facets, axis.labels, ..
-string_starts_with("b_Intercept", colnames(d1))
)


# check if prior sample are available

d2 <- brms::prior_samples(model, pars=colnames(d1))

if (is.null(d2))
stop("No prior-samples found. Please use option `sample_prior = TRUE` when fitting the model.", call. = FALSE)

} else if (inherits(model, c("stanreg", "stanfit"))) {

# check if rstanarm can be loaded
Expand Down