diff --git a/R/ard_effectsize_cohens_d.R b/R/ard_effectsize_cohens_d.R index b0c51df9b..91f5441a1 100644 --- a/R/ard_effectsize_cohens_d.R +++ b/R/ard_effectsize_cohens_d.R @@ -13,6 +13,8 @@ #' Independent tests will be run for each variable. #' @param id ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' column name of the subject or participant ID +#' @param conf.level (scalar `numeric`)\cr +#' confidence level for confidence interval. Default is `0.95`. #' @param ... arguments passed to `effectsize::cohens_d(...)` #' #' @return ARD data frame @@ -46,7 +48,7 @@ NULL #' @rdname ard_effectsize_cohens_d #' @export -ard_effectsize_cohens_d <- function(data, by, variables, ...) { +ard_effectsize_cohens_d <- function(data, by, variables, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -60,7 +62,7 @@ ard_effectsize_cohens_d <- function(data, by, variables, ...) { data <- dplyr::ungroup(data) cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by) - + check_range(conf.level, range = c(0, 1)) # if no variables selected, return empty tibble ------------------------------ if (is_empty(variables)) { return(dplyr::tibble()) @@ -75,7 +77,7 @@ ard_effectsize_cohens_d <- function(data, by, variables, ...) { variable = variable, lst_tidy = cards::eval_capture_conditions( - effectsize::cohens_d(data[[variable]] ~ data[[by]], data = data, paired = FALSE, ...) |> + effectsize::cohens_d(data[[variable]] ~ data[[by]], data = data, paired = FALSE, ci = conf.level, ...) |> parameters::standardize_names(style = "broom") ), paired = FALSE, @@ -89,7 +91,7 @@ ard_effectsize_cohens_d <- function(data, by, variables, ...) { #' @rdname ard_effectsize_cohens_d #' @export -ard_effectsize_paired_cohens_d <- function(data, by, variables, id, ...) { +ard_effectsize_paired_cohens_d <- function(data, by, variables, id, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -105,6 +107,7 @@ ard_effectsize_paired_cohens_d <- function(data, by, variables, id, ...) { cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}, id = {{ id }}) check_scalar(by) check_scalar(id) + check_range(conf.level, range = c(0, 1)) # if no variables selected, return empty tibble ------------------------------ if (is_empty(variables)) { @@ -123,7 +126,7 @@ ard_effectsize_paired_cohens_d <- function(data, by, variables, id, ...) { # 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) # perform paired cohen's d test - effectsize::cohens_d(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ...) |> + effectsize::cohens_d(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ci = conf.level, ...) |> parameters::standardize_names(style = "broom") }), paired = TRUE, diff --git a/R/ard_effectsize_hedges_g.R b/R/ard_effectsize_hedges_g.R index 3cdcf3a8d..58b228b5d 100644 --- a/R/ard_effectsize_hedges_g.R +++ b/R/ard_effectsize_hedges_g.R @@ -13,6 +13,8 @@ #' tests will be run for each variable #' @param id ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' column name of the subject or participant ID +#' @param conf.level (scalar `numeric`)\cr +#' confidence level for confidence interval. Default is `0.95`. #' @param ... arguments passed to `effectsize::hedges_g(...)` #' #' @return ARD data frame @@ -46,7 +48,7 @@ NULL #' @rdname ard_effectsize_hedges_g #' @export -ard_effectsize_hedges_g <- function(data, by, variables, ...) { +ard_effectsize_hedges_g <- function(data, by, variables, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -59,6 +61,7 @@ ard_effectsize_hedges_g <- function(data, by, variables, ...) { data <- dplyr::ungroup(data) cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by) + check_range(conf.level, range = c(0, 1)) # if no variables selected, return empty tibble ------------------------------ if (is_empty(variables)) { @@ -79,7 +82,7 @@ ard_effectsize_hedges_g <- function(data, by, variables, ...) { # Will also need to remove `hedges_g` from globalVariables() withr::with_namespace( package = "effectsize", - code = hedges_g(data[[variable]] ~ data[[by]], paired = FALSE, ...) + code = hedges_g(data[[variable]] ~ data[[by]], paired = FALSE, ci = conf.level, ...) ) |> parameters::standardize_names(style = "broom") ), @@ -93,7 +96,7 @@ ard_effectsize_hedges_g <- function(data, by, variables, ...) { #' @rdname ard_effectsize_hedges_g #' @export -ard_effectsize_paired_hedges_g <- function(data, by, variables, id, ...) { +ard_effectsize_paired_hedges_g <- function(data, by, variables, id, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -109,6 +112,7 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, ...) { cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}, id = {{ id }}) check_scalar(by) check_scalar(id) + check_range(conf.level, range = c(0, 1)) # if no variables selected, return empty tibble ------------------------------ if (is_empty(variables)) { @@ -129,7 +133,7 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, ...) { # perform paired cohen's d test withr::with_namespace( package = "effectsize", - code = hedges_g(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ...) + code = hedges_g(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ci = conf.level, ...) ) |> parameters::standardize_names(style = "broom") }), diff --git a/R/ard_stats_fisher_test.R b/R/ard_stats_fisher_test.R index 8fa50ce46..0831f45bc 100644 --- a/R/ard_stats_fisher_test.R +++ b/R/ard_stats_fisher_test.R @@ -12,6 +12,8 @@ #' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' column names to be compared. Independent tests will be computed for #' each variable. +#' @param conf.level (scalar `numeric`)\cr +#' confidence level for confidence interval. Default is `0.95`. #' @param ... additional arguments passed to `fisher.test(...)` #' #' @return ARD data frame @@ -20,7 +22,7 @@ #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL[1:30, ] |> #' ard_stats_fisher_test(by = "ARM", variables = "AGEGR1") -ard_stats_fisher_test <- function(data, by, variables, ...) { +ard_stats_fisher_test <- function(data, by, variables, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -33,6 +35,7 @@ ard_stats_fisher_test <- function(data, by, variables, ...) { check_data_frame(data) cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by) + check_range(conf.level, range = c(0, 1)) # if no variables selected, return empty tibble ------------------------------ if (is_empty(variables)) { @@ -45,7 +48,7 @@ ard_stats_fisher_test <- function(data, by, variables, ...) { cards::tidy_as_ard( lst_tidy = cards::eval_capture_conditions( - stats::fisher.test(x = data[[variable]], y = data[[by]], ...) |> + stats::fisher.test(x = data[[variable]], y = data[[by]], conf.level = conf.level, ...) |> broom::tidy() ), tidy_result_names = diff --git a/R/ard_stats_prop_test.R b/R/ard_stats_prop_test.R index f96784737..1b4389814 100644 --- a/R/ard_stats_prop_test.R +++ b/R/ard_stats_prop_test.R @@ -10,6 +10,8 @@ #' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' column names to be compared. Must be a binary column coded as `TRUE`/`FALSE` #' or `1`/`0`. Independent tests will be computed for each variable. +#' @param conf.level (scalar `numeric`)\cr +#' confidence level for confidence interval. Default is `0.95`. #' @param ... arguments passed to `prop.test(...)` #' #' @return ARD data frame @@ -18,7 +20,7 @@ #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' mtcars |> #' ard_stats_prop_test(by = vs, variables = am) -ard_stats_prop_test <- function(data, by, variables, ...) { +ard_stats_prop_test <- function(data, by, variables, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -29,6 +31,7 @@ ard_stats_prop_test <- function(data, by, variables, ...) { check_not_missing(variables) check_not_missing(by) check_data_frame(data) + check_range(conf.level, range = c(0, 1)) # process inputs ------------------------------------------------------------- cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) @@ -72,6 +75,7 @@ ard_stats_prop_test <- function(data, by, variables, ...) { stats::prop.test( x = data_counts[["x"]], n = data_counts[["n"]], + conf.level = conf.level, ... ) |> broom::tidy() |> diff --git a/R/ard_stats_t_test.R b/R/ard_stats_t_test.R index b506d981c..91e603c58 100644 --- a/R/ard_stats_t_test.R +++ b/R/ard_stats_t_test.R @@ -12,6 +12,8 @@ #' each variable. #' @param id ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' column name of the subject or participant ID +#' @param conf.level (scalar `numeric`)\cr +#' confidence level for confidence interval. Default is `0.95`. #' @param ... arguments passed to `t.test(...)` #' #' @return ARD data frame @@ -43,7 +45,7 @@ NULL #' @rdname ard_stats_t_test #' @export -ard_stats_t_test <- function(data, variables, by = NULL, ...) { +ard_stats_t_test <- function(data, variables, by = NULL, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -56,6 +58,7 @@ ard_stats_t_test <- function(data, variables, by = NULL, ...) { data <- dplyr::ungroup(data) cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by, allow_empty = TRUE) + check_range(conf.level, range = c(0, 1)) # if no variables selected, return empty tibble ------------------------------ if (is_empty(variables)) { @@ -72,7 +75,7 @@ ard_stats_t_test <- function(data, variables, by = NULL, ...) { lst_tidy = # styler: off cards::eval_capture_conditions( - if (!is_empty(by)) stats::t.test(data[[variable]] ~ data[[by]], ...) |> broom::tidy() + if (!is_empty(by)) stats::t.test(data[[variable]] ~ data[[by]], conf.level = conf.level, ...) |> broom::tidy() else stats::t.test(data[[variable]], ...) |> broom::tidy() ), # styler: on @@ -86,7 +89,7 @@ ard_stats_t_test <- function(data, variables, by = NULL, ...) { #' @rdname ard_stats_t_test #' @export -ard_stats_paired_t_test <- function(data, by, variables, id, ...) { +ard_stats_paired_t_test <- function(data, by, variables, id, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -120,7 +123,7 @@ ard_stats_paired_t_test <- function(data, by, variables, id, ...) { # 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) # perform paired t-test - stats::t.test(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ...) |> + stats::t.test(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, conf.level = conf.level, ...) |> broom::tidy() }), paired = TRUE, diff --git a/R/ard_stats_wilcox_test.R b/R/ard_stats_wilcox_test.R index c2a14bd49..5972230bb 100644 --- a/R/ard_stats_wilcox_test.R +++ b/R/ard_stats_wilcox_test.R @@ -12,6 +12,8 @@ #' each variable. #' @param id ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' column name of the subject or participant ID. +#' @param conf.level (scalar `numeric`)\cr +#' confidence level for confidence interval. Default is `0.95`. #' @param ... arguments passed to `wilcox.test(...)` #' #' @return ARD data frame @@ -43,7 +45,7 @@ NULL #' @rdname ard_stats_wilcox_test #' @export -ard_stats_wilcox_test <- function(data, variables, by = NULL, ...) { +ard_stats_wilcox_test <- function(data, variables, by = NULL, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -56,6 +58,7 @@ ard_stats_wilcox_test <- function(data, variables, by = NULL, ...) { data <- dplyr::ungroup(data) cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by, allow_empty = TRUE) + check_range(conf.level, range = c(0, 1)) # if no variables selected, return empty tibble ------------------------------ if (is_empty(variables)) { @@ -73,7 +76,7 @@ ard_stats_wilcox_test <- function(data, variables, by = NULL, ...) { # styler: off cards::eval_capture_conditions( if (!is_empty(by)) { - stats::wilcox.test(data[[variable]] ~ data[[by]], ...) |> + stats::wilcox.test(data[[variable]] ~ data[[by]], conf.level = conf.level, ...) |> broom::tidy() } else { @@ -92,7 +95,7 @@ ard_stats_wilcox_test <- function(data, variables, by = NULL, ...) { #' @rdname ard_stats_wilcox_test #' @export -ard_stats_paired_wilcox_test <- function(data, by, variables, id, ...) { +ard_stats_paired_wilcox_test <- function(data, by, variables, id, conf.level = 0.95, ...) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -126,7 +129,7 @@ ard_stats_paired_wilcox_test <- function(data, by, variables, id, ...) { # 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) # perform paired wilcox test - stats::wilcox.test(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, ...) |> + stats::wilcox.test(x = data_wide[["by1"]], y = data_wide[["by2"]], paired = TRUE, conf.level = conf.level, ...) |> broom::tidy() }), paired = TRUE, diff --git a/R/ard_survey_svychisq.R b/R/ard_survey_svychisq.R index 8fb57325f..5ad520a42 100644 --- a/R/ard_survey_svychisq.R +++ b/R/ard_survey_svychisq.R @@ -5,7 +5,7 @@ #' Only two-way comparisons are supported. #' #' @param data (`survey.design`)\cr -#' a survey design object often created with the {survey} package +#' a survey design object often created with the \{survey\} package #' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr #' column name to compare by. #' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr diff --git a/man/ard_effectsize_cohens_d.Rd b/man/ard_effectsize_cohens_d.Rd index 3eb2ac94e..93c907aa6 100644 --- a/man/ard_effectsize_cohens_d.Rd +++ b/man/ard_effectsize_cohens_d.Rd @@ -5,9 +5,9 @@ \alias{ard_effectsize_paired_cohens_d} \title{ARD Cohen's D Test} \usage{ -ard_effectsize_cohens_d(data, by, variables, ...) +ard_effectsize_cohens_d(data, by, variables, conf.level = 0.95, ...) -ard_effectsize_paired_cohens_d(data, by, variables, id, ...) +ard_effectsize_paired_cohens_d(data, by, variables, id, conf.level = 0.95, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -20,6 +20,9 @@ column name to compare by. Must be a categorical variable with exactly two level column names to be compared. Must be a continuous variables. Independent tests will be run for each variable.} +\item{conf.level}{(scalar \code{numeric})\cr +confidence level for confidence interval. Default is \code{0.95}.} + \item{...}{arguments passed to \code{effectsize::cohens_d(...)}} \item{id}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr diff --git a/man/ard_effectsize_hedges_g.Rd b/man/ard_effectsize_hedges_g.Rd index 5ec59117a..23c43e8d2 100644 --- a/man/ard_effectsize_hedges_g.Rd +++ b/man/ard_effectsize_hedges_g.Rd @@ -5,9 +5,9 @@ \alias{ard_effectsize_paired_hedges_g} \title{ARD Hedge's G Test} \usage{ -ard_effectsize_hedges_g(data, by, variables, ...) +ard_effectsize_hedges_g(data, by, variables, conf.level = 0.95, ...) -ard_effectsize_paired_hedges_g(data, by, variables, id, ...) +ard_effectsize_paired_hedges_g(data, by, variables, id, conf.level = 0.95, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -20,6 +20,9 @@ column name to compare by. Must be a categorical variable with exactly two level column names to be compared. Must be a continuous variable. Independent tests will be run for each variable} +\item{conf.level}{(scalar \code{numeric})\cr +confidence level for confidence interval. Default is \code{0.95}.} + \item{...}{arguments passed to \code{effectsize::hedges_g(...)}} \item{id}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr diff --git a/man/ard_stats_fisher_test.Rd b/man/ard_stats_fisher_test.Rd index 1e07809b0..7831e81e9 100644 --- a/man/ard_stats_fisher_test.Rd +++ b/man/ard_stats_fisher_test.Rd @@ -4,7 +4,7 @@ \alias{ard_stats_fisher_test} \title{ARD Fisher's Exact Test} \usage{ -ard_stats_fisher_test(data, by, variables, ...) +ard_stats_fisher_test(data, by, variables, conf.level = 0.95, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -17,6 +17,9 @@ column name to compare by} column names to be compared. Independent tests will be computed for each variable.} +\item{conf.level}{(scalar \code{numeric})\cr +confidence level for confidence interval. Default is \code{0.95}.} + \item{...}{additional arguments passed to \code{fisher.test(...)}} } \value{ diff --git a/man/ard_stats_prop_test.Rd b/man/ard_stats_prop_test.Rd index cb966e1c4..61bf61791 100644 --- a/man/ard_stats_prop_test.Rd +++ b/man/ard_stats_prop_test.Rd @@ -4,7 +4,7 @@ \alias{ard_stats_prop_test} \title{ARD 2-sample proportion test} \usage{ -ard_stats_prop_test(data, by, variables, ...) +ard_stats_prop_test(data, by, variables, conf.level = 0.95, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -17,6 +17,9 @@ column name to compare by} column names to be compared. Must be a binary column coded as \code{TRUE}/\code{FALSE} or \code{1}/\code{0}. Independent tests will be computed for each variable.} +\item{conf.level}{(scalar \code{numeric})\cr +confidence level for confidence interval. Default is \code{0.95}.} + \item{...}{arguments passed to \code{prop.test(...)}} } \value{ diff --git a/man/ard_stats_t_test.Rd b/man/ard_stats_t_test.Rd index 1bfb7fbe9..edd55ee94 100644 --- a/man/ard_stats_t_test.Rd +++ b/man/ard_stats_t_test.Rd @@ -5,9 +5,9 @@ \alias{ard_stats_paired_t_test} \title{ARD t-test} \usage{ -ard_stats_t_test(data, variables, by = NULL, ...) +ard_stats_t_test(data, variables, by = NULL, conf.level = 0.95, ...) -ard_stats_paired_t_test(data, by, variables, id, ...) +ard_stats_paired_t_test(data, by, variables, id, conf.level = 0.95, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -20,6 +20,9 @@ each variable.} \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr optional column name to compare by.} +\item{conf.level}{(scalar \code{numeric})\cr +confidence level for confidence interval. Default is \code{0.95}.} + \item{...}{arguments passed to \code{t.test(...)}} \item{id}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr diff --git a/man/ard_stats_wilcox_test.Rd b/man/ard_stats_wilcox_test.Rd index 14f48b213..86486171b 100644 --- a/man/ard_stats_wilcox_test.Rd +++ b/man/ard_stats_wilcox_test.Rd @@ -5,9 +5,9 @@ \alias{ard_stats_paired_wilcox_test} \title{ARD Wilcoxon Rank-Sum Test} \usage{ -ard_stats_wilcox_test(data, variables, by = NULL, ...) +ard_stats_wilcox_test(data, variables, by = NULL, conf.level = 0.95, ...) -ard_stats_paired_wilcox_test(data, by, variables, id, ...) +ard_stats_paired_wilcox_test(data, by, variables, id, conf.level = 0.95, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -20,6 +20,9 @@ each variable.} \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr optional column name to compare by.} +\item{conf.level}{(scalar \code{numeric})\cr +confidence level for confidence interval. Default is \code{0.95}.} + \item{...}{arguments passed to \code{wilcox.test(...)}} \item{id}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr diff --git a/man/ard_survey_svychisq.Rd b/man/ard_survey_svychisq.Rd index e645f5c00..05d660264 100644 --- a/man/ard_survey_svychisq.Rd +++ b/man/ard_survey_svychisq.Rd @@ -8,7 +8,7 @@ ard_survey_svychisq(data, by, variables, statistic = "F", ...) } \arguments{ \item{data}{(\code{survey.design})\cr -a survey design object often created with the {survey} package} +a survey design object often created with the \{survey\} package} \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr column name to compare by.}