From 905cde5d4142683e81c31f5d6ca727d779d5194b Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 1 Dec 2023 09:19:48 +0100 Subject: [PATCH] lintr --- R/plot.check_collinearity.R | 50 +++++++++++++++---------------- R/plot.check_heteroscedasticity.R | 24 +++++++-------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/R/plot.check_collinearity.R b/R/plot.check_collinearity.R index 594c556ec..cf84d66e2 100644 --- a/R/plot.check_collinearity.R +++ b/R/plot.check_collinearity.R @@ -69,11 +69,11 @@ plot.see_check_collinearity <- function(x, xlim <- nrow(x) if (ylim < 10) ylim <- 10 - if (!is.null(ci_data)) { - x <- cbind(x, ci_data) - } else { + if (is.null(ci_data)) { x$VIF_CI_low <- NA_real_ x$VIF_CI_high <- NA_real_ + } else { + x <- cbind(x, ci_data) } # make sure legend is properly sorted @@ -119,31 +119,29 @@ plot.see_check_collinearity <- function(x, color = NA, alpha = 0.15 ) + - { - if (!is.null(ci_data)) { - list( - ggplot2::geom_linerange( - linewidth = size_line, - na.rm = TRUE + if (!is.null(ci_data)) { + list( + ggplot2::geom_linerange( + linewidth = size_line, + na.rm = TRUE + ), + ggplot2::geom_segment( + data = x[x$VIF_CI_high > ylim * 1.15, ], + mapping = aes( + x = .data$x, + xend = .data$x, + y = .data$y, + yend = .data$VIF_CI_high + ), + lineend = "round", + linejoin = "round", + arrow = ggplot2::arrow( + ends = "last", type = "closed", + angle = 20, length = ggplot2::unit(0.03, "native") ), - ggplot2::geom_segment( - data = x[x$VIF_CI_high > ylim * 1.15, ], - mapping = aes( - x = .data$x, - xend = .data$x, - y = .data$y, - yend = .data$VIF_CI_high - ), - lineend = "round", - linejoin = "round", - arrow = ggplot2::arrow( - ends = "last", type = "closed", - angle = 20, length = ggplot2::unit(0.03, "native") - ), - show.legend = FALSE - ) + show.legend = FALSE ) - } + ) } + geom_point2( size = size_point, diff --git a/R/plot.check_heteroscedasticity.R b/R/plot.check_heteroscedasticity.R index 53cd814c2..18c9b9260 100644 --- a/R/plot.check_heteroscedasticity.R +++ b/R/plot.check_heteroscedasticity.R @@ -24,21 +24,19 @@ plot.see_check_heteroscedasticity <- function(x, data = NULL, ...) { faminfo <- insight::model_info(model) r <- tryCatch( - { - if (inherits(model, "merMod")) { - stats::residuals(model, scaled = TRUE) - } else if (inherits(model, c("glmmTMB", "MixMod"))) { - sigma <- if (faminfo$is_mixed) { - sqrt(insight::get_variance_residual(model)) - } else { - .sigma_glmmTMB_nonmixed(model, faminfo) - } - stats::residuals(model) / sigma - } else if (inherits(model, "glm")) { - stats::rstandard(model, type = "pearson") + if (inherits(model, "merMod")) { + stats::residuals(model, scaled = TRUE) + } else if (inherits(model, c("glmmTMB", "MixMod"))) { + sig <- if (faminfo$is_mixed) { + sqrt(insight::get_variance_residual(model)) } else { - stats::rstandard(model) + .sigma_glmmTMB_nonmixed(model, faminfo) } + stats::residuals(model) / sig + } else if (inherits(model, "glm")) { + stats::rstandard(model, type = "pearson") + } else { + stats::rstandard(model) }, error = function(e) { NULL