From 6aaa29a20c44b5c645ae6c065c9592edf1630614 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 29 Mar 2024 18:18:54 +0100 Subject: [PATCH] Remove `pp_check()` alias Fixes #477 --- R/check_predictions.R | 65 ++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/R/check_predictions.R b/R/check_predictions.R index eaa94219b..82af994dd 100644 --- a/R/check_predictions.R +++ b/R/check_predictions.R @@ -115,24 +115,55 @@ check_predictions.default <- function(object, # args type <- match.arg(type, choices = c("density", "discrete_dots", "discrete_interval", "discrete_both")) - if (isTRUE(minfo$is_bayesian) && isFALSE(inherits(object, "BFBayesFactor"))) { - insight::check_if_installed( - "bayesplot", - "to create posterior prediction plots for Stan models" - ) - bayesplot::pp_check(object) + pp_check.lm( + object, + iterations = iterations, + check_range = check_range, + re_formula = re_formula, + bandwidth = bandwidth, + type = type, + verbose = verbose, + model_info = minfo, + ... + ) +} + +#' @export +check_predictions.stanreg <- function(object, + iterations = 50, + check_range = FALSE, + re_formula = NULL, + bandwidth = "nrd", + type = "density", + verbose = TRUE, + ...) { + # retrieve model information + minfo <- insight::model_info(object, verbose = FALSE) + + # try to find sensible default for "type" argument + suggest_dots <- (minfo$is_bernoulli || minfo$is_count || minfo$is_ordinal || minfo$is_categorical || minfo$is_multinomial) # nolint + if (missing(type) && suggest_dots) { + type <- "discrete_interval" + } + + # args + type <- match.arg(type, choices = c("density", "discrete_dots", "discrete_interval", "discrete_both")) + + # convert to type-argument for pp_check + type <- switch(type, + density = "density", + "bars" + ) + + insight::check_if_installed( + "bayesplot", + "to create posterior prediction plots for Stan models" + ) + + if (inherits(object, "brmsfit")) { + out <- bayesplot::pp_check(object, type = type, ndraws = iterations, ...) } else { - pp_check.lm( - object, - iterations = iterations, - check_range = check_range, - re_formula = re_formula, - bandwidth = bandwidth, - type = type, - verbose = verbose, - model_info = minfo, - ... - ) + out <- bayesplot::pp_check(object, type = type, nreps = iterations, ...) } }