Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary import directives #607

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -30,13 +30,13 @@
#' \ifelse{latex}{
#' \deqn{\textrm{Cramer's } V = \phi / \sqrt{\min(\textit{nrow}, \textit{ncol}) - 1}}
#' }{
#' \deqn{\textrm{Cramer's } V = \phi / \sqrt{\min(\textit{nrow}, \textit{ncol}) - 1}}{Cramer's V = \phi / sqrt(min(nrow, ncol) - 1)}

Check warning on line 33 in R/convert_stat_chisq.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/convert_stat_chisq.R,line=33,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 132 characters.
#' }
#'
#' \ifelse{latex}{
#' \deqn{\textrm{Tschuprow's } T = \phi / \sqrt[4]{(\textit{nrow} - 1) \times (\textit{ncol} - 1)}}
#' }{
#' \deqn{\textrm{Tschuprow's } T = \phi / \sqrt[4]{(\textit{nrow} - 1) \times (\textit{ncol} - 1)}}{Tschuprow's T = \phi / sqrt(sqrt((nrow-1) * (ncol-1)))}

Check warning on line 39 in R/convert_stat_chisq.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/convert_stat_chisq.R,line=39,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 155 characters.
#' }
#'
#' \ifelse{latex}{
Expand All @@ -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)

Check warning on line 21 in R/effectsize-package.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/effectsize-package.R,line=21,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 122 characters.
#' 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 @@ -23,7 +23,7 @@
#' @param verbose Toggle warnings and messages on or off.
#' @inheritParams chisq_to_phi
#' @param ... Arguments passed to or from other methods.
#' - Can be `include_intercept = TRUE` to include the effect size for the intercept (when it is included in the ANOVA table).

Check warning on line 26 in R/eta_squared-main.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/eta_squared-main.R,line=26,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 127 characters.
#' - For Bayesian models, arguments passed to `ss_function`.
#'
#' @return
Expand Down Expand Up @@ -248,7 +248,7 @@
ci = 0.95, alternative = "greater",
verbose = TRUE, ...) {
alternative <- .match.alt(alternative, FALSE)
out <- .anova_es(model, type = "epsilon", partial = partial, ci = ci, alternative = alternative, verbose = verbose, ...)

Check warning on line 251 in R/eta_squared-main.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/eta_squared-main.R,line=251,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 122 characters.
class(out) <- unique(c("effectsize_anova", "effectsize_table", "see_effectsize_table", class(out)))
if ("CI" %in% colnames(out)) attr(out, "ci_method") <- list(method = "ncp", distribution = "F")
attr(out, "approximate") <- isTRUE(attr(out, "approximate", exact = TRUE))
Expand Down Expand Up @@ -294,7 +294,7 @@

es_name <- get_effectsize_name(colnames(res))
res[[es_name]] <- res[[es_name]] / (1 - res[[es_name]])
if (grepl("_partial", es_name)) {

Check warning on line 297 in R/eta_squared-main.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/eta_squared-main.R,line=297,col=13,[fixed_regex_linter] This regular expression is static, i.e., its matches can be expressed as a fixed substring expression, which is faster to compute. Here, you can use "_partial" with fixed = TRUE.
colnames(res)[colnames(res) == es_name] <- "Cohens_f2_partial"
} else {
colnames(res)[colnames(res) == es_name] <- "Cohens_f2"
Expand All @@ -316,7 +316,7 @@
if ("CI" %in% colnames(res)) attr(res, "ci_method") <- list(method = "ncp", distribution = "F")
class(res) <- unique(c("effectsize_anova", "effectsize_table", "see_effectsize_table", class(res)))
attr(res, "approximate") <- isTRUE(attr(res, "approximate", exact = TRUE))
attr(res, "table_footer") <- if (method != "eta") sprintf("Based on %s squared.", paste0(toupper(substring(method, 1, 1)), substring(method, 2)))

Check warning on line 319 in R/eta_squared-main.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/eta_squared-main.R,line=319,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 147 characters.
res
}

Expand Down Expand Up @@ -448,7 +448,7 @@

aov_table$Eta2_generalized <- aov_table$Sum_Squares /
(aov_table$Sum_Squares + values$Sum_Squares_residuals + obs_SSn1 - obs_SSn2)
} else if (!isTRUE(partial)) {

Check warning on line 451 in R/eta_squared-main.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/eta_squared-main.R,line=451,col=16,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
aov_table$Eta2 <- aov_table$Sum_Squares /
values$Sum_Squares_total
} else {
Expand All @@ -457,7 +457,7 @@
(aov_table$Sum_Squares + values$Sum_Squares_residuals)
}
} else if (type == "omega") {
if (!isTRUE(partial)) {

Check warning on line 460 in R/eta_squared-main.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/eta_squared-main.R,line=460,col=9,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
aov_table$Omega2 <-
(aov_table$Sum_Squares - aov_table$df * values$Mean_Square_residuals) /
(values$Sum_Squares_total + values$Mean_Square_residuals)
Expand All @@ -469,7 +469,7 @@
aov_table$Omega2_partial <- pmax(0, aov_table$Omega2_partial)
}
} else if (type == "epsilon") {
if (!isTRUE(partial)) {

Check warning on line 472 in R/eta_squared-main.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/eta_squared-main.R,line=472,col=9,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
aov_table$Epsilon2 <-
(aov_table$Sum_Squares - aov_table$df * values$Mean_Square_residuals) /
values$Sum_Squares_total
Expand Down Expand Up @@ -764,7 +764,6 @@


#' @keywords internal
#' @importFrom stats anova
.anova_es.default <- function(model, ...) {
.anova_es.anova(stats::anova(model), ...)
}
Expand Down Expand Up @@ -842,8 +841,6 @@
}

#' @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 @@
.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)
})
Loading