Skip to content

Commit

Permalink
Remove unnecessary import directives (#607)
Browse files Browse the repository at this point in the history
* Remove unnecessary import directives

Discovered while thinking about easystats/easystats#379

* fix strict workflow

* clean up some lints
  • Loading branch information
IndrajeetPatil authored Sep 20, 2023
1 parent 09e3209 commit 9a6bb14
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 53 deletions.
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion R/cohens_d.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion R/convert_stat_chisq.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions R/effectsize-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
#'
Expand Down
5 changes: 0 additions & 5 deletions R/eta_squared-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -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), ...)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions R/eta_squared-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/xtab_diff.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
3 changes: 2 additions & 1 deletion man/convert_chisq.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/effectsize-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 48 additions & 6 deletions tests/testthat/test-effectsize.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
})


Expand Down
79 changes: 55 additions & 24 deletions tests/testthat/test-eta_squared.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})


Expand All @@ -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]]

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
})

0 comments on commit 9a6bb14

Please sign in to comment.