Skip to content

Commit

Permalink
save model information
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 5, 2024
1 parent 2f9fa5d commit 1910113
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions R/check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ check_model.default <- function(x,

minfo <- insight::model_info(x, verbose = FALSE)

ca <- tryCatch(
assumptions_data <- tryCatch(
if (minfo$is_bayesian) {
suppressWarnings(.check_assumptions_stan(x, ...))
} else if (minfo$is_linear) {
Expand All @@ -196,10 +196,10 @@ check_model.default <- function(x,
}
)

if (inherits(ca, c("error", "simpleError"))) {
if (inherits(assumptions_data, c("error", "simpleError"))) {
pattern <- "(\n|\\s{2,})"
replacement <- " "
cleaned_string <- gsub(pattern, replacement, ca$message)
cleaned_string <- gsub(pattern, replacement, assumptions_data$message)
insight::format_error(
paste("`check_model()` returned following error:", cleaned_string),
paste0("\nIf the error message does not help identifying your problem, another reason why `check_model()` failed might be that models of class `", class(x)[1], "` are not yet supported.") # nolint
Expand All @@ -218,21 +218,22 @@ check_model.default <- function(x,
show_dots <- is.null(n) || n <= 1e5
}

attr(ca, "panel") <- panel
attr(ca, "dot_size") <- dot_size
attr(ca, "line_size") <- line_size
attr(ca, "check") <- check
attr(ca, "alpha") <- alpha
attr(ca, "dot_alpha") <- dot_alpha
attr(ca, "show_dots") <- isTRUE(show_dots)
attr(ca, "detrend") <- detrend
attr(ca, "colors") <- colors
attr(ca, "theme") <- theme
attr(ca, "model_info") <- minfo
attr(ca, "overdisp_type") <- list(...)$plot_type
attr(ca, "bandwidth") <- bandwidth
attr(ca, "type") <- type
ca
attr(assumptions_data, "panel") <- panel
attr(assumptions_data, "dot_size") <- dot_size
attr(assumptions_data, "line_size") <- line_size
attr(assumptions_data, "check") <- check
attr(assumptions_data, "alpha") <- alpha
attr(assumptions_data, "dot_alpha") <- dot_alpha
attr(assumptions_data, "show_dots") <- isTRUE(show_dots)
attr(assumptions_data, "detrend") <- detrend
attr(assumptions_data, "colors") <- colors
attr(assumptions_data, "theme") <- theme
attr(assumptions_data, "model_info") <- minfo
attr(assumptions_data, "overdisp_type") <- list(...)$plot_type
attr(assumptions_data, "bandwidth") <- bandwidth
attr(assumptions_data, "type") <- type
attr(assumptions_data, "model_class") <- class(x)[1]
assumptions_data
}


Expand Down Expand Up @@ -267,7 +268,7 @@ check_model.stanreg <- function(x,
dot_alpha = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
detrend = FALSE,
detrend = TRUE,
show_dots = NULL,
bandwidth = "nrd",
type = "density",
Expand Down

0 comments on commit 1910113

Please sign in to comment.