From cea214ddb215f47b14602da4df14e5b64268256e Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 5 May 2024 21:17:18 -0700 Subject: [PATCH] removing missing values before calculating values to avoid note about NA values being dropped --- R/ard_effectsize_cohens_d.R | 13 +++++++++++-- R/ard_effectsize_hedges_g.R | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/R/ard_effectsize_cohens_d.R b/R/ard_effectsize_cohens_d.R index 1babbd898..b6e9d29a7 100644 --- a/R/ard_effectsize_cohens_d.R +++ b/R/ard_effectsize_cohens_d.R @@ -77,7 +77,13 @@ ard_effectsize_cohens_d <- function(data, by, variables, conf.level = 0.95, ...) variable = variable, lst_tidy = cards::eval_capture_conditions( - effectsize::cohens_d(data[[variable]] ~ data[[by]], data = data, paired = FALSE, ci = conf.level, ...) |> + effectsize::cohens_d( + 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 = "Cohen's D") ), @@ -125,7 +131,10 @@ ard_effectsize_paired_cohens_d <- function(data, by, variables, id, conf.level = lst_tidy = cards::eval_capture_conditions({ # adding this reshape inside the eval, so if there is an error it's captured in the ARD object - data_wide <- .paired_data_pivot_wider(data, by = by, variable = variable, id = id) + data_wide <- + data |> + tidyr::drop_na(all_of(c(id, by, variable))) |> + .paired_data_pivot_wider(by = by, variable = variable, id = id) # perform paired cohen's d test effectsize::cohens_d(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ci = conf.level, ...) |> parameters::standardize_names(style = "broom") |> diff --git a/R/ard_effectsize_hedges_g.R b/R/ard_effectsize_hedges_g.R index d130b7b4f..f129a5186 100644 --- a/R/ard_effectsize_hedges_g.R +++ b/R/ard_effectsize_hedges_g.R @@ -82,7 +82,14 @@ ard_effectsize_hedges_g <- function(data, by, variables, conf.level = 0.95, ...) # Will also need to remove `hedges_g` from globalVariables() withr::with_namespace( package = "effectsize", - code = hedges_g(data[[variable]] ~ data[[by]], paired = FALSE, ci = conf.level, ...) + code = + 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") @@ -130,7 +137,10 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, conf.level = lst_tidy = cards::eval_capture_conditions({ # adding this reshape inside the eval, so if there is an error it's captured in the ARD object - data_wide <- .paired_data_pivot_wider(data, by = by, variable = variable, id = id) + data_wide <- + data |> + tidyr::drop_na(all_of(c(id, by, variable))) |> + .paired_data_pivot_wider(by = by, variable = variable, id = id) # perform paired cohen's d test withr::with_namespace( package = "effectsize",