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
Show file tree
Hide file tree
Changes from 2 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
10 changes: 6 additions & 4 deletions R/ard_effectsize_cohens_d.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ---------------------------------------------------
Expand Down Expand Up @@ -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,
Expand All @@ -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 ---------------------------------------------------
Expand Down Expand Up @@ -123,7 +125,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,
Expand Down
10 changes: 6 additions & 4 deletions R/ard_effectsize_hedges_g.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ---------------------------------------------------
Expand Down Expand Up @@ -79,7 +81,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")
),
Expand All @@ -93,7 +95,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 ---------------------------------------------------
Expand Down Expand Up @@ -129,7 +131,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")
}),
Expand Down
6 changes: 4 additions & 2 deletions R/ard_stats_fisher_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ---------------------------------------------------
Expand All @@ -45,7 +47,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 =
Expand Down
5 changes: 4 additions & 1 deletion R/ard_stats_prop_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ---------------------------------------------------
Expand Down Expand Up @@ -72,6 +74,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() |>
Expand Down
10 changes: 6 additions & 4 deletions R/ard_stats_t_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ---------------------------------------------------
Expand Down Expand Up @@ -72,7 +74,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
Expand All @@ -86,7 +88,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 ---------------------------------------------------
Expand Down Expand Up @@ -120,7 +122,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,
Expand Down
10 changes: 6 additions & 4 deletions R/ard_stats_wilcox_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ---------------------------------------------------
Expand Down Expand Up @@ -73,7 +75,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 {
Expand All @@ -92,7 +94,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 ---------------------------------------------------
Expand Down Expand Up @@ -126,7 +128,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,
Expand Down
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

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_wilcox_test.Rd

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

Loading