-
-
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 139_survfit_update@main
- Loading branch information
Showing
21 changed files
with
531 additions
and
48 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.1.0.9042 | ||
Version: 0.1.0.9043 | ||
Authors@R: c( | ||
person("Daniel", "Sjoberg", , "[email protected]", role = c("aut", "cre")), | ||
person("Abinaya", "Yogasekaram", , "[email protected]", role = "aut"), | ||
|
@@ -18,7 +18,7 @@ BugReports: https://github.com/insightsengineering/cardx/issues | |
Depends: | ||
R (>= 4.1) | ||
Imports: | ||
cards (>= 0.1.0.9014), | ||
cards (>= 0.1.0.9026), | ||
cli (>= 3.6.1), | ||
dplyr (>= 1.1.2), | ||
glue (>= 1.6.2), | ||
|
@@ -33,13 +33,13 @@ Suggests: | |
effectsize (>= 0.6.0), | ||
emmeans (>= 1.7.3), | ||
geepack (>= 1.3.2), | ||
ggsurvfit (>= 1.0.0), | ||
ggsurvfit (>= 1.1.0), | ||
lme4 (>= 1.1-31), | ||
parameters (>= 0.20.2), | ||
smd (>= 0.6.6), | ||
spelling, | ||
survey (>= 4.1), | ||
survival (>= 3.2-11), | ||
survival (>= 3.6-4), | ||
testthat (>= 3.2.0), | ||
withr (>= 2.5.0) | ||
Remotes: | ||
|
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,37 @@ | ||
#' ARD Attributes | ||
#' | ||
#' @description | ||
#' Add variable attributes to an ARD data frame. | ||
#' - The `label` attribute will be added for all columns, and when no label | ||
#' is specified and no label has been set for a column using the `label=` argument, | ||
#' the column name will be placed in the label statistic. | ||
#' - The `class` attribute will also be returned for all columns. | ||
#' - Any other attribute returned by `attributes()` will also be added, e.g. factor levels. | ||
#' | ||
#' @rdname ard_attributes | ||
#' @param data (`survey.design`)\cr | ||
#' a design object often created with [`survey::svydesign()`]. | ||
#' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' variables to include | ||
#' @param label (named `list`)\cr | ||
#' named list of variable labels, e.g. `list(cyl = "No. Cylinders")`. | ||
#' Default is `NULL` | ||
#' @inheritParams rlang::args_dots_empty | ||
#' | ||
#' @return an ARD data frame of class 'card' | ||
#' @export | ||
#' | ||
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survey", reference_pkg = "cardx")) | ||
#' data(api, package = "survey") | ||
#' dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) | ||
#' | ||
#' ard_attributes( | ||
#' data = dclus1, | ||
#' variables = c(sname, dname), | ||
#' label = list(sname = "School Name", dname = "District Name") | ||
#' ) | ||
ard_attributes.survey.design <- function(data, variables = everything(), label = NULL, ...) { | ||
set_cli_abort_call() | ||
|
||
cards::ard_attributes(data = data[["variables"]], variables = {{ variables }}, label = label, ...) | ||
} |
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,71 @@ | ||
#' ARD one-sample t-test | ||
#' | ||
#' @description | ||
#' Analysis results data for one-sample t-tests. | ||
#' Result may be stratified by including the `by` argument. | ||
#' | ||
#' @param data (`data.frame`)\cr | ||
#' a data frame. See below for details. | ||
#' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' column names to be analyzed. Independent t-tests will be computed for | ||
#' each variable. | ||
#' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' optional column name to stratify results by. | ||
#' @inheritParams ard_stats_t_test | ||
#' | ||
#' @return ARD data frame | ||
#' @export | ||
#' | ||
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) | ||
#' cards::ADSL |> | ||
#' ard_stats_t_test_onesample(by = ARM, variables = AGE) | ||
ard_stats_t_test_onesample <- function(data, variables, by = dplyr::group_vars(data), conf.level = 0.95, ...) { | ||
set_cli_abort_call() | ||
|
||
# check installed packages --------------------------------------------------- | ||
check_pkg_installed("broom", reference_pkg = "cardx") | ||
|
||
# check/process inputs ------------------------------------------------------- | ||
check_not_missing(data) | ||
check_not_missing(variables) | ||
check_data_frame(data) | ||
data <- dplyr::ungroup(data) | ||
cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) | ||
check_scalar_range(conf.level, range = c(0, 1)) | ||
|
||
# if no variables selected, return empty tibble ------------------------------ | ||
if (is_empty(variables)) { | ||
return(dplyr::tibble()) | ||
} | ||
|
||
cards::ard_continuous( | ||
data = data, | ||
variables = all_of(variables), | ||
by = all_of(by), | ||
statistic = all_of(variables) ~ list(t_test_onesample = \(x) stats::t.test(x = x, conf.level = conf.level, ...) |> broom::tidy()) | ||
) |> | ||
cards::bind_ard( | ||
cards::ard_continuous( | ||
data = data, | ||
variables = all_of(variables), | ||
by = all_of(by), | ||
statistic = | ||
all_of(variables) ~ | ||
list(conf.level = \(x) { | ||
formals(asNamespace("stats")[["t.test.default"]])["mu"] |> | ||
utils::modifyList(list(conf.level = conf.level, ...)) | ||
}) | ||
) | ||
) |> | ||
dplyr::select(-"stat_label") |> | ||
dplyr::left_join( | ||
.df_ttest_stat_labels(by = NULL), | ||
by = "stat_name" | ||
) |> | ||
dplyr::mutate( | ||
stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name), | ||
context = "ard_stats_t_test_onesample", | ||
) |> | ||
cards::tidy_ard_row_order() |> | ||
cards::tidy_ard_column_order() | ||
} |
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,72 @@ | ||
#' ARD one-sample Wilcox Rank-sum | ||
#' | ||
#' @description | ||
#' Analysis results data for one-sample Wilcox Rank-sum. | ||
#' Result may be stratified by including the `by` argument. | ||
#' | ||
#' @param data (`data.frame`)\cr | ||
#' a data frame. See below for details. | ||
#' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' column names to be analyzed. Independent Wilcox Rank-sum tests will be computed for | ||
#' each variable. | ||
#' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr | ||
#' optional column name to stratify results by. | ||
#' @inheritParams ard_stats_wilcox_test | ||
#' | ||
#' @return ARD data frame | ||
#' @export | ||
#' | ||
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) | ||
#' cards::ADSL |> | ||
#' ard_stats_wilcox_test_onesample(by = ARM, variables = AGE) | ||
ard_stats_wilcox_test_onesample <- function(data, variables, by = dplyr::group_vars(data), conf.level = 0.95, ...) { | ||
set_cli_abort_call() | ||
|
||
# check installed packages --------------------------------------------------- | ||
check_pkg_installed("broom", reference_pkg = "cardx") | ||
|
||
# check/process inputs ------------------------------------------------------- | ||
check_not_missing(data) | ||
check_not_missing(variables) | ||
check_data_frame(data) | ||
data <- dplyr::ungroup(data) | ||
cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) | ||
check_scalar_range(conf.level, range = c(0, 1)) | ||
|
||
# if no variables selected, return empty tibble ------------------------------ | ||
if (is_empty(variables)) { | ||
return(dplyr::tibble()) | ||
} | ||
|
||
cards::ard_continuous( | ||
data = data, | ||
variables = all_of(variables), | ||
by = all_of(by), | ||
statistic = all_of(variables) ~ list(t_test_onesample = \(x) stats::wilcox.test(x = x, conf.level = conf.level, ...) |> broom::tidy()) | ||
) |> | ||
cards::bind_ard( | ||
cards::ard_continuous( | ||
data = data, | ||
variables = all_of(variables), | ||
by = all_of(by), | ||
statistic = | ||
all_of(variables) ~ | ||
list(conf.level = \(x) { | ||
formals(asNamespace("stats")[["wilcox.test.default"]])[c("mu", "exact", "conf.int", "tol.root", "digits.rank")] |> | ||
utils::modifyList(list(conf.level = conf.level, ...)) |> | ||
compact() | ||
}) | ||
) | ||
) |> | ||
dplyr::select(-"stat_label") |> | ||
dplyr::left_join( | ||
.df_ttest_stat_labels(by = NULL), | ||
by = "stat_name" | ||
) |> | ||
dplyr::mutate( | ||
stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name), | ||
context = "ard_stats_wilcox_test_onesample", | ||
) |> | ||
cards::tidy_ard_row_order() |> | ||
cards::tidy_ard_column_order() | ||
} |
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
Oops, something went wrong.