diff --git a/R/check_model.R b/R/check_model.R index 576f483e4..11562a351 100644 --- a/R/check_model.R +++ b/R/check_model.R @@ -462,35 +462,35 @@ check_model.DHARMa <- check_model.performance_simres # multicollinearity -------------- if (any(c("all", "vif") %in% check)) { - dat$VIF <- .diag_vif(model, verbose = verbose) + dat$VIF <- .model_diagnostic_vif(model, verbose = verbose) } # Q-Q plot (normality/uniformity of residuals) -------------- if (any(c("all", "qq") %in% check)) { dat$QQ <- switch(residual_type, simulated = .safe(simulate_residuals(model, ...)), - .diag_qq(model, model_info = model_info, verbose = verbose) + .model_diagnostic_qq(model, model_info = model_info, verbose = verbose) ) } # Random Effects Q-Q plot (normality of BLUPs) -------------- if (any(c("all", "reqq") %in% check)) { - dat$REQQ <- .diag_reqq(model, level = 0.95, model_info = model_info, verbose = verbose) + dat$REQQ <- .model_diagnostic_ranef_qq(model, level = 0.95, model_info = model_info, verbose = verbose) } # normal-curve plot (normality of residuals) -------------- if (any(c("all", "normality") %in% check)) { - dat$NORM <- .diag_norm(model, verbose = verbose) + dat$NORM <- .model_diagnostic_normality(model, verbose = verbose) } # non-constant variance (heteroskedasticity, liniearity) -------------- if (any(c("all", "ncv", "linearity") %in% check)) { - dat$NCV <- .diag_ncv(model, verbose = verbose) + dat$NCV <- .model_diagnostic_ncv(model, verbose = verbose) } # homogeneity of variance -------------- if (any(c("all", "homogeneity") %in% check)) { - dat$HOMOGENEITY <- .diag_homogeneity(model, verbose = verbose) + dat$HOMOGENEITY <- .model_diagnostic_homogeneity(model, verbose = verbose) } # outliers -------------- @@ -501,7 +501,7 @@ check_model.DHARMa <- check_model.performance_simres } else { threshold <- attributes(dat$OUTLIERS)$threshold$cook } - dat$INFLUENTIAL <- .influential_obs(model, threshold = threshold) + dat$INFLUENTIAL <- .safe(.model_diagnostic_outlier(model, threshold = threshold)) } # posterior predictive checks -------------- @@ -523,25 +523,25 @@ check_model.DHARMa <- check_model.performance_simres # multicollinearity -------------- if (any(c("all", "vif") %in% check)) { - dat$VIF <- .diag_vif(model, verbose = verbose) + dat$VIF <- .model_diagnostic_vif(model, verbose = verbose) } # Q-Q plot (normality/uniformity of residuals) -------------- if (any(c("all", "qq") %in% check)) { dat$QQ <- switch(residual_type, simulated = .safe(simulate_residuals(model, ...)), - .diag_qq(model, model_info = model_info, verbose = verbose) + .model_diagnostic_qq(model, model_info = model_info, verbose = verbose) ) } # homogeneity of variance -------------- if (any(c("all", "homogeneity") %in% check)) { - dat$HOMOGENEITY <- .diag_homogeneity(model, verbose = verbose) + dat$HOMOGENEITY <- .model_diagnostic_homogeneity(model, verbose = verbose) } # Random Effects Q-Q plot (normality of BLUPs) -------------- if (any(c("all", "reqq") %in% check)) { - dat$REQQ <- .diag_reqq(model, level = 0.95, model_info = model_info, verbose = verbose) + dat$REQQ <- .model_diagnostic_ranef_qq(model, level = 0.95, model_info = model_info, verbose = verbose) } # outliers -------------- @@ -552,7 +552,7 @@ check_model.DHARMa <- check_model.performance_simres } else { threshold <- attributes(dat$OUTLIERS)$threshold$cook } - dat$INFLUENTIAL <- .influential_obs(model, threshold = threshold) + dat$INFLUENTIAL <- .safe(.model_diagnostic_outlier(model, threshold = threshold)) } # posterior predictive checks -------------- @@ -567,7 +567,7 @@ check_model.DHARMa <- check_model.performance_simres # misspecified dispersion and zero-inflation -------------- if (isTRUE(model_info$is_count) && any(c("all", "overdispersion") %in% check)) { - dat$OVERDISPERSION <- .diag_overdispersion(model) + dat$OVERDISPERSION <- .model_diagnostic_overdispersion(model) } dat <- insight::compact_list(dat) diff --git a/R/check_model_diagnostics.R b/R/check_model_diagnostics.R index 8897c685e..9595ed968 100644 --- a/R/check_model_diagnostics.R +++ b/R/check_model_diagnostics.R @@ -1,6 +1,6 @@ # prepare data for VIF plot ---------------------------------- -.diag_vif <- function(model, verbose = TRUE) { +.model_diagnostic_vif <- function(model, verbose = TRUE) { out <- check_collinearity(model, verbose = verbose) dat <- insight::compact_list(out) if (is.null(dat)) { @@ -35,7 +35,7 @@ # prepare data for QQ plot ---------------------------------- -.diag_qq <- function(model, model_info = NULL, verbose = TRUE) { +.model_diagnostic_qq <- function(model, model_info = NULL, verbose = TRUE) { if (inherits(model, c("lme", "lmerMod", "merMod", "gam"))) { res_ <- stats::residuals(model) } else if (inherits(model, "geeglm")) { @@ -98,7 +98,7 @@ # prepare data for random effects QQ plot ---------------------------------- -.diag_reqq <- function(model, level = 0.95, model_info = NULL, verbose = TRUE) { +.model_diagnostic_ranef_qq <- function(model, level = 0.95, model_info = NULL, verbose = TRUE) { # check if we have mixed model if (is.null(model_info) || !model_info$is_mixed) { return(NULL) @@ -161,7 +161,7 @@ # prepare data for normality of residuals plot ---------------------------------- -.diag_norm <- function(model, verbose = TRUE) { +.model_diagnostic_normality <- function(model, verbose = TRUE) { r <- try(as.numeric(stats::residuals(model)), silent = TRUE) if (inherits(r, "try-error")) { @@ -181,7 +181,7 @@ # prepare data for influential obs plot ---------------------------------- -.diag_influential_obs <- function(model, threshold = NULL) { +.model_diagnostic_outlier <- function(model, threshold = NULL) { s <- summary(model) if (inherits(model, "lm", which = TRUE) == 1) { @@ -220,7 +220,7 @@ # prepare data for non-constant variance plot ---------------------------------- -.diag_ncv <- function(model, verbose = TRUE) { +.model_diagnostic_ncv <- function(model, verbose = TRUE) { ncv <- tryCatch( data.frame( x = as.numeric(stats::fitted(model)), @@ -248,7 +248,7 @@ # prepare data for homogeneity of variance plot ---------------------------------- -.diag_homogeneity <- function(model, verbose = TRUE) { +.model_diagnostic_homogeneity <- function(model, verbose = TRUE) { faminfo <- insight::model_info(model) r <- tryCatch( if (inherits(model, "merMod")) { @@ -367,7 +367,7 @@ -.diag_overdispersion <- function(model, ...) { +.model_diagnostic_overdispersion <- function(model, ...) { faminfo <- insight::model_info(model) # data for poisson models diff --git a/R/check_normality.R b/R/check_normality.R index 7ea6970ec..ffd4ba824 100644 --- a/R/check_normality.R +++ b/R/check_normality.R @@ -231,7 +231,7 @@ check_normality.merMod <- function(x, effects = c("fixed", "random"), ...) { p.val <- c(p.val, .check_normality(re[[i]][[j]], x, "random effects")) } } - attr(p.val, "re_qq") <- .diag_reqq(x, level = 0.95, model_info = info) + attr(p.val, "re_qq") <- .model_diagnostic_ranef_qq(x, level = 0.95, model_info = info) attr(p.val, "type") <- "random effects" attr(p.val, "re_groups") <- re_groups } diff --git a/R/check_outliers.R b/R/check_outliers.R index 071bd39a3..7729f9931 100644 --- a/R/check_outliers.R +++ b/R/check_outliers.R @@ -588,7 +588,7 @@ check_outliers.default <- function(x, attr(outlier, "threshold") <- thresholds attr(outlier, "method") <- method attr(outlier, "text_size") <- 3 - attr(outlier, "influential_obs") <- .influential_obs(x, threshold = unlist(thresholds)) + attr(outlier, "influential_obs") <- .safe(.model_diagnostic_outlier(x, threshold = unlist(thresholds))) # nolint attr(outlier, "variables") <- "(Whole model)" attr(outlier, "raw_data") <- my_data attr(outlier, "outlier_var") <- outlier_var @@ -2036,14 +2036,6 @@ check_outliers.DHARMa <- check_outliers.performance_simres -# influential observations data -------- - -.influential_obs <- function(x, threshold = NULL) { - .safe(.diag_influential_obs(x, threshold = threshold)) -} - - - # Non-supported model classes --------------------------------------- #' @export diff --git a/R/check_overdispersion.R b/R/check_overdispersion.R index 0d877b0ad..fc8e25e32 100644 --- a/R/check_overdispersion.R +++ b/R/check_overdispersion.R @@ -101,7 +101,7 @@ plot.check_overdisp <- function(x, ...) { } } if (!is.null(model)) { - x <- .diag_overdispersion(model) + x <- .model_diagnostic_overdispersion(model) class(x) <- c("see_check_overdisp", "data.frame") attr(x, "colors") <- list(...)$colors attr(x, "line_size") <- list(...)$size_line