Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 24, 2024
1 parent f94c5b1 commit 0b2002e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
26 changes: 13 additions & 13 deletions R/check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------
Expand All @@ -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 --------------
Expand All @@ -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 --------------
Expand All @@ -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 --------------
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions R/check_model_diagnostics.R
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -367,7 +367,7 @@



.diag_overdispersion <- function(model, ...) {
.model_diagnostic_overdispersion <- function(model, ...) {
faminfo <- insight::model_info(model)

# data for poisson models
Expand Down
2 changes: 1 addition & 1 deletion R/check_normality.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 1 addition & 9 deletions R/check_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/check_overdispersion.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b2002e

Please sign in to comment.