-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 46_ard_basic
- Loading branch information
Showing
30 changed files
with
848 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: cardx | ||
Title: Extra Analysis Results Data Utilities | ||
Version: 0.0.0.9038 | ||
Version: 0.0.0.9043 | ||
Authors@R: c( | ||
person("Daniel", "Sjoberg", , "[email protected]", role = c("aut", "cre")), | ||
person("F. Hoffmann-La Roche AG", role = c("cph", "fnd")) | ||
|
@@ -14,7 +14,7 @@ BugReports: https://github.com/insightsengineering/cardx/issues | |
Depends: | ||
R (>= 4.1) | ||
Imports: | ||
cards (>= 0.0.0.9044), | ||
cards (>= 0.0.0.9049), | ||
cli (>= 3.6.1), | ||
dplyr (>= 1.1.2), | ||
glue (>= 1.6.2), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# cardx 0.0.0.9038 | ||
# cardx 0.0.0.9043 | ||
|
||
### New Features | ||
* New package! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#' ARD McNemar's Test | ||
#' | ||
#' @description | ||
#' Analysis results data for McNemar's statistical test. | ||
#' | ||
#' @param data (`data.frame`)\cr | ||
#' a data frame. See below for details. | ||
#' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' column name to compare by. | ||
#' @param variable ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' column name to be compared. | ||
#' @param ... arguments passed to `stats::mcnemar.test(...)` | ||
#' | ||
#' @return ARD data frame | ||
#' @name ard_mcnemartest | ||
#' | ||
#' @details | ||
#' For the `ard_mcnemartest()` function, the data is expected to be one row per subject. | ||
#' The data is passed as `stats::mcnemar.test(x = data[[variable]], y = data[[by]], ...)`. | ||
#' Please use `table(x = data[[variable]], y = data[[by]])` to check the contingency table. | ||
#' | ||
#' @examples | ||
#' cards::ADSL |> | ||
#' ard_mcnemartest(by = "SEX", variable = "EFFFL") | ||
#' | ||
NULL | ||
|
||
#' @rdname ard_mcnemartest | ||
#' @export | ||
ard_mcnemartest <- function(data, by, variable, ...) { | ||
# check installed packages --------------------------------------------------- | ||
cards::check_pkg_installed("broom", reference_pkg = "cardx") | ||
|
||
# check/process inputs ------------------------------------------------------- | ||
check_not_missing(data) | ||
check_not_missing(variable) | ||
check_not_missing(by) | ||
check_data_frame(data) | ||
data <- dplyr::ungroup(data) | ||
cards::process_selectors(data, by = {{ by }}, variable = {{ variable }}) | ||
check_scalar(by) | ||
check_scalar(variable) | ||
|
||
# build ARD ------------------------------------------------------------------ | ||
.format_mcnemartest_results( | ||
by = by, | ||
variable = variable, | ||
lst_tidy = | ||
cards::eval_capture_conditions( | ||
stats::mcnemar.test(x = data[[variable]], y = data[[by]], ...) |> | ||
broom::tidy() | ||
), | ||
... | ||
) | ||
} | ||
|
||
#' Convert McNemar's test to ARD | ||
#' | ||
#' @inheritParams cards::tidy_as_ard | ||
#' @inheritParams stats::mcnemar.test | ||
#' @param by (`string`)\cr by column name | ||
#' @param variable (`string`)\cr variable column name | ||
#' @param ... passed to `stats::mcnemar.test(...)` | ||
#' | ||
#' @return ARD data frame | ||
#' | ||
#' @examples | ||
#' cardx:::.format_mcnemartest_results( | ||
#' by = "ARM", | ||
#' variable = "AGE", | ||
#' lst_tidy = | ||
#' cards::eval_capture_conditions( | ||
#' stats::mcnemar.test(cards::ADSL[["SEX"]], cards::ADSL[["EFFFL"]]) |> | ||
#' broom::tidy() | ||
#' ) | ||
#' ) | ||
#' | ||
#' @keywords internal | ||
.format_mcnemartest_results <- function(by, variable, lst_tidy, ...) { | ||
# build ARD ------------------------------------------------------------------ | ||
ret <- | ||
cards::tidy_as_ard( | ||
lst_tidy = lst_tidy, | ||
tidy_result_names = c("statistic", "p.value", "method"), | ||
fun_args_to_record = c("correct"), | ||
formals = formals(asNamespace("stats")[["mcnemar.test"]]), | ||
passed_args = dots_list(...), | ||
lst_ard_columns = list(group1 = by, variable = variable, context = "mcnemartest") | ||
) | ||
|
||
# add the stat label --------------------------------------------------------- | ||
ret |> | ||
dplyr::left_join( | ||
.df_mcnemar_stat_labels(), | ||
by = "stat_name" | ||
) |> | ||
dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> | ||
cards::tidy_ard_column_order() | ||
} | ||
|
||
.df_mcnemar_stat_labels <- function() { | ||
dplyr::tribble( | ||
~stat_name, ~stat_label, | ||
"statistic", "X-squared Statistic", | ||
"parameter", "Degrees of Freedom", | ||
"p.value", "p-value", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#' ARD Mood Test | ||
#' | ||
#' @description | ||
#' Analysis results data for Mood two sample test of scale. Note this not to be confused with | ||
#' the Brown-Mood test of medians. | ||
#' | ||
#' @param data (`data.frame`)\cr | ||
#' a data frame. See below for details. | ||
#' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' column name to compare by. | ||
#' @param variable ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' column name to be compared. | ||
#' @param ... arguments passed to `mood.test(...)` | ||
#' | ||
#' @return ARD data frame | ||
#' @name ard_moodtest | ||
#' | ||
#' @details | ||
#' For the `ard_moodtest()` function, the data is expected to be one row per subject. | ||
#' The data is passed as `mood.test(data[[variable]] ~ data[[by]], ...)`. | ||
#' @rdname ard_moodtest | ||
#' @export | ||
#' | ||
#' @examples | ||
#' cards::ADSL |> | ||
#' ard_moodtest(by = "SEX", variable = "AGE") | ||
ard_moodtest <- function(data, by, variable, ...) { | ||
# check installed packages --------------------------------------------------- | ||
cards::check_pkg_installed("broom", reference_pkg = "cardx") | ||
|
||
# check/process inputs ------------------------------------------------------- | ||
check_not_missing(data) | ||
check_not_missing(variable) | ||
check_not_missing(by) | ||
check_data_frame(data) | ||
data <- dplyr::ungroup(data) | ||
cards::process_selectors(data, by = {{ by }}, variable = {{ variable }}) | ||
check_scalar(by) | ||
check_scalar(variable) | ||
|
||
# build ARD ------------------------------------------------------------------ | ||
.format_moodtest_results( | ||
by = by, | ||
variable = variable, | ||
lst_tidy = | ||
cards::eval_capture_conditions( | ||
stats::mood.test(data[[variable]] ~ data[[by]], ...) |> | ||
broom::tidy() | ||
), | ||
... | ||
) | ||
} | ||
#' Convert mood test results to ARD | ||
#' | ||
#' @inheritParams cards::tidy_as_ard | ||
#' @inheritParams stats::mood.test | ||
#' @param by (`string`)\cr by column name | ||
#' @param variable (`string`)\cr variable column name | ||
#' @param ... passed to `mood.test(...)` | ||
#' | ||
#' @return ARD data frame | ||
#' @keywords internal | ||
#' @examples | ||
#' cardx:::.format_moodtest_results( | ||
#' by = "SEX", | ||
#' variable = "AGE", | ||
#' lst_tidy = | ||
#' cards::eval_capture_conditions( | ||
#' stats::mood.test(ADSL[["AGE"]] ~ ADSL[["SEX"]]) |> | ||
#' broom::tidy() | ||
#' ) | ||
#' ) | ||
.format_moodtest_results <- function(by, variable, lst_tidy, ...) { | ||
# build ARD ------------------------------------------------------------------ | ||
ret <- | ||
cards::tidy_as_ard( | ||
lst_tidy = lst_tidy, | ||
tidy_result_names = c("statistic", "p.value", "method", "alternative"), | ||
formals = formals(asNamespace("stats")[["mood.test.default"]]), | ||
passed_args = c(dots_list(...)), | ||
lst_ard_columns = list(group1 = by, variable = variable, context = "moodtest") | ||
) | ||
|
||
# add the stat label --------------------------------------------------------- | ||
ret |> | ||
dplyr::left_join( | ||
.df_moodtest_stat_labels(), | ||
by = "stat_name" | ||
) |> | ||
dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> | ||
cards::tidy_ard_column_order() | ||
} | ||
|
||
.df_moodtest_stat_labels <- function() { | ||
dplyr::tribble( | ||
~stat_name, ~stat_label, | ||
"statistic", "Z-Statistic", | ||
"p.value", "p-value", | ||
"alternative", "Alternative Hypothesis" | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.