Skip to content

Commit

Permalink
effectsize.htest get hedges g
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Dec 30, 2020
1 parent 089c10b commit 86ef40e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/effectsize.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @details
#'
#' - For an object of class `htest`, data is extracted via [insight::get_data()], and passed to the relevant function according to:
#' - A **t-test** returns *Cohen's d*.
#' - A **t-test** depending on `type`: `"cohens_d"` (default), `"hedges_g"`.
#' - A **correlation test** returns *r*.
#' - A **Chi-squared tests of independence or goodness-of-fit**, depending on `type`: `"cramers_v"` (default), `"phi"` or `"cohens_w"`, `"oddsratio"`, or `"riskratio"`.
#' - A **One-way ANOVA test**, depending on `type`: `"eta"` (default), `"omega"` or `"epsilon"` -squared, `"f"`, or `"f2"`.
Expand Down
20 changes: 15 additions & 5 deletions R/effectsize.htest.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ effectsize.htest <- function(model, type = NULL, verbose = TRUE, ...) {
...
)
} else {
out <- cohens_d(data$x, data$y,
mu = model$null.value,
paired = !grepl("Two", model$method),
pooled_sd = !grepl("Welch", model$method),
...)
if (is.null(type)) type <- "d"
f <- switch(tolower(type),
d = ,
cohens_d = cohens_d,

g = ,
hedges_g = hedges_g
)


out <- f(data$x, data$y,
mu = model$null.value,
paired = !grepl("Two", model$method),
pooled_sd = !grepl("Welch", model$method),
...)
}

return(out)
Expand Down
2 changes: 1 addition & 1 deletion man/effectsize.Rd

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

1 change: 1 addition & 0 deletions tests/testthat/test-effectsize.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (require("testthat") && require("effectsize")) {
y <<- c(1,1:9)
model <- t.test(x, y)
expect_equal(effectsize(model), cohens_d(x, y, pooled_sd = FALSE), ignore_attr = TRUE)
expect_equal(effectsize(model, type = "g"), hedges_g(x, y, pooled_sd = FALSE), ignore_attr = TRUE)

model <- t.test(x, y, paired = TRUE)
expect_equal(effectsize(model), cohens_d(x, y, paired = TRUE), ignore_attr = TRUE)
Expand Down

0 comments on commit 86ef40e

Please sign in to comment.