From 325f6f6f84ea10cea7582b8e3834c5d696da30c6 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 20 Sep 2023 16:29:26 +0200 Subject: [PATCH 1/3] Remove unnecessary import directives Discovered while thinking about https://github.com/easystats/easystats/issues/379 --- NAMESPACE | 6 ------ R/eta_squared-main.R | 5 ----- R/eta_squared-methods.R | 3 --- 3 files changed, 14 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 969a9e4f..358496b6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -247,14 +247,8 @@ importFrom(bayestestR,equivalence_test) importFrom(datawizard,standardise) importFrom(datawizard,standardize) importFrom(insight,display) -importFrom(insight,find_predictors) importFrom(insight,print_html) importFrom(insight,print_md) -importFrom(parameters,model_parameters) importFrom(parameters,standardize_info) importFrom(parameters,standardize_parameters) importFrom(parameters,standardize_posteriors) -importFrom(stats,anova) -importFrom(stats,aov) -importFrom(stats,na.omit) -importFrom(utils,packageVersion) diff --git a/R/eta_squared-main.R b/R/eta_squared-main.R index ff464089..1f5d2447 100644 --- a/R/eta_squared-main.R +++ b/R/eta_squared-main.R @@ -764,7 +764,6 @@ cohens_f_squared <- function(model, #' @keywords internal -#' @importFrom stats anova .anova_es.default <- function(model, ...) { .anova_es.anova(stats::anova(model), ...) } @@ -842,8 +841,6 @@ cohens_f_squared <- function(model, } #' @keywords internal -#' @importFrom parameters model_parameters -#' @importFrom stats anova .anova_es.aov <- function(model, type = c("eta", "omega", "epsilon"), partial = TRUE, @@ -885,8 +882,6 @@ cohens_f_squared <- function(model, .anova_es.glm <- .anova_es.lm #' @keywords internal -#' @importFrom parameters model_parameters -#' @importFrom insight find_predictors .anova_es.aovlist <- function(model, type = c("eta", "omega", "epsilon"), partial = TRUE, diff --git a/R/eta_squared-methods.R b/R/eta_squared-methods.R index bee08cac..12b5463e 100644 --- a/R/eta_squared-methods.R +++ b/R/eta_squared-methods.R @@ -179,7 +179,6 @@ #' @keywords internal .anova_es.anova.lme <- .anova_es.anova -#' @importFrom stats na.omit #' @keywords internal .anova_es.parameters_model <- function(model, type = c("eta", "omega", "epsilon"), @@ -249,8 +248,6 @@ # Specific models --------------------------------------------------------- #' @keywords internal -#' @importFrom stats aov -#' @importFrom utils packageVersion .anova_es.maov <- function(model, type = c("eta", "omega", "epsilon"), partial = TRUE, From 83c526d4dca32be9dac1886d0fc05703a25892ab Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 20 Sep 2023 20:39:49 +0200 Subject: [PATCH 2/3] fix strict workflow --- R/eta_squared-methods.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/eta_squared-methods.R b/R/eta_squared-methods.R index 12b5463e..9368f4f6 100644 --- a/R/eta_squared-methods.R +++ b/R/eta_squared-methods.R @@ -110,7 +110,7 @@ within <- names(model$idata) within <- lapply(within, function(x) c(NA, x)) within <- do.call(expand.grid, within) - within <- apply(within, 1, na.omit) + within <- apply(within, 1, stats::na.omit) ns <- sapply(within, length) within <- sapply(within, paste, collapse = ":") within <- within[order(ns)] From 056506e624344302916ee9f6c8257321b60f7b70 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 20 Sep 2023 20:59:14 +0200 Subject: [PATCH 3/3] clean up some lints --- R/cohens_d.R | 2 +- R/convert_stat_chisq.R | 3 +- R/effectsize-package.R | 5 +- R/xtab_diff.R | 2 +- man/convert_chisq.Rd | 3 +- man/effectsize-package.Rd | 5 +- tests/testthat/test-effectsize.R | 54 ++++++++++++++++++--- tests/testthat/test-eta_squared.R | 79 +++++++++++++++++++++---------- 8 files changed, 115 insertions(+), 38 deletions(-) diff --git a/R/cohens_d.R b/R/cohens_d.R index 5069f144..5956bf6a 100644 --- a/R/cohens_d.R +++ b/R/cohens_d.R @@ -266,7 +266,7 @@ glass_delta <- function(x, y = NULL, data = NULL, } out <- data.frame(d = (d - mu) / s) - types <- c("d" = "Cohens_d", "g" = "Hedges_g", "delta" = "Glass_delta") + types <- c(d = "Cohens_d", g = "Hedges_g", delta = "Glass_delta") colnames(out) <- types[type] if (.test_ci(ci)) { diff --git a/R/convert_stat_chisq.R b/R/convert_stat_chisq.R index 6700528f..fcf0d57a 100644 --- a/R/convert_stat_chisq.R +++ b/R/convert_stat_chisq.R @@ -48,7 +48,8 @@ #' #' \deqn{\textrm{Pearson's } C = \sqrt{\chi^2 / (\chi^2 + n)}}{Pearson's C = sqrt(\chi^2 / (\chi^2 + n))} #' -#' For versions adjusted for small-sample bias of \eqn{\phi}, \eqn{V}, and \eqn{T}, see [Bergsma, 2013](https://en.wikipedia.org/wiki/Cram%C3%A9r%27s_V#Bias_correction). +#' For versions adjusted for small-sample bias of \eqn{\phi}, \eqn{V}, and \eqn{T}, +#' see [Bergsma, 2013](https://en.wikipedia.org/wiki/Cram%C3%A9r%27s_V#Bias_correction). #' #' @inheritSection effectsize_CIs Confidence (Compatibility) Intervals (CIs) #' @inheritSection effectsize_CIs CIs and Significance Tests diff --git a/R/effectsize-package.R b/R/effectsize-package.R index ba31a5cd..d4351aff 100644 --- a/R/effectsize-package.R +++ b/R/effectsize-package.R @@ -18,8 +18,9 @@ #' and hypothesis tests, such as [cohens_d()], [phi()], [eta_squared()], and #' many more. #' -#' See [`vignette("effectsize", package = "effectsize")`](https://easystats.github.io/effectsize/articles/effectsize.html) for more details, -#' or [`vignette(package = "effectsize")`](https://easystats.github.io/effectsize/articles/) for a full list of vignettes. +#' See [`vignette("effectsize", package = "effectsize")`](https://easystats.github.io/effectsize/articles/effectsize.html) +#' for more details, or [`vignette(package = "effectsize")`](https://easystats.github.io/effectsize/articles/) +#' for a full list of vignettes. #' #' References: Ben-Shachar et al. (2020) \doi{10.21105/joss.02815}. #' diff --git a/R/xtab_diff.R b/R/xtab_diff.R index 3ce05331..a80f6455 100644 --- a/R/xtab_diff.R +++ b/R/xtab_diff.R @@ -295,7 +295,7 @@ arr <- function(x, y = NULL, ci = 0.95, alternative = "two.sided", ...) { nnt <- function(x, y = NULL, ci = 0.95, alternative = "two.sided", ...) { alternative <- .match.alt(alternative) - flip_alt <- c("less" = "greater", "greater" = "less", "two.sided" = "two.sided") + flip_alt <- c(less = "greater", greater = "less", two.sided = "two.sided") alternative2 <- unname(flip_alt[alternative]) if (.is_htest_of_type(x, "Pearson's Chi-squared", "Chi-squared-test")) { diff --git a/man/convert_chisq.Rd b/man/convert_chisq.Rd index 694eedb6..68da11c2 100644 --- a/man/convert_chisq.Rd +++ b/man/convert_chisq.Rd @@ -127,7 +127,8 @@ Where \eqn{p_E} are the expected probabilities. \deqn{\textrm{Pearson's } C = \sqrt{\chi^2 / (\chi^2 + n)}}{Pearson's C = sqrt(\chi^2 / (\chi^2 + n))} -For versions adjusted for small-sample bias of \eqn{\phi}, \eqn{V}, and \eqn{T}, see \href{https://en.wikipedia.org/wiki/Cram\%C3\%A9r\%27s_V#Bias_correction}{Bergsma, 2013}. +For versions adjusted for small-sample bias of \eqn{\phi}, \eqn{V}, and \eqn{T}, +see \href{https://en.wikipedia.org/wiki/Cram\%C3\%A9r\%27s_V#Bias_correction}{Bergsma, 2013}. } \section{Confidence (Compatibility) Intervals (CIs)}{ Unless stated otherwise, confidence (compatibility) intervals (CIs) are diff --git a/man/effectsize-package.Rd b/man/effectsize-package.Rd index 6098ac39..30c9a441 100644 --- a/man/effectsize-package.Rd +++ b/man/effectsize-package.Rd @@ -20,8 +20,9 @@ and their confidence intervals (CIs), from a variety of statistical models and hypothesis tests, such as \code{\link[=cohens_d]{cohens_d()}}, \code{\link[=phi]{phi()}}, \code{\link[=eta_squared]{eta_squared()}}, and many more. -See \href{https://easystats.github.io/effectsize/articles/effectsize.html}{\code{vignette("effectsize", package = "effectsize")}} for more details, -or \href{https://easystats.github.io/effectsize/articles/}{\code{vignette(package = "effectsize")}} for a full list of vignettes. +See \href{https://easystats.github.io/effectsize/articles/effectsize.html}{\code{vignette("effectsize", package = "effectsize")}} +for more details, or \href{https://easystats.github.io/effectsize/articles/}{\code{vignette(package = "effectsize")}} +for a full list of vignettes. References: Ben-Shachar et al. (2020) \doi{10.21105/joss.02815}. } diff --git a/tests/testthat/test-effectsize.R b/tests/testthat/test-effectsize.R index 55208059..32b7d160 100644 --- a/tests/testthat/test-effectsize.R +++ b/tests/testthat/test-effectsize.R @@ -252,14 +252,56 @@ test_that("htest | rank", { }) test_that("htest | Get args from htest", { - tt <- t.test(mtcars$hp, mtcars$mpg, alternative = "l", mu = -3, conf.level = 0.8, var.equal = TRUE) - expect_equal(cohens_d(tt), cohens_d(mtcars$hp, mtcars$mpg, alternative = "l", mu = -3, ci = 0.8), ignore_attr = TRUE) + tt <- t.test( + mtcars$hp, + mtcars$mpg, + alternative = "l", + mu = -3, + conf.level = 0.8, + var.equal = TRUE + ) + expect_equal( + cohens_d(tt), + cohens_d( + mtcars$hp, + mtcars$mpg, + alternative = "l", + mu = -3, + ci = 0.8 + ), + ignore_attr = TRUE + ) - suppressWarnings(ww1 <- wilcox.test(mtcars$hp, mtcars$mpg, alternative = "l", mu = -3)) - expect_equal(rank_biserial(ww1), rank_biserial(mtcars$hp, mtcars$mpg, alternative = "l", mu = -3), ignore_attr = TRUE) + suppressWarnings({ + ww1 <- wilcox.test(mtcars$hp, mtcars$mpg, alternative = "l", mu = -3) + }) + expect_equal( + rank_biserial(ww1), + rank_biserial(mtcars$hp, mtcars$mpg, alternative = "l", mu = -3), + ignore_attr = TRUE + ) - suppressWarnings(ww2 <- wilcox.test(mtcars$hp, mtcars$mpg, alternative = "l", mu = -3, conf.int = TRUE, conf.level = 0.8)) - expect_equal(rank_biserial(ww2), rank_biserial(mtcars$hp, mtcars$mpg, alternative = "l", mu = -3, ci = 0.8), ignore_attr = TRUE) + suppressWarnings({ + ww2 <- wilcox.test( + mtcars$hp, + mtcars$mpg, + alternative = "l", + mu = -3, + conf.int = TRUE, + conf.level = 0.8 + ) + }) + expect_equal( + rank_biserial(ww2), + rank_biserial( + mtcars$hp, + mtcars$mpg, + alternative = "l", + mu = -3, + ci = 0.8 + ), + ignore_attr = TRUE + ) }) diff --git a/tests/testthat/test-eta_squared.R b/tests/testthat/test-eta_squared.R index 56a9f07f..fbf89769 100644 --- a/tests/testthat/test-eta_squared.R +++ b/tests/testthat/test-eta_squared.R @@ -516,19 +516,47 @@ test_that("afex | mixed()", { # Intercept data("stroop", package = "afex") stroop <- subset(stroop, study == 1 & acc == 1 & trialnum < 20) - suppressMessages(m1 <- afex::mixed(rt ~ condition + (condition | pno), data = stroop, method = "KR")) - suppressMessages(m2 <- afex::mixed(rt ~ condition + (condition | pno), data = stroop, test_intercept = TRUE, method = "KR")) + suppressMessages({ + m1 <- afex::mixed(rt ~ condition + (condition | pno), data = stroop, method = "KR") + }) + suppressMessages({ + m2 <- afex::mixed(rt ~ condition + (condition | pno), + data = stroop, + test_intercept = TRUE, + method = "KR" + ) + }) - expect_warning(a1a <- eta_squared(m1, include_intercept = TRUE), regexp = "Intercept") - expect_warning(a1b <- eta_squared(m1, include_intercept = FALSE), regexp = NA) + expect_warning( + { + a1a <- eta_squared(m1, include_intercept = TRUE) + }, + regexp = "Intercept" + ) + expect_warning( + { + a1b <- eta_squared(m1, include_intercept = FALSE) + }, + regexp = NA + ) expect_equal(a1a, a1b) expect_equal(nrow(a1a), 1L) - expect_warning(a2a <- eta_squared(m2, include_intercept = TRUE), regexp = NA) - expect_warning(a2b <- eta_squared(m2, include_intercept = FALSE), regexp = NA) + expect_warning( + { + a2a <- eta_squared(m2, include_intercept = TRUE) + }, + regexp = NA + ) + expect_warning( + { + a2b <- eta_squared(m2, include_intercept = FALSE) + }, + regexp = NA + ) expect_equal(nrow(a2a), 2L) expect_equal(nrow(a2b), 1L) - expect_equal(a1a, a2a[2, ], ignore_attr = TRUE) + expect_equal(a1a, a2a[2L, ], ignore_attr = TRUE) }) @@ -546,17 +574,18 @@ test_that("car MVM", { id = 1:8 ) - ds_long <- - datawizard::reshape_longer(ds, - select = 1:4, - names_to = "ind_var", - values_to = "score" - ) + ds_long <- datawizard::reshape_longer(ds, + select = 1:4, + names_to = "ind_var", + values_to = "score" + ) fit <- lm(cbind(I, II, III, IV) ~ 1, data = ds) - in_rep <- data.frame(ind_var = gl(4, 1)) - suppressMessages(A_car <- car::Anova(fit, idata = in_rep, idesign = ~ind_var)) + in_rep <- data.frame(ind_var = gl(4L, 1L)) + suppressMessages({ + A_car <- car::Anova(fit, idata = in_rep, idesign = ~ind_var) + }) eta_car <- effectsize::eta_squared(A_car, ci = NULL)[[2]] @@ -570,11 +599,13 @@ test_that("car MVM", { # Complex --- data(obk.long, package = "afex") - suppressMessages(mod <- afex::aov_ez("id", "value", obk.long, - between = c("treatment", "gender"), - within = c("phase", "hour"), - observed = "gender" - )) + suppressMessages({ + mod <- afex::aov_ez("id", "value", obk.long, + between = c("treatment", "gender"), + within = c("phase", "hour"), + observed = "gender" + ) + }) expect_equal( sort(eta_squared(mod$Anova, generalized = "gender")[[2]]), sort(mod$anova_table$ges) @@ -592,7 +623,7 @@ test_that("Anova.mlm Manova", { mod <- lm(cbind(mpg, qsec, disp) ~ am_f * cyl_f, data = mtcars) - Manova <- car::Manova(mod, type = 2) + Manova <- car::Manova(mod, type = 2L) expect_true(is.null(summary(Manova, univariate = TRUE)[["univariate.tests"]])) expect_error(eta_squared(Manova), regexp = NA) @@ -622,8 +653,8 @@ test_that("merMod and lmerModLmerTest", { data("sleepstudy", package = "lme4") - m <- lme4::lmer(Reaction ~ Days + (Days | Subject), sleepstudy) - mtest <- lmerTest::lmer(Reaction ~ Days + (Days | Subject), sleepstudy) + m <- lme4::lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) + mtest <- lmerTest::lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy) expect_equal( eta_squared(m), @@ -676,7 +707,7 @@ test_that("ets_squared | rms", { skip_if_not_installed("car") skip_if_not_installed("base", minimum_version = "3.6.1") - b_lm <- car::Anova(lm(mpg ~ cyl + am, data = mtcars), type = 2) + b_lm <- car::Anova(lm(mpg ~ cyl + am, data = mtcars), type = 2L) out_lm <- eta_squared(b_lm) expect_equal(out[1:2, ], out_lm, ignore_attr = TRUE) })