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

Closes #103 update effectsize package and corresponding hedges_g code accordingly #153

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Suggests:
broom.helpers (>= 1.15.0),
broom.mixed (>= 0.2.9),
car (>= 3.0-11),
effectsize (>= 0.6.0),
effectsize (>= 0.8.8),
emmeans (>= 1.7.3),
geepack (>= 1.3.2),
ggsurvfit (>= 1.1.0),
Expand Down
28 changes: 9 additions & 19 deletions R/ard_effectsize_hedges_g.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#' The data are then passed as
#' `effectsize::hedges_g(x = data_wide[[<by level 1>]], y = data_wide[[<by level 2>]], paired = TRUE, ...)`.
#'
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters", "withr"), reference_pkg = "cardx"))
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters"), reference_pkg = "cardx"))
#' cards::ADSL |>
#' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |>
#' ard_effectsize_hedges_g(by = ARM, variables = AGE)
Expand All @@ -52,7 +52,7 @@ ard_effectsize_hedges_g <- function(data, by, variables, conf.level = 0.95, ...)
set_cli_abort_call()

# check installed packages ---------------------------------------------------
check_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")
check_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")

# check/process inputs -------------------------------------------------------
check_not_missing(data)
Expand All @@ -77,19 +77,12 @@ ard_effectsize_hedges_g <- function(data, by, variables, conf.level = 0.95, ...)
variable = variable,
lst_tidy =
cards::eval_capture_conditions(
# Need to eval in NAMESAPCE DUE TO BUG IN effectsize v0.8.7.
# Can remove this later along with requirements for withr to be installed.
# Will also need to remove `hedges_g` from globalVariables()
withr::with_namespace(
package = "effectsize",
code =
hedges_g(
reformulate2(by, response = variable),
data = data |> tidyr::drop_na(all_of(c(by, variable))),
paired = FALSE,
ci = conf.level,
...
)
effectsize::hedges_g(
reformulate2(by, response = variable),
data = data |> tidyr::drop_na(all_of(c(by, variable))),
paired = FALSE,
ci = conf.level,
...
) |>
parameters::standardize_names(style = "broom") |>
dplyr::mutate(method = "Hedge's G")
Expand Down Expand Up @@ -143,10 +136,7 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, conf.level =
.paired_data_pivot_wider(by = by, variable = variable, id = id) |>
tidyr::drop_na(any_of(c("by1", "by2")))
# perform paired cohen's d test
withr::with_namespace(
package = "effectsize",
code = hedges_g(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ci = conf.level, ...)
) |>
effectsize::hedges_g(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ci = conf.level, ...) |>
parameters::standardize_names(style = "broom") |>
dplyr::mutate(method = "Paired Hedge's G")
}),
Expand Down
2 changes: 1 addition & 1 deletion R/cardx-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
## usethis namespace: end
NULL

utils::globalVariables(c(".", "hedges_g"))
utils::globalVariables(c("."))
2 changes: 1 addition & 1 deletion man/ard_effectsize_hedges_g.Rd

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

10 changes: 3 additions & 7 deletions tests/testthat/test-ard_effectsize_hedges_g.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
skip_if_not(is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx"))
skip_if_not(is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx"))

test_that("ard_effectsize_hedges_g() works", {
withr::local_namespace("effectsize")

expect_error(
ard_hedges_g <-
cards::ADSL |>
Expand All @@ -14,7 +12,7 @@ test_that("ard_effectsize_hedges_g() works", {
expect_equal(
ard_hedges_g |>
cards::get_ard_statistics(stat_name %in% c("estimate", "conf.low", "conf.high")),
hedges_g(
effectsize::hedges_g(
AGE ~ ARM,
zdz2101 marked this conversation as resolved.
Show resolved Hide resolved
data = cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose"))
) |>
Expand Down Expand Up @@ -45,8 +43,6 @@ test_that("ard_effectsize_hedges_g() works", {
})

test_that("ard_effectsize_paired_hedges_g() works", {
withr::local_namespace("effectsize")

ADSL_paired <-
cards::ADSL[c("ARM", "AGE")] |>
dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |>
Expand All @@ -72,7 +68,7 @@ test_that("ard_effectsize_paired_hedges_g() works", {
by = "USUBJID"
),
expr =
hedges_g(
effectsize::hedges_g(
x = AGE1,
y = AGE2,
paired = TRUE
Expand Down
Loading