From a10448cc4a7a446269b21d6f498a41288ddd0a90 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 19 Aug 2021 09:39:53 +0200 Subject: [PATCH] #354 --- NAMESPACE | 2 ++ R/check_model.R | 54 ++++++++++++++++++++++++++++++++++++++++++++++ man/check_model.Rd | 7 ++++++ 3 files changed, 63 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 222f885e9..be18fc5d2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -34,8 +34,10 @@ S3method(check_distribution,numeric) S3method(check_heteroscedasticity,default) S3method(check_homogeneity,afex_aov) S3method(check_homogeneity,default) +S3method(check_model,brmsfit) S3method(check_model,default) S3method(check_model,model_fit) +S3method(check_model,stanreg) S3method(check_multimodal,data.frame) S3method(check_multimodal,numeric) S3method(check_normality,afex_aov) diff --git a/R/check_model.R b/R/check_model.R index d22c7e98a..f645bc580 100644 --- a/R/check_model.R +++ b/R/check_model.R @@ -38,6 +38,12 @@ #' to the dedicated functions (like `check_collinearity()`, #' `check_normality()` etc.) to get informative messages and warnings. #' +#' @details For Bayesian models from packages **rstanarm** or **brms**, +#' models will be "converted" to their frequentist counterpart, using +#' [`bayestestR::bayesian_as_frequentist`](https://easystats.github.io/bayestestR/reference/convert_bayesian_as_frequentist.html). +#' A more advanced model-check for Bayesian models will be implemented at a +#' later stage. +#' #' @section Linearity Assumption: #' The plot **Linearity** checks the assumption of linear relationship. #' However, the spread of dots also indicate possible heteroscedasticity (i.e. @@ -124,6 +130,42 @@ check_model.default <- function(x, } +## TODO for now, convert to freq, see https://github.com/easystats/performance/issues/354 +## need to fix this later + +#' @export +check_model.stanreg <- function(x, + dot_size = 2, + line_size = .8, + panel = TRUE, + check = "all", + alpha = .2, + dot_alpha = .8, + colors = c("#3aaf85", "#1b6ca8", "#cd201f"), + theme = "see::theme_lucid", + detrend = FALSE, + verbose = TRUE, + ...) { + check_model(bayestestR::bayesian_as_frequentist(x), + dot_size = dot_size, + line_size = line_size, + panel = panel, + check = check, + alpha = alpha, + dot_alpha = dot_alpha, + colors = colors, + theme = theme, + detrend = detrend, + verbose = verbose, + ...) +} + + + +#' @export +check_model.brmsfit <- check_model.stanreg + + #' @export check_model.model_fit <- function(x, dot_size = 2, @@ -131,7 +173,11 @@ check_model.model_fit <- function(x, panel = TRUE, check = "all", alpha = .2, + dot_alpha = .8, + colors = c("#3aaf85", "#1b6ca8", "#cd201f"), + theme = "see::theme_lucid", detrend = FALSE, + verbose = TRUE, ...) { check_model( x$fit, @@ -140,7 +186,11 @@ check_model.model_fit <- function(x, panel = panel, check = check, alpha = alpha, + dot_alpha = dot_alpha, + colors = colors, + theme = theme, detrend = detrend, + verbose = verbose, ... ) } @@ -149,6 +199,10 @@ check_model.model_fit <- function(x, + +# helper ------------------------ + + .check_assumptions_linear <- function(model, model_info) { dat <- list() diff --git a/man/check_model.Rd b/man/check_model.Rd index 8589c915c..45b01be7e 100644 --- a/man/check_model.Rd +++ b/man/check_model.Rd @@ -63,6 +63,13 @@ Visual check of model various assumptions (normality of residuals, normality of random effects, linear relationship, homogeneity of variance, multicollinearity). } +\details{ +For Bayesian models from packages \strong{rstanarm} or \strong{brms}, +models will be "converted" to their frequentist counterpart, using +\href{https://easystats.github.io/bayestestR/reference/convert_bayesian_as_frequentist.html}{\code{bayestestR::bayesian_as_frequentist}}. +A more advanced model-check for Bayesian models will be implemented at a +later stage. +} \note{ This function just prepares the data for plotting. To create the plots, \CRANpkg{see} needs to be installed. Furthermore, this function suppresses