From ee91b02149e9e2cde40d66812bcc35ad6f0db876 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 13 Jul 2024 18:37:32 +0200 Subject: [PATCH] lintr --- R/check_distribution.R | 14 +++++++------- R/check_homogeneity.R | 2 +- R/icc.R | 14 +++++++------- R/r2_nakagawa.R | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/R/check_distribution.R b/R/check_distribution.R index fe26f0f4c..d743b3ac1 100644 --- a/R/check_distribution.R +++ b/R/check_distribution.R @@ -191,25 +191,25 @@ check_distribution.numeric <- function(model) { # validation check, remove missings x <- x[!is.na(x)] - mode <- NULL + mode_value <- NULL # find mode for integer, or MAP for distributions if (all(.is_integer(x))) { - mode <- datawizard::distribution_mode(x) + mode_value <- datawizard::distribution_mode(x) } else { # this might fail, so we wrap in ".safe()" - mode <- tryCatch( + mode_value <- tryCatch( as.numeric(bayestestR::map_estimate(x, bw = "nrd0")), error = function(e) NULL ) - if (is.null(mode)) { - mode <- tryCatch( + if (is.null(mode_value)) { + mode_value <- tryCatch( as.numeric(bayestestR::map_estimate(x, bw = "kernel")), error = function(e) NULL ) } } - if (is.null(mode)) { + if (is.null(mode_value)) { mean_mode_diff <- mean(x) - datawizard::distribution_mode(x) msg <- "Could not accurately estimate the mode." if (!is.null(type)) { @@ -217,7 +217,7 @@ check_distribution.numeric <- function(model) { } insight::format_alert(msg) } else { - mean_mode_diff <- .safe(mean(x) - mode) + mean_mode_diff <- .safe(mean(x) - mode_value) } data.frame( diff --git a/R/check_homogeneity.R b/R/check_homogeneity.R index 76d73bc19..d6b486810 100644 --- a/R/check_homogeneity.R +++ b/R/check_homogeneity.R @@ -165,7 +165,7 @@ check_homogeneity.afex_aov <- function(x, method = "levene", ...) { between <- between[!is_covar] } - form <- stats::formula(paste0(dv, "~", paste0(between, collapse = "*"))) + form <- stats::formula(paste0(dv, "~", paste(between, collapse = "*"))) test <- car::leveneTest(form, ag_data, center = mean, ...) p.val <- test[1, "Pr(>F)"] diff --git a/R/icc.R b/R/icc.R index 569d90735..38347e563 100644 --- a/R/icc.R +++ b/R/icc.R @@ -275,11 +275,11 @@ icc <- function(model, # this is experimental! if (identical(ci_method, "analytical")) { result <- .safe(.analytical_icc_ci(model, ci)) - if (!is.null(result)) { + if (is.null(result)) { + icc_ci_adjusted <- icc_ci_unadjusted <- NA + } else { icc_ci_adjusted <- result$ICC_adjusted icc_ci_unadjusted <- result$ICC_unadjusted - } else { - icc_ci_adjusted <- icc_ci_unadjusted <- NA } } else { result <- .bootstrap_icc(model, iterations, tolerance, ci_method, ...) @@ -428,7 +428,7 @@ print.icc <- function(x, digits = 3, ...) { } # separate lines for multiple R2 - out <- paste0(out, collapse = "\n") + out <- paste(out, collapse = "\n") cat(out) cat("\n") @@ -693,10 +693,10 @@ print.icc_decomposed <- function(x, digits = 2, ...) { } model_rank <- tryCatch( - if (!is.null(model$rank)) { - model$rank - df_int - } else { + if (is.null(model$rank)) { insight::n_parameters(model) - df_int + } else { + model$rank - df_int }, error = function(e) insight::n_parameters(model) - df_int ) diff --git a/R/r2_nakagawa.R b/R/r2_nakagawa.R index d17d8bf02..dfa1eb6dc 100644 --- a/R/r2_nakagawa.R +++ b/R/r2_nakagawa.R @@ -154,7 +154,7 @@ r2_nakagawa <- function(model, if (insight::is_empty_object(vars$var.random) || is.na(vars$var.random)) { if (verbose) { # if no random effect variance, return simple R2 - insight::print_color("Random effect variances not available. Returned R2 does not account for random effects.\n", "red") + insight::print_color("Random effect variances not available. Returned R2 does not account for random effects.\n", "red") # nolint } r2_marginal <- vars$var.fixed / (vars$var.fixed + vars$var.residual) r2_conditional <- NA @@ -172,11 +172,11 @@ r2_nakagawa <- function(model, # this is experimental! if (identical(ci_method, "analytical")) { result <- .safe(.analytical_icc_ci(model, ci, fun = "r2_nakagawa")) - if (!is.null(result)) { + if (is.null(result)) { + r2_ci_marginal <- r2_ci_conditional <- NA + } else { r2_ci_marginal <- result$R2_marginal r2_ci_conditional <- result$R2_conditional - } else { - r2_ci_marginal <- r2_ci_conditional <- NA } } else { result <- .bootstrap_r2_nakagawa(model, iterations, tolerance, ci_method, ...) @@ -266,7 +266,7 @@ print.r2_nakagawa <- function(x, digits = 3, ...) { } # separate lines for multiple R2 - out <- paste0(out, collapse = "\n") + out <- paste(out, collapse = "\n") cat(out) cat("\n")