From 37343700f04f08a13580397733841985651364a4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 20 Nov 2023 13:39:23 +0100 Subject: [PATCH] fix, lintr --- R/1_model_parameters.R | 20 ++++++++++---------- R/3_p_value.R | 6 +++--- R/4_standard_error.R | 4 ++-- R/ci_profile_boot.R | 16 ++++++++-------- R/dominance_analysis.R | 7 +++---- R/methods_betareg.R | 6 +++--- R/methods_brglm2.R | 6 +++--- R/methods_car.R | 6 +++--- R/methods_cgam.R | 6 +++--- R/methods_glmmTMB.R | 10 +++++----- R/methods_hglm.R | 6 +++--- R/methods_lme4.R | 12 ++++++------ R/methods_mice.R | 6 +++--- R/methods_nestedLogit.R | 30 ++++++++++++++---------------- R/methods_plm.R | 4 ++-- R/methods_survey.R | 10 +++++----- R/utils_model_parameters.R | 6 +++--- 17 files changed, 79 insertions(+), 82 deletions(-) diff --git a/R/1_model_parameters.R b/R/1_model_parameters.R index 0113673b7..aa8106750 100644 --- a/R/1_model_parameters.R +++ b/R/1_model_parameters.R @@ -576,14 +576,14 @@ model_parameters.default <- function(model, ci_method <- "quantile" } - args <- list( + fun_args <- list( model, iterations = iterations, ci = ci, ci_method = ci_method ) - args <- c(args, dots) - params <- do.call("bootstrap_parameters", args) + fun_args <- c(fun_args, dots) + params <- do.call("bootstrap_parameters", fun_args) # Processing, non-bootstrapped parameters } else { @@ -592,7 +592,7 @@ model_parameters.default <- function(model, ci_method <- "wald" } - args <- list( + fun_args <- list( model, ci = ci, component = component, @@ -607,8 +607,8 @@ model_parameters.default <- function(model, vcov = vcov, vcov_args = vcov_args ) - args <- c(args, dots) - params <- do.call(".extract_parameters_generic", args) + fun_args <- c(fun_args, dots) + params <- do.call(".extract_parameters_generic", fun_args) } @@ -686,12 +686,12 @@ model_parameters.glm <- function(model, # tell user that profiled CIs don't respect vcov-args if (identical(ci_method, "profile") && (!is.null(vcov) || !is.null(vcov_args)) && isTRUE(verbose)) { insight::format_alert( - "When `ci_method=\"profile\"`, `vcov` only modifies standard errors, test-statistic and p-values, but not confidence intervals.", + "When `ci_method=\"profile\"`, `vcov` only modifies standard errors, test-statistic and p-values, but not confidence intervals.", # nolint "Use `ci_method=\"wald\"` to return confidence intervals based on robust standard errors." ) } - args <- list( + fun_args <- list( model = model, ci = ci, ci_method = ci_method, @@ -708,8 +708,8 @@ model_parameters.glm <- function(model, vcov_args = vcov_args, verbose = verbose ) - args <- c(args, dots) - out <- do.call(".model_parameters_generic", args) + fun_args <- c(fun_args, dots) + out <- do.call(".model_parameters_generic", fun_args) attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model)) out diff --git a/R/3_p_value.R b/R/3_p_value.R index fca6d150e..a357443f2 100644 --- a/R/3_p_value.R +++ b/R/3_p_value.R @@ -105,13 +105,13 @@ p_value.default <- function(model, if (inherits(vcov, "data.frame") || "SE" %in% colnames(vcov)) { se <- vcov } else { - args <- list(model, + fun_args <- list(model, vcov_args = vcov_args, vcov = vcov, verbose = verbose ) - args <- c(args, dots) - se <- do.call("standard_error", args) + fun_args <- c(fun_args, dots) + se <- do.call("standard_error", fun_args) } dof <- degrees_of_freedom(model, method = "wald", verbose = FALSE) diff --git a/R/4_standard_error.R b/R/4_standard_error.R index e6b1e5d46..6dc4b0292 100644 --- a/R/4_standard_error.R +++ b/R/4_standard_error.R @@ -88,8 +88,8 @@ standard_error.default <- function(model, # vcov: function which returns a matrix if (is.function(vcov)) { - args <- c(list(model), vcov_args, dots) - se <- .safe(sqrt(diag(do.call("vcov", args)))) + fun_args <- c(list(model), vcov_args, dots) + se <- .safe(sqrt(diag(do.call("vcov", fun_args)))) } # vcov: character (with backward compatibility for `robust = TRUE`) diff --git a/R/ci_profile_boot.R b/R/ci_profile_boot.R index 0dab03861..6dfc4bbb2 100644 --- a/R/ci_profile_boot.R +++ b/R/ci_profile_boot.R @@ -84,14 +84,14 @@ dot_args <- .check_profile_uniroot_args(...) if (is.null(profiled)) { - args <- list(x, method = "profile", level = ci, dot_args) - out <- as.data.frame(do.call(stats::confint, args)) + fun_args <- list(x, method = "profile", level = ci, dot_args) + out <- as.data.frame(do.call(stats::confint, fun_args)) } else { - args <- list(profiled, level = ci, dot_args) - out <- .safe(as.data.frame(do.call(stats::confint, args))) + fun_args <- list(profiled, level = ci, dot_args) + out <- .safe(as.data.frame(do.call(stats::confint, fun_args))) if (is.null(out)) { - args <- list(x, method = "profile", level = ci, dot_args) - out <- as.data.frame(do.call(stats::confint, args)) + fun_args <- list(x, method = "profile", level = ci, dot_args) + out <- as.data.frame(do.call(stats::confint, fun_args)) } } .process_glmmTMB_CI(x, out, ci, component) @@ -103,8 +103,8 @@ .ci_uniroot_glmmTMB <- function(x, ci, component, ...) { # make sure "..." doesn't pass invalid arguments to package TMB dot_args <- .check_profile_uniroot_args(...) - args <- list(x, level = ci, method = "uniroot", dot_args) - out <- as.data.frame(do.call(stats::confint, args)) + fun_args <- list(x, level = ci, method = "uniroot", dot_args) + out <- as.data.frame(do.call(stats::confint, fun_args)) .process_glmmTMB_CI(x, out, ci, component) } diff --git a/R/dominance_analysis.R b/R/dominance_analysis.R index 90d991ecb..efeb46e59 100644 --- a/R/dominance_analysis.R +++ b/R/dominance_analysis.R @@ -347,11 +347,10 @@ dominance_analysis <- function(model, sets = NULL, all = NULL, # quote arguments for domin for (arg in quote_args) { - if (!(arg %in% names(args))) { - insight::format_error(arg, " in `quote_args` not among arguments in model.") + if (arg %in% names(args)) { + args[[arg]] <- str2lang(paste0("quote(", deparse(args[[arg]]), ")", collapse = "")) } else { - args[[arg]] <- - str2lang(paste0("quote(", deparse(args[[arg]]), ")", collapse = "")) + insight::format_error(arg, " in `quote_args` not among arguments in model.") } } diff --git a/R/methods_betareg.R b/R/methods_betareg.R index dbc8451ac..4c4ce273b 100644 --- a/R/methods_betareg.R +++ b/R/methods_betareg.R @@ -32,7 +32,7 @@ model_parameters.betareg <- function(model, ## TODO check merge by - args <- list( + fun_args <- list( model, ci = ci, component = component, @@ -48,9 +48,9 @@ model_parameters.betareg <- function(model, vcov = NULL, vcov_args = NULL ) - args <- c(args, dot_args) + fun_args <- c(fun_args, dot_args) - out <- do.call(".model_parameters_generic", args) + out <- do.call(".model_parameters_generic", fun_args) attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model)) out } diff --git a/R/methods_brglm2.R b/R/methods_brglm2.R index 2b6c0cdf2..08d844d8d 100644 --- a/R/methods_brglm2.R +++ b/R/methods_brglm2.R @@ -45,7 +45,7 @@ model_parameters.bracl <- function(model, merge_by <- "Parameter" } - args <- list( + fun_args <- list( model, ci = ci, bootstrap = bootstrap, @@ -60,9 +60,9 @@ model_parameters.bracl <- function(model, vcov = NULL, vcov_args = NULL ) - args <- c(args, dot_args) + fun_args <- c(fun_args, dot_args) - out <- do.call(".model_parameters_generic", args) + out <- do.call(".model_parameters_generic", fun_args) attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model)) out } diff --git a/R/methods_car.R b/R/methods_car.R index 1de7f01c6..0224a3e67 100644 --- a/R/methods_car.R +++ b/R/methods_car.R @@ -37,7 +37,7 @@ model_parameters.deltaMethod <- function(model, p_adjust = NULL, verbose = TRUE, params <- .p_adjust(params, p_adjust, model, verbose) } - args <- list( + fun_args <- list( params, model, ci = ci, @@ -49,9 +49,9 @@ model_parameters.deltaMethod <- function(model, p_adjust = NULL, verbose = TRUE, summary = FALSE, verbose = verbose ) - args <- c(args, dots) + fun_args <- c(fun_args, dots) - params <- do.call(".add_model_parameters_attributes", args) + params <- do.call(".add_model_parameters_attributes", fun_args) class(params) <- c("parameters_model", "see_parameters_model", class(params)) attr(params, "object_name") <- insight::safe_deparse_symbol(substitute(model)) diff --git a/R/methods_cgam.R b/R/methods_cgam.R index 661dbf2e4..a9759ec0a 100644 --- a/R/methods_cgam.R +++ b/R/methods_cgam.R @@ -60,7 +60,7 @@ model_parameters.cgam <- function(model, ... ) } else { - args <- list( + fun_args <- list( model, ci = ci, ci_method = ci_method, @@ -74,8 +74,8 @@ model_parameters.cgam <- function(model, vcov = NULL, vcov_args = NULL ) - args <- c(args, dot_args) - params <- do.call(".extract_parameters_generic", args) + fun_args <- c(fun_args, dot_args) + params <- do.call(".extract_parameters_generic", fun_args) } # fix statistic column diff --git a/R/methods_glmmTMB.R b/R/methods_glmmTMB.R index 9738c947b..47cbc3be3 100644 --- a/R/methods_glmmTMB.R +++ b/R/methods_glmmTMB.R @@ -81,7 +81,7 @@ model_parameters.glmmTMB <- function(model, } } } else { - args <- list( + fun_args <- list( model, ci = ci, component = component, @@ -100,8 +100,8 @@ model_parameters.glmmTMB <- function(model, wb_component = wb_component, summary = summary ) - args <- c(args, dot_args) - params <- do.call(".extract_parameters_generic", args) + fun_args <- c(fun_args, dot_args) + params <- do.call(".extract_parameters_generic", fun_args) } # add dispersion parameter @@ -131,7 +131,7 @@ model_parameters.glmmTMB <- function(model, if (verbose) { insight::format_alert( "Cannot compute standard errors and confidence intervals for sigma parameter.", - "Your model may suffer from singularity (see '?lme4::isSingular' and '?performance::check_singularity')." + "Your model may suffer from singularity (see '?lme4::isSingular' and '?performance::check_singularity')." # nolint ) } c(NA, NA) @@ -157,7 +157,7 @@ model_parameters.glmmTMB <- function(model, params_random <- .extract_random_parameters(model, ci = ci, effects = effects, component = component) if (length(random_effects) > 1) { insight::format_alert( - "Cannot extract confidence intervals for random variance parameters from models with more than one grouping factor." + "Cannot extract confidence intervals for random variance parameters from models with more than one grouping factor." # nolint ) } } else { diff --git a/R/methods_hglm.R b/R/methods_hglm.R index beb24306d..4f237e112 100644 --- a/R/methods_hglm.R +++ b/R/methods_hglm.R @@ -223,13 +223,13 @@ p_value.hglm <- function(model, ...) { dots <- list(...) dots$component <- NULL - args <- list( + fun_args <- list( model, dof = dof, component = "conditional", method = method, verbose = verbose ) - args <- c(args, dots) - do.call("p_value.default", args) + fun_args <- c(fun_args, dots) + do.call("p_value.default", fun_args) } diff --git a/R/methods_lme4.R b/R/methods_lme4.R index 549317ef4..68380572d 100644 --- a/R/methods_lme4.R +++ b/R/methods_lme4.R @@ -197,7 +197,7 @@ model_parameters.merMod <- function(model, } } } else { - args <- list( + fun_args <- list( model, ci = ci, ci_method = ci_method, @@ -212,8 +212,8 @@ model_parameters.merMod <- function(model, vcov = vcov, vcov_args = vcov_args ) - args <- c(args, dots) - params <- do.call(".extract_parameters_mixed", args) + fun_args <- c(fun_args, dots) + params <- do.call(".extract_parameters_mixed", fun_args) } params$Effects <- "fixed" @@ -348,12 +348,12 @@ standard_error.merMod <- function(model, } if (!is.null(vcov) || isTRUE(dots[["robust"]])) { - args <- list(model, + fun_args <- list(model, vcov = vcov, vcov_args = vcov_args ) - args <- c(args, dots) - out <- do.call("standard_error.default", args) + fun_args <- c(fun_args, dots) + out <- do.call("standard_error.default", fun_args) return(out) } diff --git a/R/methods_mice.R b/R/methods_mice.R index 3f0511b9f..cdf326399 100644 --- a/R/methods_mice.R +++ b/R/methods_mice.R @@ -108,7 +108,7 @@ model_parameters.mipo <- function(model, merge_by <- "Parameter" } - args <- list( + fun_args <- list( model, ci = ci, merge_by = merge_by, @@ -119,9 +119,9 @@ model_parameters.mipo <- function(model, vcov = NULL, vcov_args = NULL ) - args <- c(args, dot_args) + fun_args <- c(fun_args, dot_args) - out <- do.call(".model_parameters_generic", args) + out <- do.call(".model_parameters_generic", fun_args) attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model)) out } diff --git a/R/methods_nestedLogit.R b/R/methods_nestedLogit.R index 7cf670ded..ad9fb0485 100644 --- a/R/methods_nestedLogit.R +++ b/R/methods_nestedLogit.R @@ -45,12 +45,12 @@ model_parameters.nestedLogit <- function(model, # tell user that profiled CIs don't respect vcov-args if (identical(ci_method, "profile") && (!is.null(vcov) || !is.null(vcov_args)) && isTRUE(verbose)) { insight::format_alert( - "When `ci_method=\"profile\"`, `vcov` only modifies standard errors, test-statistic and p-values, but not confidence intervals.", + "When `ci_method=\"profile\"`, `vcov` only modifies standard errors, test-statistic and p-values, but not confidence intervals.", # nolint "Use `ci_method=\"wald\"` to return confidence intervals based on robust standard errors." ) } - args <- list( + fun_args <- list( model = model, ci = ci, ci_method = ci_method, @@ -67,8 +67,8 @@ model_parameters.nestedLogit <- function(model, vcov = vcov, vcov_args = vcov_args ) - args <- c(args, dots) - out <- do.call(".model_parameters_generic", args) + fun_args <- c(fun_args, dots) + out <- do.call(".model_parameters_generic", fun_args) attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model)) out @@ -89,19 +89,17 @@ degrees_of_freedom.nestedLogit <- function(model, dof <- rep(vapply(model$models, stats::df.residual, numeric(1)), each = nrow(cf)) if (!is.null(component) && !identical(component, "all")) { comp <- intersect(names(dof), component) - if (!length(comp)) { + if (length(comp)) { + dof <- dof[comp] + } else { if (verbose) { - insight::format_alert( - paste0( - "No matching model found. Possible values for `component` are ", - toString(paste0("'", names(model$models), "'")), - "." - ) - ) + insight::format_alert(paste0( + "No matching model found. Possible values for `component` are ", + toString(paste0("'", names(model$models), "'")), + "." + )) } dof <- Inf - } else { - dof <- dof[comp] } } } else { @@ -128,8 +126,8 @@ standard_error.nestedLogit <- function(model, # vcov: function which returns a matrix if (is.function(vcov)) { - args <- c(list(model), vcov_args, dots) - se <- .safe(sqrt(diag(do.call("vcov", args)))) + fun_args <- c(list(model), vcov_args, dots) + se <- .safe(sqrt(diag(do.call("vcov", fun_args)))) } # vcov: character (with backward compatibility for `robust = TRUE`) diff --git a/R/methods_plm.R b/R/methods_plm.R index 109fa53ba..00a120df9 100644 --- a/R/methods_plm.R +++ b/R/methods_plm.R @@ -27,8 +27,8 @@ standard_error.plm <- function(model, vcov = NULL, vcov_args = NULL, verbose = T # vcov: function which returns a matrix if (is.function(vcov)) { - args <- c(list(model), vcov_args, dots) - se <- .safe(sqrt(diag(do.call("vcov", args)))) + fun_args <- c(list(model), vcov_args, dots) + se <- .safe(sqrt(diag(do.call("vcov", fun_args)))) } # vcov: character (with backward compatibility for `robust = TRUE`) diff --git a/R/methods_survey.R b/R/methods_survey.R index 9491d09a7..04674bf8f 100644 --- a/R/methods_survey.R +++ b/R/methods_survey.R @@ -26,7 +26,7 @@ model_parameters.svyglm <- function(model, verbose = verbose ) - args <- list( + fun_args <- list( model, ci = ci, ci_method = ci_method, @@ -38,8 +38,8 @@ model_parameters.svyglm <- function(model, summary = summary, verbose = verbose ) - args <- c(args, dot_args) - out <- do.call(".model_parameters_generic", args) + fun_args <- c(fun_args, dot_args) + out <- do.call(".model_parameters_generic", fun_args) attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(model)) out @@ -120,8 +120,8 @@ ci.svyolr <- ci.svyglm #' @export p_value.svyglm <- function(model, verbose = TRUE, ...) { statistic <- insight::get_statistic(model) - df <- insight::get_df(model, type = "residual") - p <- 2 * stats::pt(-abs(statistic$Statistic), df = df) + dof <- insight::get_df(model, type = "residual") + p <- 2 * stats::pt(-abs(statistic$Statistic), df = dof) .data_frame( Parameter = statistic$Parameter, p = as.vector(p) diff --git a/R/utils_model_parameters.R b/R/utils_model_parameters.R index a59b48d22..d726b29f5 100644 --- a/R/utils_model_parameters.R +++ b/R/utils_model_parameters.R @@ -414,10 +414,10 @@ .additional_arguments <- function(x, value, default) { - args <- attributes(x)$additional_arguments + add_args <- attributes(x)$additional_arguments - if (length(args) > 0 && value %in% names(args)) { - out <- args[[value]] + if (length(add_args) > 0 && value %in% names(add_args)) { + out <- add_args[[value]] } else { out <- attributes(x)[[value]] }