Skip to content

Commit

Permalink
Harnonize arguments (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke authored Nov 24, 2024
1 parent 71ca921 commit bd6c784
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 91 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: performance
Title: Assessment of Regression Models Performance
Version: 0.12.4.6
Version: 0.12.4.7
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

* Deprecated arguments and alias-function-names have been removed.

* Argument names in `check_model()` that refer to plot-aesthetics (like
`dot_size`) are now harmonized across *easystats* packages, meaning that
these have been renamed. They now follow the pattern `aesthetic_type`, e.g.
`size_dot` (instead of `dot_size`).

## Changes

* Increased accuracy for `check_convergence()` for *glmmTMB* models.
Expand Down
106 changes: 53 additions & 53 deletions R/check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#' get hints about possible problems.
#'
#' @param x A model object.
#' @param dot_size,line_size Size of line and dot-geoms.
#' @param base_size,title_size,axis_title_size Base font size for axis and plot titles.
#' @param size_dot,size_line Size of line and dot-geoms.
#' @param base_size,size_title,size_axis_title Base font size for axis and plot titles.
#' @param panel Logical, if `TRUE`, plots are arranged as panels; else,
#' single plots for each diagnostic are returned.
#' @param check Character vector, indicating which checks for should be performed
Expand All @@ -23,7 +23,7 @@
#' `"linearity"`, and checks for non-constant variance, i.e. for
#' heteroscedasticity, as well as the linear relationship. By default, all
#' possible checks are performed and plotted.
#' @param alpha,dot_alpha The alpha level of the confidence bands and dot-geoms.
#' @param alpha,alpha_dot The alpha level of the confidence bands and dot-geoms.
#' Scalar from 0 to 1.
#' @param colors Character vector with color codes (hex-format). Must be of
#' length 3. First color is usually used for reference lines, second color
Expand Down Expand Up @@ -196,13 +196,13 @@ check_model.default <- function(x,
type = "density",
residual_type = NULL,
show_dots = NULL,
dot_size = 2,
line_size = 0.8,
title_size = 12,
axis_title_size = base_size,
size_dot = 2,
size_line = 0.8,
size_title = 12,
size_axis_title = base_size,
base_size = 10,
alpha = 0.2,
dot_alpha = 0.8,
alpha_dot = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
verbose = FALSE,
Expand Down Expand Up @@ -277,14 +277,14 @@ check_model.default <- function(x,
}

attr(assumptions_data, "panel") <- panel
attr(assumptions_data, "dot_size") <- dot_size
attr(assumptions_data, "line_size") <- line_size
attr(assumptions_data, "dot_size") <- size_dot
attr(assumptions_data, "line_size") <- size_line
attr(assumptions_data, "base_size") <- base_size
attr(assumptions_data, "axis_title_size") <- axis_title_size
attr(assumptions_data, "title_size") <- title_size
attr(assumptions_data, "axis_title_size") <- size_axis_title
attr(assumptions_data, "title_size") <- size_title
attr(assumptions_data, "check") <- check
attr(assumptions_data, "alpha") <- alpha
attr(assumptions_data, "dot_alpha") <- dot_alpha
attr(assumptions_data, "dot_alpha") <- alpha_dot
attr(assumptions_data, "show_dots") <- isTRUE(show_dots)
attr(assumptions_data, "detrend") <- detrend
attr(assumptions_data, "colors") <- colors
Expand Down Expand Up @@ -328,28 +328,28 @@ check_model.stanreg <- function(x,
type = "density",
residual_type = NULL,
show_dots = NULL,
dot_size = 2,
line_size = 0.8,
title_size = 12,
axis_title_size = base_size,
size_dot = 2,
size_line = 0.8,
size_title = 12,
size_axis_title = base_size,
base_size = 10,
alpha = 0.2,
dot_alpha = 0.8,
alpha_dot = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
verbose = FALSE,
...) {
check_model(bayestestR::bayesian_as_frequentist(x),
dot_size = dot_size,
line_size = line_size,
size_dot = size_dot,
size_line = size_line,
panel = panel,
check = check,
alpha = alpha,
dot_alpha = dot_alpha,
alpha_dot = alpha_dot,
colors = colors,
theme = theme,
base_size = base_size,
axis_title_size = axis_title_size,
size_axis_title = size_axis_title,
detrend = detrend,
show_dots = show_dots,
bandwidth = bandwidth,
Expand All @@ -374,26 +374,26 @@ check_model.model_fit <- function(x,
type = "density",
residual_type = NULL,
show_dots = NULL,
dot_size = 2,
line_size = 0.8,
title_size = 12,
axis_title_size = base_size,
size_dot = 2,
size_line = 0.8,
size_title = 12,
size_axis_title = base_size,
base_size = 10,
alpha = 0.2,
dot_alpha = 0.8,
alpha_dot = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
verbose = FALSE,
...) {
check_model(
x$fit,
dot_size = dot_size,
line_size = line_size,
size_dot = size_dot,
size_line = size_line,
panel = panel,
check = check,
alpha = alpha,
axis_title_size = axis_title_size,
dot_alpha = dot_alpha,
size_axis_title = size_axis_title,
alpha_dot = alpha_dot,
colors = colors,
theme = theme,
base_size = base_size,
Expand All @@ -417,26 +417,26 @@ check_model.performance_simres <- function(x,
type = "density",
residual_type = NULL,
show_dots = NULL,
dot_size = 2,
line_size = 0.8,
title_size = 12,
axis_title_size = base_size,
size_dot = 2,
size_line = 0.8,
size_title = 12,
size_axis_title = base_size,
base_size = 10,
alpha = 0.2,
dot_alpha = 0.8,
alpha_dot = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
verbose = FALSE,
...) {
check_model(
x$fittedModel,
dot_size = dot_size,
line_size = line_size,
size_dot = size_dot,
size_line = size_line,
panel = panel,
check = check,
alpha = alpha,
dot_alpha = dot_alpha,
axis_title_size = axis_title_size,
alpha_dot = alpha_dot,
size_axis_title = size_axis_title,
colors = colors,
theme = theme,
base_size = base_size,
Expand All @@ -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
Loading

0 comments on commit bd6c784

Please sign in to comment.