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 #133 proliferate conf.level argument as appropriate across package #142

Merged
merged 3 commits into from
May 3, 2024
Merged
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
13 changes: 8 additions & 5 deletions R/ard_effectsize_cohens_d.R
Original file line number Diff line number Diff line change
@@ -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,
12 changes: 8 additions & 4 deletions R/ard_effectsize_hedges_g.R
Original file line number Diff line number Diff line change
@@ -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")
}),
7 changes: 5 additions & 2 deletions R/ard_stats_fisher_test.R
Original file line number Diff line number Diff line change
@@ -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 =
6 changes: 5 additions & 1 deletion R/ard_stats_prop_test.R
Original file line number Diff line number Diff line change
@@ -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() |>
11 changes: 7 additions & 4 deletions R/ard_stats_t_test.R
Original file line number Diff line number Diff line change
@@ -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,
11 changes: 7 additions & 4 deletions R/ard_stats_wilcox_test.R
Original file line number Diff line number Diff line change
@@ -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,
2 changes: 1 addition & 1 deletion R/ard_survey_svychisq.R
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions man/ard_effectsize_cohens_d.Rd

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

7 changes: 5 additions & 2 deletions man/ard_effectsize_hedges_g.Rd

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

5 changes: 4 additions & 1 deletion man/ard_stats_fisher_test.Rd

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

5 changes: 4 additions & 1 deletion man/ard_stats_prop_test.Rd

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

7 changes: 5 additions & 2 deletions man/ard_stats_t_test.Rd
7 changes: 5 additions & 2 deletions man/ard_stats_wilcox_test.Rd
2 changes: 1 addition & 1 deletion man/ard_survey_svychisq.Rd