From 60f0c0d22c1d79a4e03dc37f05a43323ff976fe3 Mon Sep 17 00:00:00 2001 From: Abinaya Yogasekaram <73252787+ayogasekaram@users.noreply.github.com> Date: Fri, 12 Apr 2024 00:06:55 -0400 Subject: [PATCH 01/14] rename functions with new package conventions. (#110) **What changes are proposed in this pull request?** Functions are renamed according to new conventions: `ard__()` if a package specific function is used If a `.` appears in a function name it will be replaced with a `_` in the ard_*() function name. closes #106 @ayogasekaram -------------------------------------------------------------------------------- Pre-review Checklist (if item does not apply, mark is as complete) - [x] **All** GitHub Action workflows pass with a :white_check_mark: - [x] PR branch has pulled the most recent updates from master branch: `usethis::pr_merge_main()` - [x] If a bug was fixed, a unit test was added. - [x] If a new `ard_*()` function was added, it passes the ARD structural checks from `cards::check_ard_structure()`. - [x] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()` - [x] Request a reviewer Reviewer Checklist (if item does not apply, mark is as complete) - [x] If a bug was fixed, a unit test was added. - [x] Run `pkgdown::build_site()`. Check the R console for errors, and review the rendered website. - [x] Code coverage is suitable for any new functions/features: `devtools::test_coverage()` When the branch is ready to be merged: - [x] Update `NEWS.md` with the changes from this pull request under the heading "`# cards (development version)`". If there is an issue associated with the pull request, reference it in parentheses at the end update (see `NEWS.md` for examples). - [ ] **All** GitHub Action workflows pass with a :white_check_mark: - [ ] Approve Pull Request - [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge". --------- Co-authored-by: Daniel Sjoberg --- .github/PULL_REQUEST_TEMPLATE.md | 4 +- NAMESPACE | 46 ++++++------ NEWS.md | 22 +++++- R/{ard_vif.R => ard_car_vif.R} | 8 +- ...d_cohens_d.R => ard_effectsize_cohens_d.R} | 18 ++--- ...d_hedges_g.R => ard_effectsize_hedges_g.R} | 18 ++--- R/{ard_smd.R => ard_smd_smd.R} | 6 +- R/{ard_aov.R => ard_stats_aov.R} | 4 +- R/{ard_chisqtest.R => ard_stats_chisq_test.R} | 4 +- ...d_fishertest.R => ard_stats_fisher_test.R} | 4 +- ...kruskaltest.R => ard_stats_kruskal_test.R} | 4 +- ...mcnemartest.R => ard_stats_mcnemar_test.R} | 6 +- R/{ard_moodtest.R => ard_stats_mood_test.R} | 10 +-- ...d_onewaytest.R => ard_stats_oneway_test.R} | 4 +- R/{ard_proptest.R => ard_stats_prop_test.R} | 4 +- R/{ard_ttest.R => ard_stats_t_test.R} | 18 ++--- ...d_wilcoxtest.R => ard_stats_wilcox_test.R} | 20 ++--- R/{ard_svychisq.R => ard_survey_svychisq.R} | 4 +- ...ontinuous.R => ard_survey_svycontinuous.R} | 12 +-- ...svyranktest.R => ard_survey_svyranktest.R} | 10 +-- R/{ard_svyttest.R => ard_survey_svyttest.R} | 4 +- R/{ard_survfit.R => ard_survival_survfit.R} | 16 ++-- _pkgdown.yml | 46 ++++++------ man/{ard_vif.Rd => ard_car_vif.Rd} | 10 +-- ...cohens_d.Rd => ard_effectsize_cohens_d.Rd} | 20 ++--- ...hedges_g.Rd => ard_effectsize_hedges_g.Rd} | 20 ++--- man/{ard_smd.Rd => ard_smd_smd.Rd} | 12 +-- man/{ard_aov.Rd => ard_stats_aov.Rd} | 10 +-- ...d_chisqtest.Rd => ard_stats_chisq_test.Rd} | 10 +-- ...fishertest.Rd => ard_stats_fisher_test.Rd} | 10 +-- ...uskaltest.Rd => ard_stats_kruskal_test.Rd} | 10 +-- ...nemartest.Rd => ard_stats_mcnemar_test.Rd} | 12 +-- ...ard_moodtest.Rd => ard_stats_mood_test.Rd} | 12 +-- ...onewaytest.Rd => ard_stats_oneway_test.Rd} | 10 +-- ...ard_proptest.Rd => ard_stats_prop_test.Rd} | 10 +-- man/{ard_ttest.Rd => ard_stats_t_test.Rd} | 20 ++--- ...wilcoxtest.Rd => ard_stats_wilcox_test.Rd} | 20 ++--- ...ard_svychisq.Rd => ard_survey_svychisq.Rd} | 10 +-- ...tinuous.Rd => ard_survey_svycontinuous.Rd} | 10 +-- ...yranktest.Rd => ard_survey_svyranktest.Rd} | 16 ++-- ...ard_svyttest.Rd => ard_survey_svyttest.Rd} | 10 +-- ...ard_survfit.Rd => ard_survival_survfit.Rd} | 14 ++-- man/dot-format_cohens_d_results.Rd | 2 +- man/dot-format_hedges_g_results.Rd | 2 +- man/dot-format_mcnemartest_results.Rd | 2 +- man/dot-format_moodtest_results.Rd | 2 +- man/dot-format_proptest_results.Rd | 2 +- man/dot-format_survfit_results.Rd | 2 +- man/dot-format_ttest_results.Rd | 2 +- man/dot-format_wilcoxtest_results.Rd | 4 +- man/dot-paired_data_pivot_wider.Rd | 2 +- man/dot-process_survfit_probs.Rd | 2 +- man/dot-process_survfit_time.Rd | 2 +- tests/testthat/_snaps/ard_chisqtest.md | 17 ----- ...cohens_d.md => ard_effectsize_cohens_d.md} | 21 +++--- ...hedges_g.md => ard_effectsize_hedges_g.md} | 21 +++--- .../_snaps/{ard_aov.md => ard_stats_aov.md} | 2 +- ...uskaltest.md => ard_stats_kruskal_test.md} | 4 +- tests/testthat/_snaps/ard_stats_t_test.md | 75 +++++++++++++++++++ .../_snaps/ard_survey_svycontinuous.md | 55 ++++++++++++++ .../{test-ard_vif.R => test-ard_car_vif.R} | 12 +-- ...ens_d.R => test-ard_effectsize_cohens_d.R} | 18 ++--- ...ges_g.R => test-ard_effectsize_hedges_g.R} | 14 ++-- .../{test-ard_smd.R => test-ard_smd_smd.R} | 12 +-- .../{test-ard_aov.R => test-ard_stats_aov.R} | 4 +- ...hisqtest.R => test-ard_stats_chisq_test.R} | 12 +-- ...hertest.R => test-ard_stats_fisher_test.R} | 8 +- ...altest.R => test-ard_stats_kruskal_test.R} | 10 +-- ...artest.R => test-ard_stats_mcnemar_test.R} | 14 ++-- ..._moodtest.R => test-ard_stats_mood_test.R} | 10 +-- ...waytest.R => test-ard_stats_oneway_test.R} | 6 +- ..._proptest.R => test-ard_stats_prop_test.R} | 14 ++-- ...st-ard_ttest.R => test-ard_stats_t_test.R} | 18 ++--- ...coxtest.R => test-ard_stats_wilcox_test.R} | 18 ++--- ..._svychisq.R => test-ard_survey_svychisq.R} | 10 +-- ...uous.R => test-ard_survey_svycontinuous.R} | 34 ++++----- ...nktest.R => test-ard_survey_svyranktest.R} | 6 +- ..._svyttest.R => test-ard_survey_svyttest.R} | 12 +-- ..._survfit.R => test-ard_survival_survfit.R} | 46 ++++++------ 79 files changed, 583 insertions(+), 452 deletions(-) rename R/{ard_vif.R => ard_car_vif.R} (96%) rename R/{ard_cohens_d.R => ard_effectsize_cohens_d.R} (91%) rename R/{ard_hedges_g.R => ard_effectsize_hedges_g.R} (91%) rename R/{ard_smd.R => ard_smd_smd.R} (94%) rename R/{ard_aov.R => ard_stats_aov.R} (95%) rename R/{ard_chisqtest.R => ard_stats_chisq_test.R} (95%) rename R/{ard_fishertest.R => ard_stats_fisher_test.R} (95%) rename R/{ard_kruskaltest.R => ard_stats_kruskal_test.R} (94%) rename R/{ard_mcnemartest.R => ard_stats_mcnemar_test.R} (94%) rename R/{ard_moodtest.R => ard_stats_mood_test.R} (92%) rename R/{ard_onewaytest.R => ard_stats_oneway_test.R} (93%) rename R/{ard_proptest.R => ard_stats_prop_test.R} (97%) rename R/{ard_ttest.R => ard_stats_t_test.R} (93%) rename R/{ard_wilcoxtest.R => ard_stats_wilcox_test.R} (92%) rename R/{ard_svychisq.R => ard_survey_svychisq.R} (94%) rename R/{ard_svycontinuous.R => ard_survey_svycontinuous.R} (96%) rename R/{ard_svyranktest.R => ard_survey_svyranktest.R} (87%) rename R/{ard_svyttest.R => ard_survey_svyttest.R} (95%) rename R/{ard_survfit.R => ard_survival_survfit.R} (96%) rename man/{ard_vif.Rd => ard_car_vif.Rd} (79%) rename man/{ard_cohens_d.Rd => ard_effectsize_cohens_d.Rd} (76%) rename man/{ard_hedges_g.Rd => ard_effectsize_hedges_g.Rd} (76%) rename man/{ard_smd.Rd => ard_smd_smd.Rd} (82%) rename man/{ard_aov.Rd => ard_stats_aov.Rd} (79%) rename man/{ard_chisqtest.Rd => ard_stats_chisq_test.Rd} (79%) rename man/{ard_fishertest.Rd => ard_stats_fisher_test.Rd} (79%) rename man/{ard_kruskaltest.Rd => ard_stats_kruskal_test.Rd} (77%) rename man/{ard_mcnemartest.Rd => ard_stats_mcnemar_test.Rd} (75%) rename man/{ard_moodtest.Rd => ard_stats_mood_test.Rd} (75%) rename man/{ard_onewaytest.Rd => ard_stats_oneway_test.Rd} (80%) rename man/{ard_proptest.Rd => ard_stats_prop_test.Rd} (81%) rename man/{ard_ttest.Rd => ard_stats_t_test.Rd} (74%) rename man/{ard_wilcoxtest.Rd => ard_stats_wilcox_test.Rd} (73%) rename man/{ard_svychisq.Rd => ard_survey_svychisq.Rd} (83%) rename man/{ard_svycontinuous.Rd => ard_survey_svycontinuous.Rd} (92%) rename man/{ard_svyranktest.Rd => ard_survey_svyranktest.Rd} (69%) rename man/{ard_svyttest.Rd => ard_survey_svyttest.Rd} (81%) rename man/{ard_survfit.Rd => ard_survival_survfit.Rd} (86%) delete mode 100644 tests/testthat/_snaps/ard_chisqtest.md rename tests/testthat/_snaps/{ard_cohens_d.md => ard_effectsize_cohens_d.md} (75%) rename tests/testthat/_snaps/{ard_hedges_g.md => ard_effectsize_hedges_g.md} (75%) rename tests/testthat/_snaps/{ard_aov.md => ard_stats_aov.md} (92%) rename tests/testthat/_snaps/{ard_kruskaltest.md => ard_stats_kruskal_test.md} (85%) create mode 100644 tests/testthat/_snaps/ard_stats_t_test.md create mode 100644 tests/testthat/_snaps/ard_survey_svycontinuous.md rename tests/testthat/{test-ard_vif.R => test-ard_car_vif.R} (74%) rename tests/testthat/{test-ard_cohens_d.R => test-ard_effectsize_cohens_d.R} (81%) rename tests/testthat/{test-ard_hedges_g.R => test-ard_effectsize_hedges_g.R} (84%) rename tests/testthat/{test-ard_smd.R => test-ard_smd_smd.R} (80%) rename tests/testthat/{test-ard_aov.R => test-ard_stats_aov.R} (83%) rename tests/testthat/{test-ard_chisqtest.R => test-ard_stats_chisq_test.R} (77%) rename tests/testthat/{test-ard_fishertest.R => test-ard_stats_fisher_test.R} (71%) rename tests/testthat/{test-ard_kruskaltest.R => test-ard_stats_kruskal_test.R} (70%) rename tests/testthat/{test-ard_mcnemartest.R => test-ard_stats_mcnemar_test.R} (70%) rename tests/testthat/{test-ard_moodtest.R => test-ard_stats_mood_test.R} (69%) rename tests/testthat/{test-ard_onewaytest.R => test-ard_stats_oneway_test.R} (78%) rename tests/testthat/{test-ard_proptest.R => test-ard_stats_prop_test.R} (83%) rename tests/testthat/{test-ard_ttest.R => test-ard_stats_t_test.R} (80%) rename tests/testthat/{test-ard_wilcoxtest.R => test-ard_stats_wilcox_test.R} (83%) rename tests/testthat/{test-ard_svychisq.R => test-ard_survey_svychisq.R} (81%) rename tests/testthat/{test-ard_svycontinuous.R => test-ard_survey_svycontinuous.R} (93%) rename tests/testthat/{test-ard_svyranktest.R => test-ard_survey_svyranktest.R} (91%) rename tests/testthat/{test-ard_svyttest.R => test-ard_survey_svyttest.R} (88%) rename tests/testthat/{test-ard_survfit.R => test-ard_survival_survfit.R} (71%) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d5682bc9e..9845c478e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -14,16 +14,14 @@ Pre-review Checklist (if item does not apply, mark is as complete) - [ ] If a bug was fixed, a unit test was added. - [ ] If a new `ard_*()` function was added, it passes the ARD structural checks from `cards::check_ard_structure()`. - [ ] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()` -- [ ] Request a reviewer Reviewer Checklist (if item does not apply, mark is as complete) - [ ] If a bug was fixed, a unit test was added. -- [ ] Run `pkgdown::build_site()`. Check the R console for errors, and review the rendered website. - [ ] Code coverage is suitable for any new functions/features: `devtools::test_coverage()` When the branch is ready to be merged: -- [ ] Update `NEWS.md` with the changes from this pull request under the heading "`# cards (development version)`". If there is an issue associated with the pull request, reference it in parentheses at the end update (see `NEWS.md` for examples). +- [ ] Update `NEWS.md` with the changes from this pull request under the heading "`# cardx (development version)`". If there is an issue associated with the pull request, reference it in parentheses at the end update (see `NEWS.md` for examples). - [ ] **All** GitHub Action workflows pass with a :white_check_mark: - [ ] Approve Pull Request - [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge". diff --git a/NAMESPACE b/NAMESPACE index 59d7cd0d2..401c17a57 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,33 +4,33 @@ S3method(ard_regression,default) export("%>%") export(all_of) export(any_of) -export(ard_aov) export(ard_car_anova) -export(ard_chisqtest) -export(ard_cohens_d) -export(ard_fishertest) -export(ard_hedges_g) -export(ard_kruskaltest) -export(ard_mcnemartest) -export(ard_moodtest) -export(ard_onewaytest) -export(ard_paired_cohens_d) -export(ard_paired_hedges_g) -export(ard_paired_ttest) -export(ard_paired_wilcoxtest) +export(ard_car_vif) +export(ard_effectsize_cohens_d) +export(ard_effectsize_hedges_g) +export(ard_effectsize_paired_cohens_d) +export(ard_effectsize_paired_hedges_g) export(ard_proportion_ci) -export(ard_proptest) export(ard_regression) export(ard_regression_basic) -export(ard_smd) -export(ard_survfit) -export(ard_svychisq) -export(ard_svycontinuous) -export(ard_svyranktest) -export(ard_svyttest) -export(ard_ttest) -export(ard_vif) -export(ard_wilcoxtest) +export(ard_smd_smd) +export(ard_stats_aov) +export(ard_stats_chisq_test) +export(ard_stats_fisher_test) +export(ard_stats_kruskal_test) +export(ard_stats_mcnemar_test) +export(ard_stats_mood_test) +export(ard_stats_oneway_test) +export(ard_stats_paired_t_test) +export(ard_stats_paired_wilcox_test) +export(ard_stats_prop_test) +export(ard_stats_t_test) +export(ard_stats_wilcox_test) +export(ard_survey_svychisq) +export(ard_survey_svycontinuous) +export(ard_survey_svyranktest) +export(ard_survey_svyttest) +export(ard_survival_survfit) export(contains) export(ends_with) export(everything) diff --git a/NEWS.md b/NEWS.md index 022b7da94..e4ddc6445 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,23 @@ # cardx 0.1.0.9011 +### Breaking Changes + +* Updated function names have been updated to follow the pattern `ard__()`. Former functions names have _not_ been deprecated. (#106) + +```r +ard_ttest() -> ard_stats_t_test() +ard_paired_ttest() -> ard_stats_paired_t_test() +ard_wilcoxtest() -> ard_stats_wilcox_test() +ard_paired_wilcoxtest() -> ard_stats_paired_wilcox_test() +ard_chisqtest() -> ard_stats_chisq_test() +ard_fishertest() -> ard_stats_fisher_test() +ard_kruskaltest() -> ard_stats_kruskal_test() +ard_mcnemartest() -> ard_stats_mcnemar_test() +ard_moodtest() -> ard_stats_mood_test() +``` + +### New Features + * Added the following functions for calculating Analysis Results Data (ARD). - `ard_aov()` for calculating ANOVA results using `stats::aov()`. (#3) - `ard_car_anova()` for calculating ANOVA results using `car::Anova()`. (#3) @@ -15,9 +33,9 @@ - `ard_svyranktest()` for weighted/survey rank tests using `survey::svyranktest()`. (#71) - `ard_vif()` for calculating the variance inflation factor using `car::vif()`. (#10) -* Updated functions `ard_ttest()`, `ard_paired_ttest()`, `ard_wilcoxtest()`, `ard_paired_wilcoxtest()`, `ard_chisqtest()`, `ard_fishertest()`, `ard_kruskaltest()`, `ard_mcnemartest()`, and `ard_moodtest()` to accept multiple variables at once. Independent tests are calculated for each variable. The `variable` argument is renamed to `variables`. (#77) +* Updated functions `ard_stats_t_test()`, `ard_stats_paired_t_test()`, `ard_stats_wilcox_test()`, `ard_stats_paired_wilcox_test()`, `ard_stats_chisq_test()`, `ard_stats_fisher_test()`, `ard_stats_kruskal_test()`, `ard_stats_mcnemar_test()`, and `ard_stats_mood_test()` to accept multiple variables at once. Independent tests are calculated for each variable. The `variable` argument is renamed to `variables`. (#77) -* Updated `ard_ttest()` and `ard_wilcoxtest()` to no longer require the `by` argument, which yields central estimates with their confidence intervals. (#82) +* Updated `ard_stats_t_test()` and `ard_stats_wilcox_test()` to no longer require the `by` argument, which yields central estimates with their confidence intervals. (#82) # cardx 0.1.0 diff --git a/R/ard_vif.R b/R/ard_car_vif.R similarity index 96% rename from R/ard_vif.R rename to R/ard_car_vif.R index d44a20e99..66212247e 100644 --- a/R/ard_vif.R +++ b/R/ard_car_vif.R @@ -10,14 +10,14 @@ #' @param ... arguments passed to `car::vif(...)` #' #' @return data frame -#' @name ard_vif -#' @rdname ard_vif +#' @name ard_car_vif +#' @rdname ard_car_vif #' @export #' #' @examples #' lm(AGE ~ ARM + SEX, data = cards::ADSL) |> -#' ard_vif() -ard_vif <- function(x, ...) { +#' ard_car_vif() +ard_car_vif <- function(x, ...) { # check inputs --------------------------------------------------------------- check_not_missing(x) diff --git a/R/ard_cohens_d.R b/R/ard_effectsize_cohens_d.R similarity index 91% rename from R/ard_cohens_d.R rename to R/ard_effectsize_cohens_d.R index b1b70221b..ba6b45fd8 100644 --- a/R/ard_cohens_d.R +++ b/R/ard_effectsize_cohens_d.R @@ -16,13 +16,13 @@ #' @param ... arguments passed to `effectsize::cohens_d(...)` #' #' @return ARD data frame -#' @name ard_cohens_d +#' @name ard_effectsize_cohens_d #' #' @details -#' For the `ard_cohens_d()` function, the data is expected to be one row per subject. +#' For the `ard_effectsize_cohens_d()` function, the data is expected to be one row per subject. #' The data is passed as `effectsize::cohens_d(data[[variable]]~data[[by]], data, paired = FALSE, ...)`. #' -#' For the `ard_paired_cohens_d()` function, the data is expected to be one row +#' For the `ard_effectsize_paired_cohens_d()` function, the data is expected to be one row #' per subject per by level. Before the effect size is calculated, the data are #' reshaped to a wide format to be one row per subject. #' The data are then passed as @@ -31,7 +31,7 @@ #' @examplesIf cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> -#' ard_cohens_d(by = ARM, variables = AGE) +#' ard_effectsize_cohens_d(by = ARM, variables = AGE) #' #' # constructing a paired data set, #' # where patients receive both treatments @@ -41,12 +41,12 @@ #' dplyr::arrange(USUBJID, ARM) |> #' dplyr::group_by(USUBJID) |> #' dplyr::filter(dplyr::n() > 1) |> -#' ard_paired_cohens_d(by = ARM, variables = AGE, id = USUBJID) +#' ard_effectsize_paired_cohens_d(by = ARM, variables = AGE, id = USUBJID) NULL -#' @rdname ard_cohens_d +#' @rdname ard_effectsize_cohens_d #' @export -ard_cohens_d <- function(data, by, variables, ...) { +ard_effectsize_cohens_d <- function(data, by, variables, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") @@ -85,9 +85,9 @@ ard_cohens_d <- function(data, by, variables, ...) { } -#' @rdname ard_cohens_d +#' @rdname ard_effectsize_cohens_d #' @export -ard_paired_cohens_d <- function(data, by, variables, id, ...) { +ard_effectsize_paired_cohens_d <- function(data, by, variables, id, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("effectsize", reference_pkg = "cardx") cards::check_pkg_installed("parameters", reference_pkg = "cardx") diff --git a/R/ard_hedges_g.R b/R/ard_effectsize_hedges_g.R similarity index 91% rename from R/ard_hedges_g.R rename to R/ard_effectsize_hedges_g.R index 33e0e719e..4a4cd1bc0 100644 --- a/R/ard_hedges_g.R +++ b/R/ard_effectsize_hedges_g.R @@ -16,13 +16,13 @@ #' @param ... arguments passed to `effectsize::hedges_g(...)` #' #' @return ARD data frame -#' @name ard_hedges_g +#' @name ard_effectsize_hedges_g #' #' @details -#' For the `ard_hedges_g()` function, the data is expected to be one row per subject. +#' For the `ard_effectsize_hedges_g()` function, the data is expected to be one row per subject. #' The data is passed as `effectsize::hedges_g(data[[variable]]~data[[by]], data, paired = FALSE, ...)`. #' -#' For the `ard_paired_hedges_g()` function, the data is expected to be one row +#' For the `ard_effectsize_paired_hedges_g()` function, the data is expected to be one row #' per subject per by level. Before the effect size is calculated, the data are #' reshaped to a wide format to be one row per subject. #' The data are then passed as @@ -31,7 +31,7 @@ #' @examplesIf cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx") #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> -#' ard_hedges_g(by = ARM, variables = AGE) +#' ard_effectsize_hedges_g(by = ARM, variables = AGE) #' #' # constructing a paired data set, #' # where patients receive both treatments @@ -41,12 +41,12 @@ #' dplyr::arrange(USUBJID, ARM) |> #' dplyr::group_by(USUBJID) |> #' dplyr::filter(dplyr::n() > 1) |> -#' ard_paired_hedges_g(by = ARM, variables = AGE, id = USUBJID) +#' ard_effectsize_paired_hedges_g(by = ARM, variables = AGE, id = USUBJID) NULL -#' @rdname ard_hedges_g +#' @rdname ard_effectsize_hedges_g #' @export -ard_hedges_g <- function(data, by, variables, ...) { +ard_effectsize_hedges_g <- function(data, by, variables, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx") @@ -89,9 +89,9 @@ ard_hedges_g <- function(data, by, variables, ...) { dplyr::bind_rows() } -#' @rdname ard_hedges_g +#' @rdname ard_effectsize_hedges_g #' @export -ard_paired_hedges_g <- function(data, by, variables, id, ...) { +ard_effectsize_paired_hedges_g <- function(data, by, variables, id, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("effectsize", reference_pkg = "cardx") cards::check_pkg_installed("parameters", reference_pkg = "cardx") diff --git a/R/ard_smd.R b/R/ard_smd_smd.R similarity index 94% rename from R/ard_smd.R rename to R/ard_smd_smd.R index 40050339e..cb6c4ec8c 100644 --- a/R/ard_smd.R +++ b/R/ard_smd_smd.R @@ -17,9 +17,9 @@ #' @export #' #' @examplesIf cards::is_pkg_installed("smd", reference_pkg = "cardx") -#' ard_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE) -#' ard_smd(cards::ADSL, by = ARM, variables = AGEGR1, std.error = TRUE) -ard_smd <- function(data, by, variables, ...) { +#' ard_smd_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE) +#' ard_smd_smd(cards::ADSL, by = ARM, variables = AGEGR1, std.error = TRUE) +ard_smd_smd <- function(data, by, variables, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("smd", reference_pkg = "cardx") diff --git a/R/ard_aov.R b/R/ard_stats_aov.R similarity index 95% rename from R/ard_aov.R rename to R/ard_stats_aov.R index ee519ba00..3abdd4759 100644 --- a/R/ard_aov.R +++ b/R/ard_stats_aov.R @@ -11,8 +11,8 @@ #' @export #' #' @examplesIf cards::is_pkg_installed(c("broom.helpers"), reference_pkg = "cardx") -#' ard_aov(AGE ~ ARM, data = cards::ADSL) -ard_aov <- function(formula, data, ...) { +#' ard_stats_aov(AGE ~ ARM, data = cards::ADSL) +ard_stats_aov <- function(formula, data, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed(c("broom.helpers"), reference_pkg = "cardx") diff --git a/R/ard_chisqtest.R b/R/ard_stats_chisq_test.R similarity index 95% rename from R/ard_chisqtest.R rename to R/ard_stats_chisq_test.R index 5dd139f17..9f76c3118 100644 --- a/R/ard_chisqtest.R +++ b/R/ard_stats_chisq_test.R @@ -19,8 +19,8 @@ #' #' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") #' cards::ADSL |> -#' ard_chisqtest(by = "ARM", variables = "AGEGR1") -ard_chisqtest <- function(data, by, variables, ...) { +#' ard_stats_chisq_test(by = "ARM", variables = "AGEGR1") +ard_stats_chisq_test <- function(data, by, variables, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") diff --git a/R/ard_fishertest.R b/R/ard_stats_fisher_test.R similarity index 95% rename from R/ard_fishertest.R rename to R/ard_stats_fisher_test.R index c7f25f0f4..a48773c37 100644 --- a/R/ard_fishertest.R +++ b/R/ard_stats_fisher_test.R @@ -19,8 +19,8 @@ #' #' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") #' cards::ADSL[1:30, ] |> -#' ard_fishertest(by = "ARM", variables = "AGEGR1") -ard_fishertest <- function(data, by, variables, ...) { +#' ard_stats_fisher_test(by = "ARM", variables = "AGEGR1") +ard_stats_fisher_test <- function(data, by, variables, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") diff --git a/R/ard_kruskaltest.R b/R/ard_stats_kruskal_test.R similarity index 94% rename from R/ard_kruskaltest.R rename to R/ard_stats_kruskal_test.R index 5021b6910..876d5af00 100644 --- a/R/ard_kruskaltest.R +++ b/R/ard_stats_kruskal_test.R @@ -18,8 +18,8 @@ #' #' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") #' cards::ADSL |> -#' ard_kruskaltest(by = "ARM", variables = "AGE") -ard_kruskaltest <- function(data, by, variables) { +#' ard_stats_kruskal_test(by = "ARM", variables = "AGE") +ard_stats_kruskal_test <- function(data, by, variables) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") diff --git a/R/ard_mcnemartest.R b/R/ard_stats_mcnemar_test.R similarity index 94% rename from R/ard_mcnemartest.R rename to R/ard_stats_mcnemar_test.R index b4735def9..da932885c 100644 --- a/R/ard_mcnemartest.R +++ b/R/ard_stats_mcnemar_test.R @@ -16,14 +16,14 @@ #' @export #' #' @details -#' For the `ard_mcnemartest()` function, the data is expected to be one row per subject. +#' For the `ard_stats_mcnemar_test()` 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. #' #' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") #' cards::ADSL |> -#' ard_mcnemartest(by = "SEX", variables = "EFFFL") -ard_mcnemartest <- function(data, by, variables, ...) { +#' ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") +ard_stats_mcnemar_test <- function(data, by, variables, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") diff --git a/R/ard_moodtest.R b/R/ard_stats_mood_test.R similarity index 92% rename from R/ard_moodtest.R rename to R/ard_stats_mood_test.R index dddb82128..ad0bb5c8a 100644 --- a/R/ard_moodtest.R +++ b/R/ard_stats_mood_test.R @@ -14,18 +14,18 @@ #' @param ... arguments passed to `mood.test(...)` #' #' @return ARD data frame -#' @name ard_moodtest +#' @name ard_stats_mood_test #' #' @details -#' For the `ard_moodtest()` function, the data is expected to be one row per subject. +#' For the `ard_stats_mood_test()` 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 +#' @rdname ard_stats_mood_test #' @export #' #' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") #' cards::ADSL |> -#' ard_moodtest(by = "SEX", variables = "AGE") -ard_moodtest <- function(data, by, variables, ...) { +#' ard_stats_mood_test(by = "SEX", variables = "AGE") +ard_stats_mood_test <- function(data, by, variables, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") diff --git a/R/ard_onewaytest.R b/R/ard_stats_oneway_test.R similarity index 93% rename from R/ard_onewaytest.R rename to R/ard_stats_oneway_test.R index 7f127fb5b..f2182b4ab 100644 --- a/R/ard_onewaytest.R +++ b/R/ard_stats_oneway_test.R @@ -11,8 +11,8 @@ #' @export #' #' @examplesIf cards::is_pkg_installed(c("broom"), reference_pkg = "cardx") -#' ard_onewaytest(AGE ~ ARM, data = cards::ADSL) -ard_onewaytest <- function(formula, data, ...) { +#' ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) +ard_stats_oneway_test <- function(formula, data, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed(c("broom"), reference_pkg = "cardx") diff --git a/R/ard_proptest.R b/R/ard_stats_prop_test.R similarity index 97% rename from R/ard_proptest.R rename to R/ard_stats_prop_test.R index 72336982b..6ef4a8b4d 100644 --- a/R/ard_proptest.R +++ b/R/ard_stats_prop_test.R @@ -17,8 +17,8 @@ #' #' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") #' mtcars |> -#' ard_proptest(by = vs, variables = am) -ard_proptest <- function(data, by, variables, ...) { +#' ard_stats_prop_test(by = vs, variables = am) +ard_stats_prop_test <- function(data, by, variables, ...) { cards::check_pkg_installed("broom", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_ttest.R b/R/ard_stats_t_test.R similarity index 93% rename from R/ard_ttest.R rename to R/ard_stats_t_test.R index 0b2b7a940..2e1f9214e 100644 --- a/R/ard_ttest.R +++ b/R/ard_stats_t_test.R @@ -15,13 +15,13 @@ #' @param ... arguments passed to `t.test(...)` #' #' @return ARD data frame -#' @name ard_ttest +#' @name ard_stats_t_test #' #' @details -#' For the `ard_ttest()` function, the data is expected to be one row per subject. +#' For the `ard_stats_t_test()` function, the data is expected to be one row per subject. #' The data is passed as `t.test(data[[variable]] ~ data[[by]], paired = FALSE, ...)`. #' -#' For the `ard_paired_ttest()` function, the data is expected to be one row +#' For the `ard_stats_paired_t_test()` function, the data is expected to be one row #' per subject per by level. Before the t-test is calculated, the data are #' reshaped to a wide format to be one row per subject. #' The data are then passed as @@ -30,7 +30,7 @@ #' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> -#' ard_ttest(by = ARM, variables = c(AGE, BMIBL)) +#' ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) #' #' # constructing a paired data set, #' # where patients receive both treatments @@ -38,12 +38,12 @@ #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> #' dplyr::arrange(USUBJID, ARM) |> -#' ard_paired_ttest(by = ARM, variables = AGE, id = USUBJID) +#' ard_stats_paired_t_test(by = ARM, variables = AGE, id = USUBJID) NULL -#' @rdname ard_ttest +#' @rdname ard_stats_t_test #' @export -ard_ttest <- function(data, variables, by = NULL, ...) { +ard_stats_t_test <- function(data, variables, by = NULL, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") @@ -82,9 +82,9 @@ ard_ttest <- function(data, variables, by = NULL, ...) { dplyr::bind_rows() } -#' @rdname ard_ttest +#' @rdname ard_stats_t_test #' @export -ard_paired_ttest <- function(data, by, variables, id, ...) { +ard_stats_paired_t_test <- function(data, by, variables, id, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") diff --git a/R/ard_wilcoxtest.R b/R/ard_stats_wilcox_test.R similarity index 92% rename from R/ard_wilcoxtest.R rename to R/ard_stats_wilcox_test.R index d17185609..7e31f6822 100644 --- a/R/ard_wilcoxtest.R +++ b/R/ard_stats_wilcox_test.R @@ -15,13 +15,13 @@ #' @param ... arguments passed to `wilcox.test(...)` #' #' @return ARD data frame -#' @name ard_wilcoxtest +#' @name ard_stats_wilcox_test #' #' @details -#' For the `ard_wilcoxtest()` function, the data is expected to be one row per subject. +#' For the `ard_stats_wilcox_test()` function, the data is expected to be one row per subject. #' The data is passed as `wilcox.test(data[[variable]] ~ data[[by]], paired = FALSE, ...)`. #' -#' For the `ard_paired_wilcoxtest()` function, the data is expected to be one row +#' For the `ard_stats_paired_wilcox_test()` function, the data is expected to be one row #' per subject per by level. Before the test is calculated, the data are #' reshaped to a wide format to be one row per subject. #' The data are then passed as @@ -30,7 +30,7 @@ #' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> -#' ard_wilcoxtest(by = "ARM", variables = "AGE") +#' ard_stats_wilcox_test(by = "ARM", variables = "AGE") #' #' # constructing a paired data set, #' # where patients receive both treatments @@ -38,12 +38,12 @@ #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> #' dplyr::arrange(USUBJID, ARM) |> -#' ard_paired_wilcoxtest(by = ARM, variables = AGE, id = USUBJID) +#' ard_stats_paired_wilcox_test(by = ARM, variables = AGE, id = USUBJID) NULL -#' @rdname ard_wilcoxtest +#' @rdname ard_stats_wilcox_test #' @export -ard_wilcoxtest <- function(data, variables, by = NULL, ...) { +ard_stats_wilcox_test <- function(data, variables, by = NULL, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") @@ -88,9 +88,9 @@ ard_wilcoxtest <- function(data, variables, by = NULL, ...) { dplyr::bind_rows() } -#' @rdname ard_wilcoxtest +#' @rdname ard_stats_wilcox_test #' @export -ard_paired_wilcoxtest <- function(data, by, variables, id, ...) { +ard_stats_paired_wilcox_test <- function(data, by, variables, id, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed("broom", reference_pkg = "cardx") @@ -148,7 +148,7 @@ ard_paired_wilcoxtest <- function(data, by, variables, id, ...) { #' # Pre-processing ADSL to have grouping factor (ARM here) with 2 levels #' ADSL <- cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> -#' ard_wilcoxtest(by = "ARM", variables = "AGE") +#' ard_stats_wilcox_test(by = "ARM", variables = "AGE") #' #' cardx:::.format_wilcoxtest_results( #' by = "ARM", diff --git a/R/ard_svychisq.R b/R/ard_survey_svychisq.R similarity index 94% rename from R/ard_svychisq.R rename to R/ard_survey_svychisq.R index 08e09d5cb..2ae37c743 100644 --- a/R/ard_svychisq.R +++ b/R/ard_survey_svychisq.R @@ -24,8 +24,8 @@ #' data(api, package = "survey") #' dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) #' -#' ard_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F") -ard_svychisq <- function(data, by, variables, statistic = "F", ...) { +#' ard_survey_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F") +ard_survey_svychisq <- function(data, by, variables, statistic = "F", ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") diff --git a/R/ard_svycontinuous.R b/R/ard_survey_svycontinuous.R similarity index 96% rename from R/ard_svycontinuous.R rename to R/ard_survey_svycontinuous.R index 762069cbe..392eabdbe 100644 --- a/R/ard_svycontinuous.R +++ b/R/ard_survey_svycontinuous.R @@ -38,15 +38,15 @@ #' data(api, package = "survey") #' dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) #' -#' ard_svycontinuous( +#' ard_survey_svycontinuous( #' data = dclus1, #' variables = api00, #' by = stype #' ) -ard_svycontinuous <- function(data, variables, by = NULL, - statistic = everything() ~ c("median", "p25", "p75"), - fmt_fn = NULL, - stat_label = NULL) { +ard_survey_svycontinuous <- function(data, variables, by = NULL, + statistic = everything() ~ c("median", "p25", "p75"), + fmt_fn = NULL, + stat_label = NULL) { cards::check_pkg_installed("survey", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- @@ -65,7 +65,7 @@ ard_svycontinuous <- function(data, variables, by = NULL, ) cards::fill_formula_selectors( data$variables[variables], - statistic = formals(ard_svycontinuous)[["statistic"]] |> eval() + statistic = formals(ard_survey_svycontinuous)[["statistic"]] |> eval() ) cards::check_list_elements( x = statistic, diff --git a/R/ard_svyranktest.R b/R/ard_survey_svyranktest.R similarity index 87% rename from R/ard_svyranktest.R rename to R/ard_survey_svyranktest.R index ebe334c94..3d7fa3c4f 100644 --- a/R/ard_svyranktest.R +++ b/R/ard_survey_svyranktest.R @@ -21,11 +21,11 @@ #' data(api, package = "survey") #' dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) #' -#' ard_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "wilcoxon") -#' ard_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "vanderWaerden") -#' ard_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") -#' ard_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis") -ard_svyranktest <- function(data, by, variables, test, ...) { +#' ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "wilcoxon") +#' ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "vanderWaerden") +#' ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") +#' ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis") +ard_survey_svyranktest <- function(data, by, variables, test, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") diff --git a/R/ard_svyttest.R b/R/ard_survey_svyttest.R similarity index 95% rename from R/ard_svyttest.R rename to R/ard_survey_svyttest.R index 8e0e86cec..d3f01c95b 100644 --- a/R/ard_svyttest.R +++ b/R/ard_survey_svyttest.R @@ -21,8 +21,8 @@ #' data(api, package = "survey") #' dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) #' -#' ard_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9) -ard_svyttest <- function(data, by, variables, conf.level = 0.95, ...) { +#' ard_survey_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9) +ard_survey_svyttest <- function(data, by, variables, conf.level = 0.95, ...) { # check installed packages --------------------------------------------------- cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") diff --git a/R/ard_survfit.R b/R/ard_survival_survfit.R similarity index 96% rename from R/ard_survfit.R rename to R/ard_survival_survfit.R index e13709af4..5dcd7ca55 100644 --- a/R/ard_survfit.R +++ b/R/ard_survival_survfit.R @@ -25,7 +25,7 @@ #' ``` #' #' @return an ARD data frame of class 'card' -#' @name ard_survfit +#' @name ard_survival_survfit #' #' @details #' * Only one of either the `times` or `probs` parameters can be specified. @@ -36,10 +36,10 @@ #' library(survival) #' #' survfit(Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> -#' ard_survfit(times = c(60, 180)) +#' ard_survival_survfit(times = c(60, 180)) #' #' survfit(Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> -#' ard_survfit(probs = c(0.25, 0.5, 0.75)) +#' ard_survival_survfit(probs = c(0.25, 0.5, 0.75)) #' #' # Competing Risks Example --------------------------- #' set.seed(1) @@ -53,12 +53,12 @@ #' ) #' #' survfit(Surv(AVAL, CNSR) ~ TRTA, data = ADTTE_MS) %>% -#' ard_survfit(times = c(60, 180)) +#' ard_survival_survfit(times = c(60, 180)) NULL -#' @rdname ard_survfit +#' @rdname ard_survival_survfit #' @export -ard_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { +ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { # check installed packages --------------------------------------------------- cards::check_pkg_installed(c("survival", "broom"), reference_pkg = "cardx") @@ -101,7 +101,7 @@ ard_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { #' Process Survival Fit For Time Estimates #' #' @inheritParams cards::tidy_as_ard -#' @inheritParams ard_survfit +#' @inheritParams ard_survival_survfit #' #' @return a `tibble` #' @@ -209,7 +209,7 @@ ard_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { #' Process Survival Fit For Quantile Estimates #' #' @inheritParams cards::tidy_as_ard -#' @inheritParams ard_survfit +#' @inheritParams ard_survival_survfit #' #' @return a `tibble` #' diff --git a/_pkgdown.yml b/_pkgdown.yml index fc98e72e1..928367043 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -11,10 +11,10 @@ template: # github: # icon: fa-github # href: https://github.com/insightsengineering/cardx - -development: - mode: auto - version_label: default +# +# development: +# mode: auto +# version_label: default authors: Daniel D. Sjoberg: @@ -24,32 +24,32 @@ reference: - title: "ARD Creation" - subtitle: "Inference" - contents: - - ard_aov - ard_car_anova - - ard_chisqtest - - ard_fishertest - - ard_kruskaltest - - ard_moodtest - - ard_mcnemartest - - ard_onewaytest - - ard_proptest - - ard_svychisq - - ard_svyranktest - - ard_svyttest - - ard_ttest - - ard_wilcoxtest + - ard_stats_aov + - ard_stats_chisq_test + - ard_stats_fisher_test + - ard_stats_kruskal_test + - ard_stats_mood_test + - ard_stats_mcnemar_test + - ard_stats_oneway_test + - ard_stats_prop_test + - ard_stats_t_test + - ard_stats_wilcox_test + - ard_survey_svychisq + - ard_survey_svyranktest + - ard_survey_svyttest - subtitle: "Estimation" - contents: - - ard_cohens_d - - ard_hedges_g + - ard_car_vif + - ard_effectsize_cohens_d + - ard_effectsize_hedges_g - ard_proportion_ci - ard_regression - ard_regression_basic - - ard_smd - - ard_survfit - - ard_svycontinuous - - ard_vif + - ard_smd_smd + - ard_survival_survfit + - ard_survey_svycontinuous - title: "Helpers" - contents: diff --git a/man/ard_vif.Rd b/man/ard_car_vif.Rd similarity index 79% rename from man/ard_vif.Rd rename to man/ard_car_vif.Rd index ca9b9bd6f..0ddbfa572 100644 --- a/man/ard_vif.Rd +++ b/man/ard_car_vif.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_vif.R -\name{ard_vif} -\alias{ard_vif} +% Please edit documentation in R/ard_car_vif.R +\name{ard_car_vif} +\alias{ard_car_vif} \title{Regression VIF ARD} \usage{ -ard_vif(x, ...) +ard_car_vif(x, ...) } \arguments{ \item{x}{regression model object @@ -21,5 +21,5 @@ using \code{\link[car:vif]{car::vif()}} and converts it to a ARD structure } \examples{ lm(AGE ~ ARM + SEX, data = cards::ADSL) |> - ard_vif() + ard_car_vif() } diff --git a/man/ard_cohens_d.Rd b/man/ard_effectsize_cohens_d.Rd similarity index 76% rename from man/ard_cohens_d.Rd rename to man/ard_effectsize_cohens_d.Rd index f133e8ea5..a0d1f5a20 100644 --- a/man/ard_cohens_d.Rd +++ b/man/ard_effectsize_cohens_d.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_cohens_d.R -\name{ard_cohens_d} -\alias{ard_cohens_d} -\alias{ard_paired_cohens_d} +% Please edit documentation in R/ard_effectsize_cohens_d.R +\name{ard_effectsize_cohens_d} +\alias{ard_effectsize_cohens_d} +\alias{ard_effectsize_paired_cohens_d} \title{ARD Cohen's D Test} \usage{ -ard_cohens_d(data, by, variables, ...) +ard_effectsize_cohens_d(data, by, variables, ...) -ard_paired_cohens_d(data, by, variables, id, ...) +ard_effectsize_paired_cohens_d(data, by, variables, id, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -33,10 +33,10 @@ Analysis results data for paired and non-paired Cohen's D Effect Size Test using \code{\link[effectsize:cohens_d]{effectsize::cohens_d()}}. } \details{ -For the \code{ard_cohens_d()} function, the data is expected to be one row per subject. +For the \code{ard_effectsize_cohens_d()} function, the data is expected to be one row per subject. The data is passed as \code{effectsize::cohens_d(data[[variable]]~data[[by]], data, paired = FALSE, ...)}. -For the \code{ard_paired_cohens_d()} function, the data is expected to be one row +For the \code{ard_effectsize_paired_cohens_d()} function, the data is expected to be one row per subject per by level. Before the effect size is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as @@ -46,7 +46,7 @@ The data are then passed as \dontshow{if (cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> - ard_cohens_d(by = ARM, variables = AGE) + ard_effectsize_cohens_d(by = ARM, variables = AGE) # constructing a paired data set, # where patients receive both treatments @@ -56,6 +56,6 @@ cards::ADSL[c("ARM", "AGE")] |> dplyr::arrange(USUBJID, ARM) |> dplyr::group_by(USUBJID) |> dplyr::filter(dplyr::n() > 1) |> - ard_paired_cohens_d(by = ARM, variables = AGE, id = USUBJID) + ard_effectsize_paired_cohens_d(by = ARM, variables = AGE, id = USUBJID) \dontshow{\}) # examplesIf} } diff --git a/man/ard_hedges_g.Rd b/man/ard_effectsize_hedges_g.Rd similarity index 76% rename from man/ard_hedges_g.Rd rename to man/ard_effectsize_hedges_g.Rd index 9e4f47509..e726614f1 100644 --- a/man/ard_hedges_g.Rd +++ b/man/ard_effectsize_hedges_g.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_hedges_g.R -\name{ard_hedges_g} -\alias{ard_hedges_g} -\alias{ard_paired_hedges_g} +% Please edit documentation in R/ard_effectsize_hedges_g.R +\name{ard_effectsize_hedges_g} +\alias{ard_effectsize_hedges_g} +\alias{ard_effectsize_paired_hedges_g} \title{ARD Hedge's G Test} \usage{ -ard_hedges_g(data, by, variables, ...) +ard_effectsize_hedges_g(data, by, variables, ...) -ard_paired_hedges_g(data, by, variables, id, ...) +ard_effectsize_paired_hedges_g(data, by, variables, id, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -33,10 +33,10 @@ Analysis results data for paired and non-paired Hedge's G Effect Size Test using \code{\link[effectsize:cohens_d]{effectsize::hedges_g()}}. } \details{ -For the \code{ard_hedges_g()} function, the data is expected to be one row per subject. +For the \code{ard_effectsize_hedges_g()} function, the data is expected to be one row per subject. The data is passed as \code{effectsize::hedges_g(data[[variable]]~data[[by]], data, paired = FALSE, ...)}. -For the \code{ard_paired_hedges_g()} function, the data is expected to be one row +For the \code{ard_effectsize_paired_hedges_g()} function, the data is expected to be one row per subject per by level. Before the effect size is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as @@ -46,7 +46,7 @@ The data are then passed as \dontshow{if (cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> - ard_hedges_g(by = ARM, variables = AGE) + ard_effectsize_hedges_g(by = ARM, variables = AGE) # constructing a paired data set, # where patients receive both treatments @@ -56,6 +56,6 @@ cards::ADSL[c("ARM", "AGE")] |> dplyr::arrange(USUBJID, ARM) |> dplyr::group_by(USUBJID) |> dplyr::filter(dplyr::n() > 1) |> - ard_paired_hedges_g(by = ARM, variables = AGE, id = USUBJID) + ard_effectsize_paired_hedges_g(by = ARM, variables = AGE, id = USUBJID) \dontshow{\}) # examplesIf} } diff --git a/man/ard_smd.Rd b/man/ard_smd_smd.Rd similarity index 82% rename from man/ard_smd.Rd rename to man/ard_smd_smd.Rd index 046f2826b..385cb01ed 100644 --- a/man/ard_smd.Rd +++ b/man/ard_smd_smd.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_smd.R -\name{ard_smd} -\alias{ard_smd} +% Please edit documentation in R/ard_smd_smd.R +\name{ard_smd_smd} +\alias{ard_smd_smd} \title{ARD Standardized Mean Difference} \usage{ -ard_smd(data, by, variables, ...) +ard_smd_smd(data, by, variables, ...) } \arguments{ \item{data}{(\code{data.frame}/\code{survey.design})\cr @@ -35,7 +35,7 @@ Standardized mean difference calculated via \code{\link[smd:smd]{smd::smd()}} wi } \examples{ \dontshow{if (cards::is_pkg_installed("smd", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -ard_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE) -ard_smd(cards::ADSL, by = ARM, variables = AGEGR1, std.error = TRUE) +ard_smd_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE) +ard_smd_smd(cards::ADSL, by = ARM, variables = AGEGR1, std.error = TRUE) \dontshow{\}) # examplesIf} } diff --git a/man/ard_aov.Rd b/man/ard_stats_aov.Rd similarity index 79% rename from man/ard_aov.Rd rename to man/ard_stats_aov.Rd index 6f0d2a3da..3731f0ccd 100644 --- a/man/ard_aov.Rd +++ b/man/ard_stats_aov.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_aov.R -\name{ard_aov} -\alias{ard_aov} +% Please edit documentation in R/ard_stats_aov.R +\name{ard_stats_aov} +\alias{ard_stats_aov} \title{ARD ANOVA} \usage{ -ard_aov(formula, data, ...) +ard_stats_aov(formula, data, ...) } \arguments{ \item{formula}{A formula specifying the model.} @@ -24,6 +24,6 @@ Calculated with \code{stats::aov()} } \examples{ \dontshow{if (cards::is_pkg_installed(c("broom.helpers"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -ard_aov(AGE ~ ARM, data = cards::ADSL) +ard_stats_aov(AGE ~ ARM, data = cards::ADSL) \dontshow{\}) # examplesIf} } diff --git a/man/ard_chisqtest.Rd b/man/ard_stats_chisq_test.Rd similarity index 79% rename from man/ard_chisqtest.Rd rename to man/ard_stats_chisq_test.Rd index da1a7f1ca..c820e8056 100644 --- a/man/ard_chisqtest.Rd +++ b/man/ard_stats_chisq_test.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_chisqtest.R -\name{ard_chisqtest} -\alias{ard_chisqtest} +% Please edit documentation in R/ard_stats_chisq_test.R +\name{ard_stats_chisq_test} +\alias{ard_stats_chisq_test} \title{ARD Chi-squared Test} \usage{ -ard_chisqtest(data, by, variables, ...) +ard_stats_chisq_test(data, by, variables, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -29,6 +29,6 @@ Calculated with \code{chisq.test(x = data[[variable]], y = data[[by]], ...)} \examples{ \dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> - ard_chisqtest(by = "ARM", variables = "AGEGR1") + ard_stats_chisq_test(by = "ARM", variables = "AGEGR1") \dontshow{\}) # examplesIf} } diff --git a/man/ard_fishertest.Rd b/man/ard_stats_fisher_test.Rd similarity index 79% rename from man/ard_fishertest.Rd rename to man/ard_stats_fisher_test.Rd index 7fafb357e..5ba78bbc8 100644 --- a/man/ard_fishertest.Rd +++ b/man/ard_stats_fisher_test.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_fishertest.R -\name{ard_fishertest} -\alias{ard_fishertest} +% Please edit documentation in R/ard_stats_fisher_test.R +\name{ard_stats_fisher_test} +\alias{ard_stats_fisher_test} \title{ARD Fisher's Exact Test} \usage{ -ard_fishertest(data, by, variables, ...) +ard_stats_fisher_test(data, by, variables, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -29,6 +29,6 @@ Calculated with \code{fisher.test(x = data[[variable]], y = data[[by]], ...)} \examples{ \dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL[1:30, ] |> - ard_fishertest(by = "ARM", variables = "AGEGR1") + ard_stats_fisher_test(by = "ARM", variables = "AGEGR1") \dontshow{\}) # examplesIf} } diff --git a/man/ard_kruskaltest.Rd b/man/ard_stats_kruskal_test.Rd similarity index 77% rename from man/ard_kruskaltest.Rd rename to man/ard_stats_kruskal_test.Rd index 341ef739a..59e4bde5c 100644 --- a/man/ard_kruskaltest.Rd +++ b/man/ard_stats_kruskal_test.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_kruskaltest.R -\name{ard_kruskaltest} -\alias{ard_kruskaltest} +% Please edit documentation in R/ard_stats_kruskal_test.R +\name{ard_stats_kruskal_test} +\alias{ard_stats_kruskal_test} \title{ARD Kruskal-Wallis Test} \usage{ -ard_kruskaltest(data, by, variables) +ard_stats_kruskal_test(data, by, variables) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -28,6 +28,6 @@ Calculated with \code{kruskal.test(data[[variable]], data[[by]], ...)} \examples{ \dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> - ard_kruskaltest(by = "ARM", variables = "AGE") + ard_stats_kruskal_test(by = "ARM", variables = "AGE") \dontshow{\}) # examplesIf} } diff --git a/man/ard_mcnemartest.Rd b/man/ard_stats_mcnemar_test.Rd similarity index 75% rename from man/ard_mcnemartest.Rd rename to man/ard_stats_mcnemar_test.Rd index 8bbcf6915..3b47a0498 100644 --- a/man/ard_mcnemartest.Rd +++ b/man/ard_stats_mcnemar_test.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_mcnemartest.R -\name{ard_mcnemartest} -\alias{ard_mcnemartest} +% Please edit documentation in R/ard_stats_mcnemar_test.R +\name{ard_stats_mcnemar_test} +\alias{ard_stats_mcnemar_test} \title{ARD McNemar's Test} \usage{ -ard_mcnemartest(data, by, variables, ...) +ard_stats_mcnemar_test(data, by, variables, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -26,13 +26,13 @@ ARD data frame Analysis results data for McNemar's statistical test. } \details{ -For the \code{ard_mcnemartest()} function, the data is expected to be one row per subject. +For the \code{ard_stats_mcnemar_test()} function, the data is expected to be one row per subject. The data is passed as \code{stats::mcnemar.test(x = data[[variable]], y = data[[by]], ...)}. Please use \code{table(x = data[[variable]], y = data[[by]])} to check the contingency table. } \examples{ \dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> - ard_mcnemartest(by = "SEX", variables = "EFFFL") + ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") \dontshow{\}) # examplesIf} } diff --git a/man/ard_moodtest.Rd b/man/ard_stats_mood_test.Rd similarity index 75% rename from man/ard_moodtest.Rd rename to man/ard_stats_mood_test.Rd index 8af20f89f..902b54c0f 100644 --- a/man/ard_moodtest.Rd +++ b/man/ard_stats_mood_test.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_moodtest.R -\name{ard_moodtest} -\alias{ard_moodtest} +% Please edit documentation in R/ard_stats_mood_test.R +\name{ard_stats_mood_test} +\alias{ard_stats_mood_test} \title{ARD Mood Test} \usage{ -ard_moodtest(data, by, variables, ...) +ard_stats_mood_test(data, by, variables, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -27,12 +27,12 @@ Analysis results data for Mood two sample test of scale. Note this not to be con the Brown-Mood test of medians. } \details{ -For the \code{ard_moodtest()} function, the data is expected to be one row per subject. +For the \code{ard_stats_mood_test()} function, the data is expected to be one row per subject. The data is passed as \code{mood.test(data[[variable]] ~ data[[by]], ...)}. } \examples{ \dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> - ard_moodtest(by = "SEX", variables = "AGE") + ard_stats_mood_test(by = "SEX", variables = "AGE") \dontshow{\}) # examplesIf} } diff --git a/man/ard_onewaytest.Rd b/man/ard_stats_oneway_test.Rd similarity index 80% rename from man/ard_onewaytest.Rd rename to man/ard_stats_oneway_test.Rd index 66427e5b3..639c814f8 100644 --- a/man/ard_onewaytest.Rd +++ b/man/ard_stats_oneway_test.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_onewaytest.R -\name{ard_onewaytest} -\alias{ard_onewaytest} +% Please edit documentation in R/ard_stats_oneway_test.R +\name{ard_stats_oneway_test} +\alias{ard_stats_oneway_test} \title{ARD One-way Test} \usage{ -ard_onewaytest(formula, data, ...) +ard_stats_oneway_test(formula, data, ...) } \arguments{ \item{formula}{a formula of the form \code{lhs ~ rhs} where \code{lhs} @@ -26,6 +26,6 @@ calculated with \code{oneway.test()} } \examples{ \dontshow{if (cards::is_pkg_installed(c("broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} -ard_onewaytest(AGE ~ ARM, data = cards::ADSL) +ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) \dontshow{\}) # examplesIf} } diff --git a/man/ard_proptest.Rd b/man/ard_stats_prop_test.Rd similarity index 81% rename from man/ard_proptest.Rd rename to man/ard_stats_prop_test.Rd index 3fa0add66..0dbfbfdc9 100644 --- a/man/ard_proptest.Rd +++ b/man/ard_stats_prop_test.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_proptest.R -\name{ard_proptest} -\alias{ard_proptest} +% Please edit documentation in R/ard_stats_prop_test.R +\name{ard_stats_prop_test} +\alias{ard_stats_prop_test} \title{ARD 2-sample proportion test} \usage{ -ard_proptest(data, by, variables, ...) +ard_stats_prop_test(data, by, variables, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -28,6 +28,6 @@ Analysis results data for a 2-sample test or proportions using \code{\link[stats \examples{ \dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} mtcars |> - ard_proptest(by = vs, variables = am) + ard_stats_prop_test(by = vs, variables = am) \dontshow{\}) # examplesIf} } diff --git a/man/ard_ttest.Rd b/man/ard_stats_t_test.Rd similarity index 74% rename from man/ard_ttest.Rd rename to man/ard_stats_t_test.Rd index 78951dd5d..5bc92322d 100644 --- a/man/ard_ttest.Rd +++ b/man/ard_stats_t_test.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_ttest.R -\name{ard_ttest} -\alias{ard_ttest} -\alias{ard_paired_ttest} +% Please edit documentation in R/ard_stats_t_test.R +\name{ard_stats_t_test} +\alias{ard_stats_t_test} +\alias{ard_stats_paired_t_test} \title{ARD t-test} \usage{ -ard_ttest(data, variables, by = NULL, ...) +ard_stats_t_test(data, variables, by = NULL, ...) -ard_paired_ttest(data, by, variables, id, ...) +ard_stats_paired_t_test(data, by, variables, id, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -32,10 +32,10 @@ ARD data frame Analysis results data for paired and non-paired t-tests. } \details{ -For the \code{ard_ttest()} function, the data is expected to be one row per subject. +For the \code{ard_stats_t_test()} function, the data is expected to be one row per subject. The data is passed as \code{t.test(data[[variable]] ~ data[[by]], paired = FALSE, ...)}. -For the \code{ard_paired_ttest()} function, the data is expected to be one row +For the \code{ard_stats_paired_t_test()} function, the data is expected to be one row per subject per by level. Before the t-test is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as @@ -45,7 +45,7 @@ The data are then passed as \dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> - ard_ttest(by = ARM, variables = c(AGE, BMIBL)) + ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) # constructing a paired data set, # where patients receive both treatments @@ -53,6 +53,6 @@ cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> - ard_paired_ttest(by = ARM, variables = AGE, id = USUBJID) + ard_stats_paired_t_test(by = ARM, variables = AGE, id = USUBJID) \dontshow{\}) # examplesIf} } diff --git a/man/ard_wilcoxtest.Rd b/man/ard_stats_wilcox_test.Rd similarity index 73% rename from man/ard_wilcoxtest.Rd rename to man/ard_stats_wilcox_test.Rd index f1619625e..9f52f4f8d 100644 --- a/man/ard_wilcoxtest.Rd +++ b/man/ard_stats_wilcox_test.Rd @@ -1,13 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_wilcoxtest.R -\name{ard_wilcoxtest} -\alias{ard_wilcoxtest} -\alias{ard_paired_wilcoxtest} +% Please edit documentation in R/ard_stats_wilcox_test.R +\name{ard_stats_wilcox_test} +\alias{ard_stats_wilcox_test} +\alias{ard_stats_paired_wilcox_test} \title{ARD Wilcoxon Rank-Sum Test} \usage{ -ard_wilcoxtest(data, variables, by = NULL, ...) +ard_stats_wilcox_test(data, variables, by = NULL, ...) -ard_paired_wilcoxtest(data, by, variables, id, ...) +ard_stats_paired_wilcox_test(data, by, variables, id, ...) } \arguments{ \item{data}{(\code{data.frame})\cr @@ -32,10 +32,10 @@ ARD data frame Analysis results data for paired and non-paired Wilcoxon Rank-Sum tests. } \details{ -For the \code{ard_wilcoxtest()} function, the data is expected to be one row per subject. +For the \code{ard_stats_wilcox_test()} function, the data is expected to be one row per subject. The data is passed as \code{wilcox.test(data[[variable]] ~ data[[by]], paired = FALSE, ...)}. -For the \code{ard_paired_wilcoxtest()} function, the data is expected to be one row +For the \code{ard_stats_paired_wilcox_test()} function, the data is expected to be one row per subject per by level. Before the test is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as @@ -45,7 +45,7 @@ The data are then passed as \dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> - ard_wilcoxtest(by = "ARM", variables = "AGE") + ard_stats_wilcox_test(by = "ARM", variables = "AGE") # constructing a paired data set, # where patients receive both treatments @@ -53,6 +53,6 @@ cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> dplyr::arrange(USUBJID, ARM) |> - ard_paired_wilcoxtest(by = ARM, variables = AGE, id = USUBJID) + ard_stats_paired_wilcox_test(by = ARM, variables = AGE, id = USUBJID) \dontshow{\}) # examplesIf} } diff --git a/man/ard_svychisq.Rd b/man/ard_survey_svychisq.Rd similarity index 83% rename from man/ard_svychisq.Rd rename to man/ard_survey_svychisq.Rd index 9206ff03c..5b8465d2b 100644 --- a/man/ard_svychisq.Rd +++ b/man/ard_survey_svychisq.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_svychisq.R -\name{ard_svychisq} -\alias{ard_svychisq} +% Please edit documentation in R/ard_survey_svychisq.R +\name{ard_survey_svychisq} +\alias{ard_survey_svychisq} \title{ARD Survey Chi-Square Test} \usage{ -ard_svychisq(data, by, variables, statistic = "F", ...) +ard_survey_svychisq(data, by, variables, statistic = "F", ...) } \arguments{ \item{data}{(\code{survey.design})\cr @@ -36,6 +36,6 @@ Only two-way comparisons are supported. data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) -ard_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F") +ard_survey_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F") \dontshow{\}) # examplesIf} } diff --git a/man/ard_svycontinuous.Rd b/man/ard_survey_svycontinuous.Rd similarity index 92% rename from man/ard_svycontinuous.Rd rename to man/ard_survey_svycontinuous.Rd index 8e13d8a63..c60b56add 100644 --- a/man/ard_svycontinuous.Rd +++ b/man/ard_survey_svycontinuous.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_svycontinuous.R -\name{ard_svycontinuous} -\alias{ard_svycontinuous} +% Please edit documentation in R/ard_survey_svycontinuous.R +\name{ard_survey_svycontinuous} +\alias{ard_survey_svycontinuous} \title{ARD Continuous Survey Statistics} \usage{ -ard_svycontinuous( +ard_survey_svycontinuous( data, variables, by = NULL, @@ -60,7 +60,7 @@ where 'p##' is are the percentiles and \verb{##} is an integer between 0 and 100 data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) -ard_svycontinuous( +ard_survey_svycontinuous( data = dclus1, variables = api00, by = stype diff --git a/man/ard_svyranktest.Rd b/man/ard_survey_svyranktest.Rd similarity index 69% rename from man/ard_svyranktest.Rd rename to man/ard_survey_svyranktest.Rd index be6aa0b29..33eea727c 100644 --- a/man/ard_svyranktest.Rd +++ b/man/ard_survey_svyranktest.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_svyranktest.R -\name{ard_svyranktest} -\alias{ard_svyranktest} +% Please edit documentation in R/ard_survey_svyranktest.R +\name{ard_survey_svyranktest} +\alias{ard_survey_svyranktest} \title{ARD Survey rank test} \usage{ -ard_svyranktest(data, by, variables, test, ...) +ard_survey_svyranktest(data, by, variables, test, ...) } \arguments{ \item{data}{(\code{survey.design})\cr @@ -33,9 +33,9 @@ Analysis results data for survey wilcox test using \code{\link[survey:svyranktes data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) -ard_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "wilcoxon") -ard_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "vanderWaerden") -ard_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") -ard_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis") +ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "wilcoxon") +ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "vanderWaerden") +ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") +ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis") \dontshow{\}) # examplesIf} } diff --git a/man/ard_svyttest.Rd b/man/ard_survey_svyttest.Rd similarity index 81% rename from man/ard_svyttest.Rd rename to man/ard_survey_svyttest.Rd index b29f806b9..c80254245 100644 --- a/man/ard_svyttest.Rd +++ b/man/ard_survey_svyttest.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_svyttest.R -\name{ard_svyttest} -\alias{ard_svyttest} +% Please edit documentation in R/ard_survey_svyttest.R +\name{ard_survey_svyttest} +\alias{ard_survey_svyttest} \title{ARD Survey t-test} \usage{ -ard_svyttest(data, by, variables, conf.level = 0.95, ...) +ard_survey_svyttest(data, by, variables, conf.level = 0.95, ...) } \arguments{ \item{data}{(\code{survey.design})\cr @@ -33,6 +33,6 @@ Analysis results data for survey t-test using \code{\link[survey:svyttest]{surve data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) -ard_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9) +ard_survey_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9) \dontshow{\}) # examplesIf} } diff --git a/man/ard_survfit.Rd b/man/ard_survival_survfit.Rd similarity index 86% rename from man/ard_survfit.Rd rename to man/ard_survival_survfit.Rd index 56eeac987..93fb00cdc 100644 --- a/man/ard_survfit.Rd +++ b/man/ard_survival_survfit.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_survfit.R -\name{ard_survfit} -\alias{ard_survfit} +% Please edit documentation in R/ard_survival_survfit.R +\name{ard_survival_survfit} +\alias{ard_survival_survfit} \title{ARD Survival Estimates} \usage{ -ard_survfit(x, times = NULL, probs = NULL, type = NULL) +ard_survival_survfit(x, times = NULL, probs = NULL, type = NULL) } \arguments{ \item{x}{(\code{\link[survival:survfit]{survival::survfit()}})\cr @@ -45,10 +45,10 @@ survival fit model. library(survival) survfit(Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> - ard_survfit(times = c(60, 180)) + ard_survival_survfit(times = c(60, 180)) survfit(Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> - ard_survfit(probs = c(0.25, 0.5, 0.75)) + ard_survival_survfit(probs = c(0.25, 0.5, 0.75)) # Competing Risks Example --------------------------- set.seed(1) @@ -62,6 +62,6 @@ ADTTE_MS <- cards::ADTTE \%>\% ) survfit(Surv(AVAL, CNSR) ~ TRTA, data = ADTTE_MS) \%>\% - ard_survfit(times = c(60, 180)) + ard_survival_survfit(times = c(60, 180)) \dontshow{\}) # examplesIf} } diff --git a/man/dot-format_cohens_d_results.Rd b/man/dot-format_cohens_d_results.Rd index 1d6dec528..87de50e57 100644 --- a/man/dot-format_cohens_d_results.Rd +++ b/man/dot-format_cohens_d_results.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_cohens_d.R +% Please edit documentation in R/ard_effectsize_cohens_d.R \name{.format_cohens_d_results} \alias{.format_cohens_d_results} \title{Convert Cohen's D Test to ARD} diff --git a/man/dot-format_hedges_g_results.Rd b/man/dot-format_hedges_g_results.Rd index 95deb3ee9..3d119c5ca 100644 --- a/man/dot-format_hedges_g_results.Rd +++ b/man/dot-format_hedges_g_results.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_hedges_g.R +% Please edit documentation in R/ard_effectsize_hedges_g.R \name{.format_hedges_g_results} \alias{.format_hedges_g_results} \title{Convert Hedge's G Test to ARD} diff --git a/man/dot-format_mcnemartest_results.Rd b/man/dot-format_mcnemartest_results.Rd index a809a791c..5d6725c69 100644 --- a/man/dot-format_mcnemartest_results.Rd +++ b/man/dot-format_mcnemartest_results.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_mcnemartest.R +% Please edit documentation in R/ard_stats_mcnemar_test.R \name{.format_mcnemartest_results} \alias{.format_mcnemartest_results} \title{Convert McNemar's test to ARD} diff --git a/man/dot-format_moodtest_results.Rd b/man/dot-format_moodtest_results.Rd index 95cae344e..dbc9a11b8 100644 --- a/man/dot-format_moodtest_results.Rd +++ b/man/dot-format_moodtest_results.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_moodtest.R +% Please edit documentation in R/ard_stats_mood_test.R \name{.format_moodtest_results} \alias{.format_moodtest_results} \title{Convert mood test results to ARD} diff --git a/man/dot-format_proptest_results.Rd b/man/dot-format_proptest_results.Rd index 8719c7275..05c97ef24 100644 --- a/man/dot-format_proptest_results.Rd +++ b/man/dot-format_proptest_results.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_proptest.R +% Please edit documentation in R/ard_stats_prop_test.R \name{.format_proptest_results} \alias{.format_proptest_results} \title{Convert prop.test to ARD} diff --git a/man/dot-format_survfit_results.Rd b/man/dot-format_survfit_results.Rd index d1a1e36fb..824e876ac 100644 --- a/man/dot-format_survfit_results.Rd +++ b/man/dot-format_survfit_results.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_survfit.R +% Please edit documentation in R/ard_survival_survfit.R \name{.format_survfit_results} \alias{.format_survfit_results} \title{Convert Tidied Survival Fit to ARD} diff --git a/man/dot-format_ttest_results.Rd b/man/dot-format_ttest_results.Rd index d8304df9f..b00306f68 100644 --- a/man/dot-format_ttest_results.Rd +++ b/man/dot-format_ttest_results.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_ttest.R +% Please edit documentation in R/ard_stats_t_test.R \name{.format_ttest_results} \alias{.format_ttest_results} \title{Convert t-test to ARD} diff --git a/man/dot-format_wilcoxtest_results.Rd b/man/dot-format_wilcoxtest_results.Rd index 69fde1ef4..083893241 100644 --- a/man/dot-format_wilcoxtest_results.Rd +++ b/man/dot-format_wilcoxtest_results.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_wilcoxtest.R +% Please edit documentation in R/ard_stats_wilcox_test.R \name{.format_wilcoxtest_results} \alias{.format_wilcoxtest_results} \title{Convert Wilcoxon test to ARD} @@ -29,7 +29,7 @@ Convert Wilcoxon test to ARD # Pre-processing ADSL to have grouping factor (ARM here) with 2 levels ADSL <- cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> - ard_wilcoxtest(by = "ARM", variables = "AGE") + ard_stats_wilcox_test(by = "ARM", variables = "AGE") cardx:::.format_wilcoxtest_results( by = "ARM", diff --git a/man/dot-paired_data_pivot_wider.Rd b/man/dot-paired_data_pivot_wider.Rd index a73b469e3..4de078355 100644 --- a/man/dot-paired_data_pivot_wider.Rd +++ b/man/dot-paired_data_pivot_wider.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_ttest.R, R/ard_wilcoxtest.R +% Please edit documentation in R/ard_stats_t_test.R, R/ard_stats_wilcox_test.R \name{.paired_data_pivot_wider} \alias{.paired_data_pivot_wider} \title{Convert long paired data to wide} diff --git a/man/dot-process_survfit_probs.Rd b/man/dot-process_survfit_probs.Rd index 4e2a89923..dc1f588e4 100644 --- a/man/dot-process_survfit_probs.Rd +++ b/man/dot-process_survfit_probs.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_survfit.R +% Please edit documentation in R/ard_survival_survfit.R \name{.process_survfit_probs} \alias{.process_survfit_probs} \title{Process Survival Fit For Quantile Estimates} diff --git a/man/dot-process_survfit_time.Rd b/man/dot-process_survfit_time.Rd index 6fe6a0dd7..7f1c673a8 100644 --- a/man/dot-process_survfit_time.Rd +++ b/man/dot-process_survfit_time.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_survfit.R +% Please edit documentation in R/ard_survival_survfit.R \name{.process_survfit_time} \alias{.process_survfit_time} \title{Process Survival Fit For Time Estimates} diff --git a/tests/testthat/_snaps/ard_chisqtest.md b/tests/testthat/_snaps/ard_chisqtest.md deleted file mode 100644 index 8ac52ec30..000000000 --- a/tests/testthat/_snaps/ard_chisqtest.md +++ /dev/null @@ -1,17 +0,0 @@ -# shuffle_ard fills missing group levels if the group is meaningful - - Code - as.data.frame(cards::shuffle_ard(cards::bind_ard(ard_chisqtest(data = adsl_sub, - by = "ARM", variables = "AGEGR1"), ard_chisqtest(data = adsl_sub, by = "SEX", - variables = "AGEGR1")))) - Output - ARM SEX variable context stat_name stat - 1 Overall ARM AGEGR1 chisqtest statistic 5.079442e+00 - 2 Overall ARM AGEGR1 chisqtest p.value 7.888842e-02 - 3 Overall ARM AGEGR1 chisqtest parameter 2.000000e+00 - 4 Overall ARM AGEGR1 chisqtest B 2.000000e+03 - 5 Overall SEX AGEGR1 chisqtest statistic 1.039442e+00 - 6 Overall SEX AGEGR1 chisqtest p.value 5.946864e-01 - 7 Overall SEX AGEGR1 chisqtest parameter 2.000000e+00 - 8 Overall SEX AGEGR1 chisqtest B 2.000000e+03 - diff --git a/tests/testthat/_snaps/ard_cohens_d.md b/tests/testthat/_snaps/ard_effectsize_cohens_d.md similarity index 75% rename from tests/testthat/_snaps/ard_cohens_d.md rename to tests/testthat/_snaps/ard_effectsize_cohens_d.md index 11a601833..7f3d5732b 100644 --- a/tests/testthat/_snaps/ard_cohens_d.md +++ b/tests/testthat/_snaps/ard_effectsize_cohens_d.md @@ -1,8 +1,8 @@ -# ard_cohens_d() works +# ard_effectsize_cohens_d() works Code - as.data.frame(dplyr::select(ard_cohens_d(cards::ADSL, by = ARM, variables = AGE), - c("variable", "stat_name", "error"))) + as.data.frame(dplyr::select(ard_effectsize_cohens_d(cards::ADSL, by = ARM, + variables = AGE), c("variable", "stat_name", "error"))) Output variable stat_name error 1 AGE estimate Grouping variable y must have exactly 2 levels. @@ -17,9 +17,10 @@ --- Code - as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select(ard_cohens_d( - dplyr::filter(cards::ADSL, ARM %in% c("Placebo", "Xanomeline High Dose")), - by = ARM, variables = c(BMIBL, HEIGHTBL)), c(1:3, 5:6)), variable), n = 3)) + as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select( + ard_effectsize_cohens_d(dplyr::filter(cards::ADSL, ARM %in% c("Placebo", + "Xanomeline High Dose")), by = ARM, variables = c(BMIBL, HEIGHTBL)), c(1:3, + 5:6)), variable), n = 3)) Output group1 variable context stat_label stat 1 ARM BMIBL cohens_d Effect Size Estimate -0.436653 @@ -29,12 +30,12 @@ 5 ARM HEIGHTBL cohens_d CI Confidence Level 0.95 6 ARM HEIGHTBL cohens_d CI Lower Bound -0.600975 -# ard_paired_cohens_d() works +# ard_effectsize_paired_cohens_d() works Code - as.data.frame(dplyr::select(ard_paired_cohens_d(dplyr::mutate(ADSL_paired, ARM = ifelse( - dplyr::row_number() == 1L, "3rd ARM", ARM)), by = ARM, variable = AGE, id = USUBJID), - c("variable", "stat_name", "error"))) + as.data.frame(dplyr::select(ard_effectsize_paired_cohens_d(dplyr::mutate( + ADSL_paired, ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM)), by = ARM, + variable = AGE, id = USUBJID), c("variable", "stat_name", "error"))) Output variable stat_name error 1 AGE estimate The `by` argument must have two and only two levels. diff --git a/tests/testthat/_snaps/ard_hedges_g.md b/tests/testthat/_snaps/ard_effectsize_hedges_g.md similarity index 75% rename from tests/testthat/_snaps/ard_hedges_g.md rename to tests/testthat/_snaps/ard_effectsize_hedges_g.md index 33568dd9f..149f7b705 100644 --- a/tests/testthat/_snaps/ard_hedges_g.md +++ b/tests/testthat/_snaps/ard_effectsize_hedges_g.md @@ -1,8 +1,8 @@ -# ard_hedges_g() works +# ard_effectsize_hedges_g() works Code - as.data.frame(dplyr::select(ard_hedges_g(cards::ADSL, by = ARM, variable = AGE), - c("variable", "stat_name", "error"))) + as.data.frame(dplyr::select(ard_effectsize_hedges_g(cards::ADSL, by = ARM, + variable = AGE), c("variable", "stat_name", "error"))) Output variable stat_name error 1 AGE estimate Grouping variable y must have exactly 2 levels. @@ -17,9 +17,10 @@ --- Code - as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select(ard_hedges_g( - dplyr::filter(cards::ADSL, ARM %in% c("Placebo", "Xanomeline High Dose")), - by = ARM, variables = c(BMIBL, HEIGHTBL)), c(1:3, 5:6)), variable), n = 3)) + as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select( + ard_effectsize_hedges_g(dplyr::filter(cards::ADSL, ARM %in% c("Placebo", + "Xanomeline High Dose")), by = ARM, variables = c(BMIBL, HEIGHTBL)), c(1:3, + 5:6)), variable), n = 3)) Output group1 variable context stat_label stat 1 ARM BMIBL hedges_g Effect Size Estimate -0.4347006 @@ -29,12 +30,12 @@ 5 ARM HEIGHTBL hedges_g CI Confidence Level 0.95 6 ARM HEIGHTBL hedges_g CI Lower Bound -0.5982873 -# ard_paired_hedges_g() works +# ard_effectsize_paired_hedges_g() works Code - as.data.frame(dplyr::select(ard_paired_hedges_g(dplyr::mutate(ADSL_paired, ARM = ifelse( - dplyr::row_number() == 1L, "3rd ARM", ARM)), by = ARM, variable = AGE, id = USUBJID), - c("variable", "stat_name", "error"))) + as.data.frame(dplyr::select(ard_effectsize_paired_hedges_g(dplyr::mutate( + ADSL_paired, ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM)), by = ARM, + variable = AGE, id = USUBJID), c("variable", "stat_name", "error"))) Output variable stat_name error 1 AGE estimate The `by` argument must have two and only two levels. diff --git a/tests/testthat/_snaps/ard_aov.md b/tests/testthat/_snaps/ard_stats_aov.md similarity index 92% rename from tests/testthat/_snaps/ard_aov.md rename to tests/testthat/_snaps/ard_stats_aov.md index 7a88f2cb4..fa24cb0d7 100644 --- a/tests/testthat/_snaps/ard_aov.md +++ b/tests/testthat/_snaps/ard_stats_aov.md @@ -1,7 +1,7 @@ # ard_aov() works Code - as.data.frame(ard_aov(AGE ~ ARM + SEX, data = cards::ADSL)) + as.data.frame(ard_stats_aov(AGE ~ ARM + SEX, data = cards::ADSL)) Output variable context stat_name stat_label stat warning error 1 ARM aov sumsq Sum of Squares 71.38574 NULL NULL diff --git a/tests/testthat/_snaps/ard_kruskaltest.md b/tests/testthat/_snaps/ard_stats_kruskal_test.md similarity index 85% rename from tests/testthat/_snaps/ard_kruskaltest.md rename to tests/testthat/_snaps/ard_stats_kruskal_test.md index 29121c26b..0b4c1c5ea 100644 --- a/tests/testthat/_snaps/ard_kruskaltest.md +++ b/tests/testthat/_snaps/ard_stats_kruskal_test.md @@ -1,7 +1,7 @@ -# ard_kurskaltest() works +# ard_stats_kruskal_test() works Code - as.data.frame(ard_kruskaltest(cards::ADSL, by = "ARM", variables = "AGE")) + as.data.frame(ard_stats_kruskal_test(cards::ADSL, by = "ARM", variables = "AGE")) Output group1 variable context stat_name stat_label 1 ARM AGE kruskaltest statistic Kruskal-Wallis chi-squared Statistic diff --git a/tests/testthat/_snaps/ard_stats_t_test.md b/tests/testthat/_snaps/ard_stats_t_test.md new file mode 100644 index 000000000..d6873cc22 --- /dev/null +++ b/tests/testthat/_snaps/ard_stats_t_test.md @@ -0,0 +1,75 @@ +# ard_stats_t_test() works + + Code + as.data.frame(ard_stats_t_test(cards::ADSL, by = ARM, variable = AGE, + var.equal = TRUE)) + Output + group1 variable context stat_name stat_label stat fmt_fn warning + 1 ARM AGE ttest estimate Mean Difference NULL NULL NULL + 2 ARM AGE ttest estimate1 Group 1 Mean NULL NULL NULL + 3 ARM AGE ttest estimate2 Group 2 Mean NULL NULL NULL + 4 ARM AGE ttest statistic t Statistic NULL NULL NULL + 5 ARM AGE ttest p.value p-value NULL NULL NULL + 6 ARM AGE ttest parameter Degrees of Freedom NULL NULL NULL + 7 ARM AGE ttest conf.low CI Lower Bound NULL NULL NULL + 8 ARM AGE ttest conf.high CI Upper Bound NULL NULL NULL + 9 ARM AGE ttest method method NULL NULL NULL + 10 ARM AGE ttest alternative alternative NULL NULL NULL + 11 ARM AGE ttest mu H0 Mean 0 1 NULL + 12 ARM AGE ttest paired Paired t-test FALSE NULL NULL + 13 ARM AGE ttest var.equal Equal Variances TRUE NULL NULL + 14 ARM AGE ttest conf.level CI Confidence Level 0.95 1 NULL + error + 1 grouping factor must have exactly 2 levels + 2 grouping factor must have exactly 2 levels + 3 grouping factor must have exactly 2 levels + 4 grouping factor must have exactly 2 levels + 5 grouping factor must have exactly 2 levels + 6 grouping factor must have exactly 2 levels + 7 grouping factor must have exactly 2 levels + 8 grouping factor must have exactly 2 levels + 9 grouping factor must have exactly 2 levels + 10 grouping factor must have exactly 2 levels + 11 grouping factor must have exactly 2 levels + 12 grouping factor must have exactly 2 levels + 13 grouping factor must have exactly 2 levels + 14 grouping factor must have exactly 2 levels + +# ard_stats_paired_t_test() works + + Code + as.data.frame(ard_stats_paired_t_test(dplyr::mutate(ADSL_paired, ARM = ifelse( + dplyr::row_number() == 1L, "3rd ARM", ARM)), by = ARM, variable = AGE, id = USUBJID, + var.equal = TRUE)) + Output + group1 variable context stat_name stat_label stat fmt_fn warning + 1 ARM AGE ttest estimate Mean Difference NULL NULL NULL + 2 ARM AGE ttest estimate1 Group 1 Mean NULL NULL NULL + 3 ARM AGE ttest estimate2 Group 2 Mean NULL NULL NULL + 4 ARM AGE ttest statistic t Statistic NULL NULL NULL + 5 ARM AGE ttest p.value p-value NULL NULL NULL + 6 ARM AGE ttest parameter Degrees of Freedom NULL NULL NULL + 7 ARM AGE ttest conf.low CI Lower Bound NULL NULL NULL + 8 ARM AGE ttest conf.high CI Upper Bound NULL NULL NULL + 9 ARM AGE ttest method method NULL NULL NULL + 10 ARM AGE ttest alternative alternative NULL NULL NULL + 11 ARM AGE ttest mu H0 Mean 0 1 NULL + 12 ARM AGE ttest paired Paired t-test TRUE NULL NULL + 13 ARM AGE ttest var.equal Equal Variances TRUE NULL NULL + 14 ARM AGE ttest conf.level CI Confidence Level 0.95 1 NULL + error + 1 The `by` argument must have two and only two levels. + 2 The `by` argument must have two and only two levels. + 3 The `by` argument must have two and only two levels. + 4 The `by` argument must have two and only two levels. + 5 The `by` argument must have two and only two levels. + 6 The `by` argument must have two and only two levels. + 7 The `by` argument must have two and only two levels. + 8 The `by` argument must have two and only two levels. + 9 The `by` argument must have two and only two levels. + 10 The `by` argument must have two and only two levels. + 11 The `by` argument must have two and only two levels. + 12 The `by` argument must have two and only two levels. + 13 The `by` argument must have two and only two levels. + 14 The `by` argument must have two and only two levels. + diff --git a/tests/testthat/_snaps/ard_survey_svycontinuous.md b/tests/testthat/_snaps/ard_survey_svycontinuous.md new file mode 100644 index 000000000..ec07ffea5 --- /dev/null +++ b/tests/testthat/_snaps/ard_survey_svycontinuous.md @@ -0,0 +1,55 @@ +# unstratified ard_survey_svycontinuous() works + + Code + ard_uni_svy_cont + Message + {cards} data frame: 10 x 8 + Output + variable context stat_name stat_label stat fmt_fn + 1 api00 continuo… mean Mean 644.169 1 + 2 api00 continuo… median Median 652 1 + 3 api00 continuo… min Minimum 411 1 + 4 api00 continuo… max Maximum 905 1 + 5 api00 continuo… sum Sum 3989985 1 + 6 api00 continuo… var Variance 11182.82 1 + 7 api00 continuo… sd Standard… 105.749 1 + 8 api00 continuo… mean.std.error SE(Mean) 23.542 1 + 9 api00 continuo… deff Design E… 9.346 1 + 10 api00 continuo… p75 75% Perc… 719 1 + Message + i 2 more variables: warning, error + +# ard_survey_svycontinuous(fmt_fn) + + Code + ard_survey_svycontinuous(dclus1, variables = api00, statistic = ~ c("mean", + "median", "min", "max"), fmt_fn = list(api00 = list(mean = 2, median = "xx.xx", + min = as.character))) + Message + {cards} data frame: 4 x 8 + Output + variable context stat_name stat_label stat fmt_fn + 1 api00 continuo… mean Mean 644.169 2 + 2 api00 continuo… median Median 652 xx.xx + 3 api00 continuo… min Minimum 411 + 4 api00 continuo… max Maximum 905 1 + Message + i 2 more variables: warning, error + +# ard_survey_svycontinuous(stat_label) + + Code + ard_survey_svycontinuous(dclus1, variables = api00, statistic = ~ c("mean", + "median", "min", "max"), stat_label = list(api00 = list(mean = "MeAn", + median = "MEDian", min = "MINimum"))) + Message + {cards} data frame: 4 x 8 + Output + variable context stat_name stat_label stat fmt_fn + 1 api00 continuo… mean MeAn 644.169 1 + 2 api00 continuo… median MEDian 652 1 + 3 api00 continuo… min MINimum 411 1 + 4 api00 continuo… max Maximum 905 1 + Message + i 2 more variables: warning, error + diff --git a/tests/testthat/test-ard_vif.R b/tests/testthat/test-ard_car_vif.R similarity index 74% rename from tests/testthat/test-ard_vif.R rename to tests/testthat/test-ard_car_vif.R index b0201d7b8..6d717b8a3 100644 --- a/tests/testthat/test-ard_vif.R +++ b/tests/testthat/test-ard_car_vif.R @@ -1,26 +1,26 @@ -test_that("ard_vif() works", { +test_that("ard_car_vif() works", { expect_snapshot( lm(AGE ~ ARM + SEX, data = cards::ADSL) |> - ard_vif() |> + ard_car_vif() |> as.data.frame() ) expect_snapshot( lm(AGE ~ BMIBL + EDUCLVL, data = cards::ADSL) |> - ard_vif() |> + ard_car_vif() |> as.data.frame() ) }) -test_that("ard_vif() appropriate errors are given for model with only 1 term", { +test_that("ard_car_vif() appropriate errors are given for model with only 1 term", { expect_snapshot( lm(AGE ~ ARM, data = cards::ADSL) |> - ard_vif() |> + ard_car_vif() |> as.data.frame() ) expect_equal( lm(AGE ~ ARM, data = cards::ADSL) |> - ard_vif() |> + ard_car_vif() |> dplyr::select(error) |> unlist() |> unique(), diff --git a/tests/testthat/test-ard_cohens_d.R b/tests/testthat/test-ard_effectsize_cohens_d.R similarity index 81% rename from tests/testthat/test-ard_cohens_d.R rename to tests/testthat/test-ard_effectsize_cohens_d.R index a8c20caaa..25a83bc5b 100644 --- a/tests/testthat/test-ard_cohens_d.R +++ b/tests/testthat/test-ard_effectsize_cohens_d.R @@ -1,6 +1,6 @@ skip_if_not(cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")) -test_that("ard_cohens_d() works", { +test_that("ard_effectsize_cohens_d() works", { # there were some discrepancies in the 7th decimal place on one system withr::local_options(list(digits = 6)) @@ -8,7 +8,7 @@ test_that("ard_cohens_d() works", { ard_cohens_d <- cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_cohens_d(by = ARM, variables = AGE, pooled_sd = FALSE), + ard_effectsize_cohens_d(by = ARM, variables = AGE, pooled_sd = FALSE), NA ) @@ -28,7 +28,7 @@ test_that("ard_cohens_d() works", { # errors are properly handled expect_snapshot( cards::ADSL |> - ard_cohens_d(by = ARM, variables = AGE) |> + ard_effectsize_cohens_d(by = ARM, variables = AGE) |> dplyr::select(c("variable", "stat_name", "error")) |> as.data.frame() ) @@ -37,7 +37,7 @@ test_that("ard_cohens_d() works", { expect_snapshot( cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_cohens_d(by = ARM, variables = c(BMIBL, HEIGHTBL)) |> + ard_effectsize_cohens_d(by = ARM, variables = c(BMIBL, HEIGHTBL)) |> dplyr::select(c(1:3, 5:6)) |> dplyr::group_by(variable) |> dplyr::slice_head(n = 3) |> @@ -45,7 +45,7 @@ test_that("ard_cohens_d() works", { ) }) -test_that("ard_paired_cohens_d() works", { +test_that("ard_effectsize_paired_cohens_d() works", { ADSL_paired <- cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> @@ -54,14 +54,14 @@ test_that("ard_paired_cohens_d() works", { dplyr::filter(dplyr::n() > 1) expect_error( - ard_paired_cohens_d <- + ard_effectsize_paired_cohens_d <- ADSL_paired |> - ard_paired_cohens_d(by = ARM, variable = AGE, id = USUBJID), + ard_effectsize_paired_cohens_d(by = ARM, variable = AGE, id = USUBJID), NA ) expect_equal( - ard_paired_cohens_d |> + ard_effectsize_paired_cohens_d |> cards::get_ard_statistics(stat_name %in% c("estimate", "conf.low", "conf.high")), with( data = @@ -88,7 +88,7 @@ test_that("ard_paired_cohens_d() works", { dplyr::mutate( ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM) ) |> - ard_paired_cohens_d(by = ARM, variable = AGE, id = USUBJID) |> + ard_effectsize_paired_cohens_d(by = ARM, variable = AGE, id = USUBJID) |> dplyr::select(c("variable", "stat_name", "error")) |> as.data.frame() ) diff --git a/tests/testthat/test-ard_hedges_g.R b/tests/testthat/test-ard_effectsize_hedges_g.R similarity index 84% rename from tests/testthat/test-ard_hedges_g.R rename to tests/testthat/test-ard_effectsize_hedges_g.R index b85164704..f2e0dee97 100644 --- a/tests/testthat/test-ard_hedges_g.R +++ b/tests/testthat/test-ard_effectsize_hedges_g.R @@ -1,13 +1,13 @@ skip_if_not(cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) -test_that("ard_hedges_g() works", { +test_that("ard_effectsize_hedges_g() works", { withr::local_namespace("effectsize") expect_error( ard_hedges_g <- cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_hedges_g(by = ARM, variable = AGE), + ard_effectsize_hedges_g(by = ARM, variable = AGE), NA ) @@ -26,7 +26,7 @@ test_that("ard_hedges_g() works", { # errors are properly handled expect_snapshot( cards::ADSL |> - ard_hedges_g(by = ARM, variable = AGE) |> + ard_effectsize_hedges_g(by = ARM, variable = AGE) |> dplyr::select(c("variable", "stat_name", "error")) |> as.data.frame() ) @@ -35,7 +35,7 @@ test_that("ard_hedges_g() works", { expect_snapshot( cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_hedges_g(by = ARM, variables = c(BMIBL, HEIGHTBL)) |> + ard_effectsize_hedges_g(by = ARM, variables = c(BMIBL, HEIGHTBL)) |> dplyr::select(c(1:3, 5:6)) |> dplyr::group_by(variable) |> dplyr::slice_head(n = 3) |> @@ -43,7 +43,7 @@ test_that("ard_hedges_g() works", { ) }) -test_that("ard_paired_hedges_g() works", { +test_that("ard_effectsize_paired_hedges_g() works", { withr::local_namespace("effectsize") ADSL_paired <- @@ -56,7 +56,7 @@ test_that("ard_paired_hedges_g() works", { expect_error( ard_paired_hedges_g <- ADSL_paired |> - ard_paired_hedges_g(by = ARM, variable = AGE, id = USUBJID), + ard_effectsize_paired_hedges_g(by = ARM, variable = AGE, id = USUBJID), NA ) @@ -88,7 +88,7 @@ test_that("ard_paired_hedges_g() works", { dplyr::mutate( ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM) ) |> - ard_paired_hedges_g(by = ARM, variable = AGE, id = USUBJID) |> + ard_effectsize_paired_hedges_g(by = ARM, variable = AGE, id = USUBJID) |> dplyr::select(c("variable", "stat_name", "error")) |> as.data.frame() ) diff --git a/tests/testthat/test-ard_smd.R b/tests/testthat/test-ard_smd_smd.R similarity index 80% rename from tests/testthat/test-ard_smd.R rename to tests/testthat/test-ard_smd_smd.R index df268141e..5c0fc2f86 100644 --- a/tests/testthat/test-ard_smd.R +++ b/tests/testthat/test-ard_smd_smd.R @@ -1,10 +1,10 @@ skip_if_not(cards::is_pkg_installed("smd", reference_pkg = "cardx")) -test_that("ard_smd() works", { +test_that("ard_smd_smd() works", { expect_error( ard_smd <- mtcars |> - ard_smd(by = vs, variables = am, std.error = TRUE), + ard_smd_smd(by = vs, variables = am, std.error = TRUE), NA ) @@ -22,10 +22,10 @@ test_that("ard_smd() works", { dplyr::bind_rows( ard_smd, mtcars |> - ard_smd(by = vs, variables = gear, std.error = TRUE) + ard_smd_smd(by = vs, variables = gear, std.error = TRUE) ), mtcars |> - ard_smd(by = vs, variables = c(am, gear), std.error = TRUE) + ard_smd_smd(by = vs, variables = c(am, gear), std.error = TRUE) ) }) @@ -37,7 +37,7 @@ test_that("ard_smd() works with survey data", { expect_error( ard_smd <- dclus1 |> - ard_smd(by = both, variable = api00, std.error = TRUE), + ard_smd_smd(by = both, variable = api00, std.error = TRUE), NA ) @@ -55,7 +55,7 @@ test_that("ard_proptest() error messaging", { # mis-specify the gref argument expect_error( bad_gref <- - ard_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE, gref = 0) |> + ard_smd_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE, gref = 0) |> as.data.frame(), NA ) diff --git a/tests/testthat/test-ard_aov.R b/tests/testthat/test-ard_stats_aov.R similarity index 83% rename from tests/testthat/test-ard_aov.R rename to tests/testthat/test-ard_stats_aov.R index 4c60b383e..99fe86831 100644 --- a/tests/testthat/test-ard_aov.R +++ b/tests/testthat/test-ard_stats_aov.R @@ -3,7 +3,7 @@ skip_if_not(cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx")) test_that("ard_aov() works", { expect_error( ard_aov <- - ard_aov(AGE ~ ARM, data = cards::ADSL), + ard_stats_aov(AGE ~ ARM, data = cards::ADSL), NA ) @@ -23,7 +23,7 @@ test_that("ard_aov() works", { # see if it can handle multiple variables expect_snapshot( - ard_aov(AGE ~ ARM + SEX, data = cards::ADSL) |> + ard_stats_aov(AGE ~ ARM + SEX, data = cards::ADSL) |> as.data.frame() ) }) diff --git a/tests/testthat/test-ard_chisqtest.R b/tests/testthat/test-ard_stats_chisq_test.R similarity index 77% rename from tests/testthat/test-ard_chisqtest.R rename to tests/testthat/test-ard_stats_chisq_test.R index 67d594564..37b3ef879 100644 --- a/tests/testthat/test-ard_chisqtest.R +++ b/tests/testthat/test-ard_stats_chisq_test.R @@ -1,10 +1,10 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_chisqtest() works", { +test_that("ard_stats_chisq_test() works", { expect_error( ard_chisqtest <- cards::ADSL |> - ard_chisqtest(by = ARM, variables = AGEGR1), + ard_stats_chisq_test(by = ARM, variables = AGEGR1), NA ) @@ -23,10 +23,10 @@ test_that("ard_chisqtest() works", { dplyr::bind_rows( ard_chisqtest, cards::ADSL |> - ard_chisqtest(by = ARM, variables = BMIBLGR1) + ard_stats_chisq_test(by = ARM, variables = BMIBLGR1) ), cards::ADSL |> - ard_chisqtest(by = ARM, variables = c(AGEGR1, BMIBLGR1)) + ard_stats_chisq_test(by = ARM, variables = c(AGEGR1, BMIBLGR1)) ) }) @@ -35,12 +35,12 @@ test_that("shuffle_ard fills missing group levels if the group is meaningful", { expect_snapshot( cards::bind_ard( - ard_chisqtest( + ard_stats_chisq_test( data = adsl_sub, by = "ARM", variables = "AGEGR1" ), - ard_chisqtest( + ard_stats_chisq_test( data = adsl_sub, by = "SEX", variables = "AGEGR1" diff --git a/tests/testthat/test-ard_fishertest.R b/tests/testthat/test-ard_stats_fisher_test.R similarity index 71% rename from tests/testthat/test-ard_fishertest.R rename to tests/testthat/test-ard_stats_fisher_test.R index faf4ca8f2..92731eaf4 100644 --- a/tests/testthat/test-ard_fishertest.R +++ b/tests/testthat/test-ard_stats_fisher_test.R @@ -1,10 +1,10 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_fishertest() works", { +test_that("ard_stats_fisher_test() works", { expect_error( ard_fishertest <- cards::ADSL[1:20, ] |> - ard_fishertest(by = ARM, variables = AGEGR1), + ard_stats_fisher_test(by = ARM, variables = AGEGR1), NA ) @@ -23,9 +23,9 @@ test_that("ard_fishertest() works", { dplyr::bind_rows( ard_fishertest, cards::ADSL[1:20, ] |> - ard_fishertest(by = ARM, variables = BMIBLGR1) + ard_stats_fisher_test(by = ARM, variables = BMIBLGR1) ), cards::ADSL[1:20, ] |> - ard_fishertest(by = ARM, variables = c(AGEGR1, BMIBLGR1)) + ard_stats_fisher_test(by = ARM, variables = c(AGEGR1, BMIBLGR1)) ) }) diff --git a/tests/testthat/test-ard_kruskaltest.R b/tests/testthat/test-ard_stats_kruskal_test.R similarity index 70% rename from tests/testthat/test-ard_kruskaltest.R rename to tests/testthat/test-ard_stats_kruskal_test.R index 8afc7f3eb..cdf1f023d 100644 --- a/tests/testthat/test-ard_kruskaltest.R +++ b/tests/testthat/test-ard_stats_kruskal_test.R @@ -1,10 +1,10 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_kurskaltest() works", { +test_that("ard_stats_kruskal_test() works", { expect_error( ard_kruskaltest <- cards::ADSL |> - ard_kruskaltest(by = ARM, variables = AGE), + ard_stats_kruskal_test(by = ARM, variables = AGE), NA ) @@ -21,7 +21,7 @@ test_that("ard_kurskaltest() works", { # errors are properly handled expect_snapshot( cards::ADSL |> - ard_kruskaltest(by = "ARM", variables = "AGE") |> + ard_stats_kruskal_test(by = "ARM", variables = "AGE") |> as.data.frame() ) @@ -30,9 +30,9 @@ test_that("ard_kurskaltest() works", { dplyr::bind_rows( ard_kruskaltest, cards::ADSL |> - ard_kruskaltest(by = ARM, variable = BMIBL) + ard_stats_kruskal_test(by = ARM, variable = BMIBL) ), cards::ADSL |> - ard_kruskaltest(by = ARM, variable = c(AGE, BMIBL)) + ard_stats_kruskal_test(by = ARM, variable = c(AGE, BMIBL)) ) }) diff --git a/tests/testthat/test-ard_mcnemartest.R b/tests/testthat/test-ard_stats_mcnemar_test.R similarity index 70% rename from tests/testthat/test-ard_mcnemartest.R rename to tests/testthat/test-ard_stats_mcnemar_test.R index ae6f7efb1..8f757cab2 100644 --- a/tests/testthat/test-ard_mcnemartest.R +++ b/tests/testthat/test-ard_stats_mcnemar_test.R @@ -1,10 +1,10 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_mcnemartest() works", { +test_that("ard_stats_mcnemar_test() works", { expect_error( ard_mcnemartest <- cards::ADSL |> - ard_mcnemartest(by = SEX, variables = EFFFL), + ard_stats_mcnemar_test(by = SEX, variables = EFFFL), NA ) @@ -20,7 +20,7 @@ test_that("ard_mcnemartest() works", { # errors are properly handled expect_equal( cards::ADSL |> - ard_mcnemartest(by = ARM, variables = AGE, correct = FALSE) |> + ard_stats_mcnemar_test(by = ARM, variables = AGE, correct = FALSE) |> dplyr::pull(error) |> getElement(1L), "'x' and 'y' must have the same number of levels (minimum 2)" @@ -33,10 +33,10 @@ test_that("ard_mcnemartest() works", { expect_equal( cards::ADSL |> dplyr::rename(`Planned Tx` = TRT01P, `Age Group` = AGEGR1) |> - ard_mcnemartest(by = `Planned Tx`, variables = `Age Group`) |> + ard_stats_mcnemar_test(by = `Planned Tx`, variables = `Age Group`) |> cards::get_ard_statistics(), cards::ADSL |> - ard_mcnemartest(by = TRT01P, variables = AGEGR1) |> + ard_stats_mcnemar_test(by = TRT01P, variables = AGEGR1) |> cards::get_ard_statistics() ) @@ -45,9 +45,9 @@ test_that("ard_mcnemartest() works", { dplyr::bind_rows( ard_mcnemartest, cards::ADSL |> - ard_mcnemartest(by = SEX, variables = COMP16FL) + ard_stats_mcnemar_test(by = SEX, variables = COMP16FL) ), cards::ADSL |> - ard_mcnemartest(by = SEX, variables = c(EFFFL, COMP16FL)) + ard_stats_mcnemar_test(by = SEX, variables = c(EFFFL, COMP16FL)) ) }) diff --git a/tests/testthat/test-ard_moodtest.R b/tests/testthat/test-ard_stats_mood_test.R similarity index 69% rename from tests/testthat/test-ard_moodtest.R rename to tests/testthat/test-ard_stats_mood_test.R index 895c1692c..34f12a0c4 100644 --- a/tests/testthat/test-ard_moodtest.R +++ b/tests/testthat/test-ard_stats_mood_test.R @@ -1,10 +1,10 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_moodtest() works", { +test_that("ard_stats_mood_test() works", { expect_error( ard_moodtest <- cards::ADSL |> - ard_moodtest(by = SEX, variable = AGE), + ard_stats_mood_test(by = SEX, variable = AGE), NA ) @@ -21,7 +21,7 @@ test_that("ard_moodtest() works", { # errors are properly handled expect_snapshot( cards::ADSL |> - ard_moodtest(by = SEX, variable = AGE) |> + ard_stats_mood_test(by = SEX, variable = AGE) |> as.data.frame() ) @@ -29,9 +29,9 @@ test_that("ard_moodtest() works", { dplyr::bind_rows( ard_moodtest, cards::ADSL |> - ard_moodtest(by = SEX, variable = BMIBL) + ard_stats_mood_test(by = SEX, variable = BMIBL) ), cards::ADSL |> - ard_moodtest(by = SEX, variable = c(AGE, BMIBL)) + ard_stats_mood_test(by = SEX, variable = c(AGE, BMIBL)) ) }) diff --git a/tests/testthat/test-ard_onewaytest.R b/tests/testthat/test-ard_stats_oneway_test.R similarity index 78% rename from tests/testthat/test-ard_onewaytest.R rename to tests/testthat/test-ard_stats_oneway_test.R index eca5184e4..2182287bc 100644 --- a/tests/testthat/test-ard_onewaytest.R +++ b/tests/testthat/test-ard_stats_oneway_test.R @@ -1,8 +1,8 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_onewaytest() works", { +test_that("ard_stats_oneway_test() works", { expect_error( - ard_onewaytest <- ard_onewaytest(AGE ~ ARM, data = cards::ADSL), + ard_onewaytest <- ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL), NA ) @@ -22,7 +22,7 @@ test_that("ard_onewaytest() works", { # warnings are properly handled - "variable" should be continuous, not character # THE WARNING HERE IS VERY LONG, SO NOT CONVERTING TO data.frame TO KEEP THE CHECK EASY ON THE EYES expect_snapshot( - ard_onewaytest(AGEGR1 ~ ARM, data = cards::ADSL) |> + ard_stats_oneway_test(AGEGR1 ~ ARM, data = cards::ADSL) |> dplyr::select(c("stat_name", "stat", "warning")) |> head(3) ) diff --git a/tests/testthat/test-ard_proptest.R b/tests/testthat/test-ard_stats_prop_test.R similarity index 83% rename from tests/testthat/test-ard_proptest.R rename to tests/testthat/test-ard_stats_prop_test.R index 10f7e798f..7ef180624 100644 --- a/tests/testthat/test-ard_proptest.R +++ b/tests/testthat/test-ard_stats_prop_test.R @@ -1,10 +1,10 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_proptest() works", { +test_that("ard_stats_prop_test() works", { expect_error( ard_proptest <- mtcars |> - ard_proptest(by = vs, variables = am, conf.level = 0.90), + ard_stats_prop_test(by = vs, variables = am, conf.level = 0.90), NA ) @@ -31,19 +31,19 @@ test_that("ard_proptest() works", { dplyr::bind_rows( ard_proptest, mtcars |> - ard_proptest(by = vs, variables = gear, conf.level = 0.90) + ard_stats_prop_test(by = vs, variables = gear, conf.level = 0.90) ), mtcars |> - ard_proptest(by = vs, variables = c(am, gear), conf.level = 0.90) + ard_stats_prop_test(by = vs, variables = c(am, gear), conf.level = 0.90) ) }) -test_that("ard_proptest() error messaging", { +test_that("ard_stats_prop_test() error messaging", { # the AGE column is not binary and we should get an error captured expect_error( non_binary <- cards::ADSL |> - ard_proptest(by = ARM, variables = AGE) |> + ard_stats_prop_test(by = ARM, variables = AGE) |> as.data.frame(), NA ) @@ -66,7 +66,7 @@ test_that("ard_proptest() error messaging", { expect_error( too_many_levels <- mtcars |> - ard_proptest(by = cyl, variables = vs) |> + ard_stats_prop_test(by = cyl, variables = vs) |> as.data.frame(), NA ) diff --git a/tests/testthat/test-ard_ttest.R b/tests/testthat/test-ard_stats_t_test.R similarity index 80% rename from tests/testthat/test-ard_ttest.R rename to tests/testthat/test-ard_stats_t_test.R index 7d500e50e..600ec68d7 100644 --- a/tests/testthat/test-ard_ttest.R +++ b/tests/testthat/test-ard_stats_t_test.R @@ -1,9 +1,9 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_ttest() works", { +test_that("ard_stats_t_test() works", { # One Sample t-test works expect_error( - ard_single <- ard_ttest(cards::ADSL, variable = AGE, var.equal = TRUE), + ard_single <- ard_stats_t_test(cards::ADSL, variable = AGE, var.equal = TRUE), NA ) @@ -25,7 +25,7 @@ test_that("ard_ttest() works", { ard_ttest <- cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_ttest(by = ARM, variable = AGE, var.equal = TRUE), + ard_stats_t_test(by = ARM, variable = AGE, var.equal = TRUE), NA ) @@ -46,7 +46,7 @@ test_that("ard_ttest() works", { # errors are properly handled expect_snapshot( cards::ADSL |> - ard_ttest(by = ARM, variable = AGE, var.equal = TRUE) |> + ard_stats_t_test(by = ARM, variable = AGE, var.equal = TRUE) |> as.data.frame() ) @@ -56,15 +56,15 @@ test_that("ard_ttest() works", { ard_ttest, cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_ttest(by = ARM, variable = BMIBL, var.equal = TRUE) + ard_stats_t_test(by = ARM, variable = BMIBL, var.equal = TRUE) ), cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_ttest(by = ARM, variable = c(AGE, BMIBL), var.equal = TRUE) + ard_stats_t_test(by = ARM, variable = c(AGE, BMIBL), var.equal = TRUE) ) }) -test_that("ard_paired_ttest() works", { +test_that("ard_stats_paired_t_test() works", { ADSL_paired <- cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> @@ -73,7 +73,7 @@ test_that("ard_paired_ttest() works", { expect_error( ard_paired_ttest <- ADSL_paired |> - ard_paired_ttest(by = ARM, variable = AGE, id = USUBJID, var.equal = TRUE), + ard_stats_paired_t_test(by = ARM, variable = AGE, id = USUBJID, var.equal = TRUE), NA ) @@ -107,7 +107,7 @@ test_that("ard_paired_ttest() works", { dplyr::mutate( ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM) ) |> - ard_paired_ttest(by = ARM, variable = AGE, id = USUBJID, var.equal = TRUE) |> + ard_stats_paired_t_test(by = ARM, variable = AGE, id = USUBJID, var.equal = TRUE) |> as.data.frame() ) }) diff --git a/tests/testthat/test-ard_wilcoxtest.R b/tests/testthat/test-ard_stats_wilcox_test.R similarity index 83% rename from tests/testthat/test-ard_wilcoxtest.R rename to tests/testthat/test-ard_stats_wilcox_test.R index 0b25261d3..82c7a7837 100644 --- a/tests/testthat/test-ard_wilcoxtest.R +++ b/tests/testthat/test-ard_stats_wilcox_test.R @@ -1,9 +1,9 @@ skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) -test_that("ard_wilcoxtest() works", { +test_that("ard_stats_wilcox_test() works", { # One Sample Wilcox works expect_error( - ard_single <- ard_wilcoxtest(cards::ADSL, variable = AGE), + ard_single <- ard_stats_wilcox_test(cards::ADSL, variable = AGE), NA ) @@ -24,7 +24,7 @@ test_that("ard_wilcoxtest() works", { ard_wilcoxtest <- cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_wilcoxtest(by = ARM, variable = AGE, correct = FALSE, conf.int = TRUE), + ard_stats_wilcox_test(by = ARM, variable = AGE, correct = FALSE, conf.int = TRUE), NA ) @@ -46,7 +46,7 @@ test_that("ard_wilcoxtest() works", { # errors are properly handled expect_equal( cards::ADSL |> - ard_wilcoxtest(by = ARM, variable = AGE, correct = FALSE) |> + ard_stats_wilcox_test(by = ARM, variable = AGE, correct = FALSE) |> dplyr::pull(error) |> getElement(1L), "grouping factor must have exactly 2 levels" @@ -58,15 +58,15 @@ test_that("ard_wilcoxtest() works", { ard_wilcoxtest, cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_wilcoxtest(by = ARM, variable = BMIBL, correct = FALSE, conf.int = TRUE) + ard_stats_wilcox_test(by = ARM, variable = BMIBL, correct = FALSE, conf.int = TRUE) ), cards::ADSL |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> - ard_wilcoxtest(by = ARM, variable = c(AGE, BMIBL), correct = FALSE, conf.int = TRUE) + ard_stats_wilcox_test(by = ARM, variable = c(AGE, BMIBL), correct = FALSE, conf.int = TRUE) ) }) -test_that("ard_paired_wilcoxtest() works", { +test_that("ard_stats_paired_wilcox_test() works", { ADSL_paired <- cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> @@ -75,7 +75,7 @@ test_that("ard_paired_wilcoxtest() works", { expect_error( ard_paired_wilcoxtest <- ADSL_paired |> - ard_paired_wilcoxtest( + ard_stats_paired_wilcox_test( by = ARM, variable = AGE, id = USUBJID, correct = FALSE, conf.int = TRUE ), @@ -113,7 +113,7 @@ test_that("ard_paired_wilcoxtest() works", { dplyr::mutate( ARM = ifelse(dplyr::row_number() == 1L, "3rd ARM", ARM) ) |> - ard_paired_wilcoxtest( + ard_stats_paired_wilcox_test( by = ARM, variable = AGE, id = USUBJID, correct = FALSE, conf.int = TRUE ) |> diff --git a/tests/testthat/test-ard_svychisq.R b/tests/testthat/test-ard_survey_svychisq.R similarity index 81% rename from tests/testthat/test-ard_svychisq.R rename to tests/testthat/test-ard_survey_svychisq.R index be6f155cb..c94cfd865 100644 --- a/tests/testthat/test-ard_svychisq.R +++ b/tests/testthat/test-ard_survey_svychisq.R @@ -1,12 +1,12 @@ skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) -test_that("ard_svychisq() works", { +test_that("ard_survey_svychisq() works", { data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) expect_error( ard_svychisq <- - ard_svychisq( + ard_survey_svychisq( dclus2, variables = sch.wide, by = comp.imp, @@ -26,7 +26,7 @@ test_that("ard_svychisq() works", { # test that the function works with multiple variables expect_snapshot( - ard_svychisq( + ard_survey_svychisq( dclus2, variables = c(sch.wide, stype), by = comp.imp, @@ -43,9 +43,9 @@ test_that("ard_svychisq() works", { dplyr::bind_rows( ard_svychisq, dclus2 |> - ard_svychisq(by = comp.imp, variables = stype) + ard_survey_svychisq(by = comp.imp, variables = stype) ), dclus2 |> - ard_svychisq(by = comp.imp, variables = c(sch.wide, stype)) + ard_survey_svychisq(by = comp.imp, variables = c(sch.wide, stype)) ) }) diff --git a/tests/testthat/test-ard_svycontinuous.R b/tests/testthat/test-ard_survey_svycontinuous.R similarity index 93% rename from tests/testthat/test-ard_svycontinuous.R rename to tests/testthat/test-ard_survey_svycontinuous.R index c7ceb4268..dfcd27496 100644 --- a/tests/testthat/test-ard_svycontinuous.R +++ b/tests/testthat/test-ard_survey_svycontinuous.R @@ -1,12 +1,12 @@ skip_if_not(cards::is_pkg_installed("survey", reference_pkg = "cardx")) -test_that("unstratified ard_svycontinuous() works", { +test_that("unstratified ard_survey_svycontinuous() works", { data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) expect_error( ard_uni_svy_cont <- - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = api00, statistic = ~ c( @@ -71,13 +71,13 @@ test_that("unstratified ard_svycontinuous() works", { }) -test_that("stratified ard_svycontinuous() works", { +test_that("stratified ard_survey_svycontinuous() works", { data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) expect_error( ard_svy_cont <- - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, by = both, variables = api00, @@ -238,13 +238,13 @@ test_that("stratified ard_svycontinuous() works", { ) }) -test_that("ard_svycontinuous() NA handling", { +test_that("ard_survey_svycontinuous() NA handling", { data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1 |> dplyr::mutate(api00 = NA_real_), fpc = ~fpc) expect_error( ard_uni_NA_svy_cont <- - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = api00, statistic = ~ c( @@ -263,7 +263,7 @@ test_that("ard_svycontinuous() NA handling", { expect_error( ard_NA_svy_cont <- - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = api00, by = both, @@ -282,7 +282,7 @@ test_that("ard_svycontinuous() NA handling", { ) }) -test_that("ard_svycontinuous() error handling", { +test_that("ard_survey_svycontinuous() error handling", { data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1[1:20, ], fpc = ~fpc) @@ -290,7 +290,7 @@ test_that("ard_svycontinuous() error handling", { # and these "results" may vary across systems (all are nonsense), so just check # that code runs without error expect_error( - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = sname, statistic = ~ c( @@ -302,7 +302,7 @@ test_that("ard_svycontinuous() error handling", { ) expect_error( - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = sname, by = both, @@ -315,12 +315,12 @@ test_that("ard_svycontinuous() error handling", { ) }) -test_that("ard_svycontinuous(fmt_fn)", { +test_that("ard_survey_svycontinuous(fmt_fn)", { data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) expect_snapshot( - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = api00, statistic = ~ c("mean", "median", "min", "max"), @@ -329,12 +329,12 @@ test_that("ard_svycontinuous(fmt_fn)", { ) }) -test_that("ard_svycontinuous(stat_label)", { +test_that("ard_survey_svycontinuous(stat_label)", { data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) expect_snapshot( - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = api00, statistic = ~ c("mean", "median", "min", "max"), @@ -343,7 +343,7 @@ test_that("ard_svycontinuous(stat_label)", { ) }) -test_that("ard_svycontinuous(by) unobserved levels/combinations", { +test_that("ard_survey_svycontinuous(by) unobserved levels/combinations", { data(api, package = "survey") dclus1 <- survey::svydesign( id = ~dnum, weights = ~pw, @@ -359,7 +359,7 @@ test_that("ard_svycontinuous(by) unobserved levels/combinations", { # The 'Neither' level is never observed, but included in the table expect_setequal( levels(dclus1$variables$both), - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = api00, by = both, @@ -373,7 +373,7 @@ test_that("ard_svycontinuous(by) unobserved levels/combinations", { # stype="E" is not observed with awards="No", but it should still appear in table with(dclus1$variables, table(stype, awards)) expect_equal( - ard_svycontinuous( + ard_survey_svycontinuous( dclus1, variables = api00, by = c(stype, awards), diff --git a/tests/testthat/test-ard_svyranktest.R b/tests/testthat/test-ard_survey_svyranktest.R similarity index 91% rename from tests/testthat/test-ard_svyranktest.R rename to tests/testthat/test-ard_survey_svyranktest.R index 2da6be457..eb74b9b6f 100644 --- a/tests/testthat/test-ard_svyranktest.R +++ b/tests/testthat/test-ard_survey_svyranktest.R @@ -1,12 +1,12 @@ skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) -test_that("ard_svyranktest() works", { +test_that("ard_survey_svyranktest() works", { data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) svyranktest <- lapply( c("wilcoxon", "vanderWaerden", "median", "KruskalWallis"), function(x) { - ard_svyranktest( + ard_survey_svyranktest( dclus2, variable = enroll, by = comp.imp, @@ -24,7 +24,7 @@ test_that("ard_svyranktest() works", { test_that("exact values match for ard_svyranktest works", { data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) - svywilcox <- ard_svyranktest( + svywilcox <- ard_survey_svyranktest( dclus2, variable = enroll, by = comp.imp, diff --git a/tests/testthat/test-ard_svyttest.R b/tests/testthat/test-ard_survey_svyttest.R similarity index 88% rename from tests/testthat/test-ard_svyttest.R rename to tests/testthat/test-ard_survey_svyttest.R index bb36853a7..529b7561b 100644 --- a/tests/testthat/test-ard_svyttest.R +++ b/tests/testthat/test-ard_survey_svyttest.R @@ -1,12 +1,12 @@ skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) -test_that("ard_svyttest() works", { +test_that("ard_survey_svyttest() works", { data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) expect_error( ard_svyttest <- - ard_svyttest( + ard_survey_svyttest( dclus2, variable = enroll, by = comp.imp, @@ -39,14 +39,14 @@ test_that("ard_svyttest() works", { expect_equal( dplyr::bind_rows( ard_svyttest, - ard_svyttest( + ard_survey_svyttest( dclus2, variable = mobility, by = comp.imp, conf.level = 0.9 ) ), - ard_svyttest( + ard_survey_svyttest( dclus2, variable = c(enroll, mobility), by = comp.imp, @@ -55,13 +55,13 @@ test_that("ard_svyttest() works", { ) }) -test_that("ard_svyttest() messaging", { +test_that("ard_survey_svyttest() messaging", { data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) expect_error( ard_svyttest <- - ard_svyttest( + ard_survey_svyttest( dclus2, variable = enroll, by = stype diff --git a/tests/testthat/test-ard_survfit.R b/tests/testthat/test-ard_survival_survfit.R similarity index 71% rename from tests/testthat/test-ard_survfit.R rename to tests/testthat/test-ard_survival_survfit.R index 80681fab5..70301e62f 100644 --- a/tests/testthat/test-ard_survfit.R +++ b/tests/testthat/test-ard_survival_survfit.R @@ -1,9 +1,9 @@ skip_if_not(cards::is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx")) -test_that("ard_survfit() works with times provided", { +test_that("ard_survival_survfit() works with times provided", { expect_snapshot( survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> - ard_survfit(times = c(60, 180)) |> + ard_survival_survfit(times = c(60, 180)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) |> @@ -11,10 +11,10 @@ test_that("ard_survfit() works with times provided", { ) }) -test_that("ard_survfit() works with different type", { +test_that("ard_survival_survfit() works with different type", { expect_snapshot( survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> - ard_survfit(times = c(60, 180), type = "risk") |> + ard_survival_survfit(times = c(60, 180), type = "risk") |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) |> @@ -22,10 +22,10 @@ test_that("ard_survfit() works with different type", { ) }) -test_that("ard_survfit() works with probs provided", { +test_that("ard_survival_survfit() works with probs provided", { expect_snapshot( survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> - ard_survfit(probs = c(0.25, 0.75)) |> + ard_survival_survfit(probs = c(0.25, 0.75)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) |> @@ -33,10 +33,10 @@ test_that("ard_survfit() works with probs provided", { ) }) -test_that("ard_survfit() works with unstratified model", { +test_that("ard_survival_survfit() works with unstratified model", { expect_snapshot( survival::survfit(survival::Surv(time, status) ~ 1, data = survival::lung) |> - ard_survfit(times = c(60, 180)) |> + ard_survival_survfit(times = c(60, 180)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) |> @@ -45,7 +45,7 @@ test_that("ard_survfit() works with unstratified model", { expect_snapshot( survival::survfit(survival::Surv(time, status) ~ 1, data = survival::lung) |> - ard_survfit(probs = c(0.5, 0.75)) |> + ard_survival_survfit(probs = c(0.5, 0.75)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) |> @@ -53,10 +53,10 @@ test_that("ard_survfit() works with unstratified model", { ) }) -test_that("ard_survfit() works with multiple stratification variables", { +test_that("ard_survival_survfit() works with multiple stratification variables", { expect_snapshot( survival::survfit(survival::Surv(time, status) ~ sex + ph.ecog, data = survival::lung) |> - ard_survfit(times = c(60, 180)) |> + ard_survival_survfit(times = c(60, 180)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) |> @@ -67,7 +67,7 @@ test_that("ard_survfit() works with multiple stratification variables", { expect_snapshot( survival::survfit(survival::Surv(time, status) ~ sex + ph.ecog, data = survival::lung) |> - ard_survfit(probs = c(0.5, 0.75)) |> + ard_survival_survfit(probs = c(0.5, 0.75)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) |> @@ -77,7 +77,7 @@ test_that("ard_survfit() works with multiple stratification variables", { ) }) -test_that("ard_survfit() works with competing risks", { +test_that("ard_survival_survfit() works with competing risks", { set.seed(1) ADTTE_MS <- cards::ADTTE %>% dplyr::mutate( @@ -90,7 +90,7 @@ test_that("ard_survfit() works with competing risks", { expect_snapshot( survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, data = ADTTE_MS) %>% - ard_survfit(times = c(60, 180)) |> + ard_survival_survfit(times = c(60, 180)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) |> @@ -98,46 +98,46 @@ test_that("ard_survfit() works with competing risks", { ) }) -test_that("ard_survfit() errors are properly handled", { +test_that("ard_survival_survfit() errors are properly handled", { expect_snapshot( - ard_survfit("not_survfit"), + ard_survival_survfit("not_survfit"), error = TRUE ) expect_snapshot( survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> - ard_survfit(times = 100, type = "notatype"), + ard_survival_survfit(times = 100, type = "notatype"), error = TRUE ) expect_snapshot( survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> - ard_survfit(times = 100, probs = c(0.25, 0.75)), + ard_survival_survfit(times = 100, probs = c(0.25, 0.75)), error = TRUE ) }) -test_that("ard_survfit() works with non-syntactic names", { +test_that("ard_survival_survfit() works with non-syntactic names", { expect_equal( survival::survfit(survival::Surv(time, status) ~ factor(sex) + `ph.ecog`, data = survival::lung) |> - ard_survfit(times = c(60, 180)) |> + ard_survival_survfit(times = c(60, 180)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ), survival::survfit(survival::Surv(time, status) ~ sex + ph.ecog, data = survival::lung) |> - ard_survfit(times = c(60, 180)) |> + ard_survival_survfit(times = c(60, 180)) |> dplyr::mutate( stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) ) ) }) -test_that("ard_survfit() errors with stratified Cox model", { +test_that("ard_survival_survfit() errors with stratified Cox model", { withr::local_namespace("survival") expect_snapshot( error = TRUE, coxph(Surv(time, status) ~ age + strata(sex), survival::lung) |> survfit() |> - ard_survfit() + ard_survival_survfit() ) }) From 8fa77abc1cc2e4a17cfaf05a58dbaf9b325c8dff Mon Sep 17 00:00:00 2001 From: ddsjoberg Date: Fri, 12 Apr 2024 04:07:50 +0000 Subject: [PATCH 02/14] [skip actions] Bump version to 0.1.0.9012 --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 234621afc..0e0e19492 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: cardx Title: Extra Analysis Results Data Utilities -Version: 0.1.0.9011 +Version: 0.1.0.9012 Authors@R: c( person("Daniel", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre")), person("Abinaya", "Yogasekaram", , "abinaya.yogasekaram@contractors.roche.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index e4ddc6445..a51353f86 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# cardx 0.1.0.9011 +# cardx 0.1.0.9012 ### Breaking Changes From ed6a26ce851649b8b082df42dc677d68ef795140 Mon Sep 17 00:00:00 2001 From: Abinaya Yogasekaram <73252787+ayogasekaram@users.noreply.github.com> Date: Sun, 14 Apr 2024 18:26:33 -0400 Subject: [PATCH 03/14] add `ard_aod_wald_test` function (#99) **What changes are proposed in this pull request?** add `ard_aod_wald_test` function closes #84 -------------------------------------------------------------------------------- Pre-review Checklist (if item does not apply, mark is as complete) - [x] **All** GitHub Action workflows pass with a :white_check_mark: - [x] PR branch has pulled the most recent updates from master branch: `usethis::pr_merge_main()` - [x] If a bug was fixed, a unit test was added. - [x] If a new `ard_*()` function was added, it passes the ARD structural checks from `cards::check_ard_structure()`. - [x] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()` - [x] Request a reviewer Reviewer Checklist (if item does not apply, mark is as complete) - [x] If a bug was fixed, a unit test was added. - [x] Run `pkgdown::build_site()`. Check the R console for errors, and review the rendered website. - [x] Code coverage is suitable for any new functions/features: `devtools::test_coverage()` When the branch is ready to be merged: - [x] Update `NEWS.md` with the changes from this pull request under the heading "`# cards (development version)`". If there is an issue associated with the pull request, reference it in parentheses at the end update (see `NEWS.md` for examples). - [x] **All** GitHub Action workflows pass with a :white_check_mark: - [x] Approve Pull Request - [x] Merge the PR. Please use "Squash and merge" or "Rebase and merge". --------- Signed-off-by: Daniel Sjoberg Signed-off-by: Abinaya Yogasekaram <73252787+ayogasekaram@users.noreply.github.com> Co-authored-by: Daniel Sjoberg --- DESCRIPTION | 1 + NAMESPACE | 1 + NEWS.md | 5 +- R/ard_aod_wald_test.R | 115 +++++++++++++++++++++ _pkgdown.yml | 1 + man/ard_aod_wald_test.Rd | 26 +++++ man/dot-extract_wald_results.Rd | 18 ++++ tests/testthat/_snaps/ard_aod_wald_test.md | 15 +++ tests/testthat/test-ard_aod_wald_test.R | 18 ++++ 9 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 R/ard_aod_wald_test.R create mode 100644 man/ard_aod_wald_test.Rd create mode 100644 man/dot-extract_wald_results.Rd create mode 100644 tests/testthat/_snaps/ard_aod_wald_test.md create mode 100644 tests/testthat/test-ard_aod_wald_test.R diff --git a/DESCRIPTION b/DESCRIPTION index 0e0e19492..fecb86314 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,7 @@ Imports: rlang (>= 1.1.1), tidyr (>= 1.3.0) Suggests: + aod (>= 1.3.3), broom (>= 1.0.5), broom.helpers (>= 1.13.0), car (>= 3.0-11), diff --git a/NAMESPACE b/NAMESPACE index 401c17a57..bac2a3508 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ S3method(ard_regression,default) export("%>%") export(all_of) export(any_of) +export(ard_aod_wald_test) export(ard_car_anova) export(ard_car_vif) export(ard_effectsize_cohens_d) diff --git a/NEWS.md b/NEWS.md index a51353f86..646f8bbbd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ ### Breaking Changes -* Updated function names have been updated to follow the pattern `ard__()`. Former functions names have _not_ been deprecated. (#106) +* Updated function names to follow the pattern `ard__()`. Former functions names have _not_ been deprecated. (#106) ```r ard_ttest() -> ard_stats_t_test() @@ -19,7 +19,8 @@ ard_moodtest() -> ard_stats_mood_test() ### New Features * Added the following functions for calculating Analysis Results Data (ARD). - - `ard_aov()` for calculating ANOVA results using `stats::aov()`. (#3) + - `ard_stats_aov()` for calculating ANOVA results using `stats::aov()`. (#3) + - `ard_aod_wald_test()` for calculating Wald Tests for regression models using `aod::wald.test()`. (#3) - `ard_car_anova()` for calculating ANOVA results using `car::Anova()`. (#3) - `ard_onewaytest()` for calculating ANOVA results using `stats::oneway.test()`. (#3) - `ard_cohens_d()`, `ard_paired_cohens_d()`, `ard_hedges_g()`, and `ard_paired_hedges_g()` for standardized differences using `effectsize::cohens_d()` and `effectsize::hedges_g()`. (#50) diff --git a/R/ard_aod_wald_test.R b/R/ard_aod_wald_test.R new file mode 100644 index 000000000..b575e11b1 --- /dev/null +++ b/R/ard_aod_wald_test.R @@ -0,0 +1,115 @@ +#' ARD Wald Test +#' +#' @description +#' Function takes a regression model object and calculates Wald +#' statistical test using [`aod::wald.test()`]. +#' +#' @param x regression model object +#' @param ... arguments passed to `aod::wald.test(...)` +#' +#' @return data frame +#' @export +#' +#' @examplesIf cards::is_pkg_installed(c("aod"), reference_pkg = "cardx") +#' lm(AGE ~ ARM, data = cards::ADSL) |> +#' ard_aod_wald_test() +ard_aod_wald_test <- function(x, ...) { + # check installed packages --------------------------------------------------- + cards::check_pkg_installed("aod", reference_pkg = "cardx") + + # check inputs --------------------------------------------------------------- + check_not_missing(x) + + # run regression() ----------------------------------------------------------- + reg_model <- cards::eval_capture_conditions( + ard_regression_basic(x, intercept = TRUE, stats_to_remove = c( + "var_type", + "var_label", + "var_class", "label", + "contrasts_type", "contrasts", "var_nlevels", "std.error", + "conf.low", "conf.high", "statistic", "p.value", "estimate" + )) + ) + + if (!is.null(reg_model[["error"]])) { + cli::cli_abort(c( + "Unable to identify underlying variable names in regression model.", + i = "Is this model type supported by {.fun broom.helpers::tidy_plus_plus}, which is the function used to identify variable names?" + )) + } + aod <- + reg_model[["result"]] %>% + dplyr::select(c( + variable = "variable", + model_terms = "stat" + )) %>% + dplyr::mutate(term_id = dplyr::row_number()) %>% + tidyr::nest(data = -"variable") %>% + dplyr::rowwise() %>% + dplyr::mutate( + model_terms = unlist(.data$data[["model_terms"]]) %>% list(), + model_terms_id = rlang::set_names(.data$data[["term_id"]]) %>% list() + ) + # run wald.test() ----------------------------------------------------------- + wald_test <- + cards::eval_capture_conditions(lapply(seq_len(length(aod$model_terms_id)), function(terms_id) { + aod::wald.test( + Sigma = stats::vcov(x), + b = stats::coef(x), Terms = aod$model_terms_id[[terms_id]] + ) + })) + + + df_list <- do.call(rbind, lapply(wald_test$result, .extract_wald_results)) + + cbind(aod$variable, df_list) %>% + tidyr::pivot_longer( + cols = !"aod$variable", + names_to = "stat_name", + values_to = "stat" + ) %>% + dplyr::rename( + "variable" = "aod$variable" + ) |> + dplyr::mutate( + stat = as.list(.data$stat), + stat_label = + dplyr::case_when( + .data$stat_name %in% "statistic" ~ "Statistic", + .data$stat_name %in% "df" ~ "Degrees of Freedom", + .data$stat_name %in% "p.value" ~ "p-value", + TRUE ~ .data$stat_name + ), + fmt_fn = + map( + .data$stat, + function(.x) { + # styler: off + if (is.integer(.x)) return(0L) + if (is.numeric(.x)) return(1L) + # styler: on + NULL + } + ), + context = "aod_wald_test", + warning = wald_test["warning"], + error = wald_test["error"] + ) |> + cards::tidy_ard_column_order() %>% + {structure(., class = c("card", class(.)))} # styler: off +} + +#' Extract data from wald.test object +#' +#' +#' @param wald_test (`data.frame`)\cr wald test object object from `aod::wald.test()` +#' +#' @return a data frame containing the wald test results. +#' @keywords internal + +.extract_wald_results <- function(wald_test) { + df <- wald_test$result$chi2[("df")] + statistic <- wald_test$result$chi2[("chi2")] + p.value <- wald_test$result$chi2[("P")] + data.frame(df, statistic, p.value) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index 928367043..aa0f8415d 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -24,6 +24,7 @@ reference: - title: "ARD Creation" - subtitle: "Inference" - contents: + - ard_aod_wald_test - ard_car_anova - ard_stats_aov - ard_stats_chisq_test diff --git a/man/ard_aod_wald_test.Rd b/man/ard_aod_wald_test.Rd new file mode 100644 index 000000000..1ebc3b0f5 --- /dev/null +++ b/man/ard_aod_wald_test.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ard_aod_wald_test.R +\name{ard_aod_wald_test} +\alias{ard_aod_wald_test} +\title{ARD Wald Test} +\usage{ +ard_aod_wald_test(x, ...) +} +\arguments{ +\item{x}{regression model object} + +\item{...}{arguments passed to \code{aod::wald.test(...)}} +} +\value{ +data frame +} +\description{ +Function takes a regression model object and calculates Wald +statistical test using \code{\link[aod:wald.test]{aod::wald.test()}}. +} +\examples{ +\dontshow{if (cards::is_pkg_installed(c("aod"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +lm(AGE ~ ARM, data = cards::ADSL) |> + ard_aod_wald_test() +\dontshow{\}) # examplesIf} +} diff --git a/man/dot-extract_wald_results.Rd b/man/dot-extract_wald_results.Rd new file mode 100644 index 000000000..24b23eb78 --- /dev/null +++ b/man/dot-extract_wald_results.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ard_aod_wald_test.R +\name{.extract_wald_results} +\alias{.extract_wald_results} +\title{Extract data from wald.test object} +\usage{ +.extract_wald_results(wald_test) +} +\arguments{ +\item{wald_test}{(\code{data.frame})\cr wald test object object from \code{aod::wald.test()}} +} +\value{ +a data frame containing the wald test results. +} +\description{ +Extract data from wald.test object +} +\keyword{internal} diff --git a/tests/testthat/_snaps/ard_aod_wald_test.md b/tests/testthat/_snaps/ard_aod_wald_test.md new file mode 100644 index 000000000..6ebe17ca3 --- /dev/null +++ b/tests/testthat/_snaps/ard_aod_wald_test.md @@ -0,0 +1,15 @@ +# ard_aod_wald_test() works + + Code + glm_ard_aod_waldtest[, 1:6] + Message + {cards} data frame: 6 x 6 + Output + variable context stat_name stat_label stat fmt_fn + 1 (Intercept) aod_wald… df Degrees … 1 1 + 2 (Intercept) aod_wald… statistic Statistic 7126.713 1 + 3 (Intercept) aod_wald… p.value p-value 0 1 + 4 ARM aod_wald… df Degrees … 2 1 + 5 ARM aod_wald… statistic Statistic 1.046 1 + 6 ARM aod_wald… p.value p-value 0.593 1 + diff --git a/tests/testthat/test-ard_aod_wald_test.R b/tests/testthat/test-ard_aod_wald_test.R new file mode 100644 index 000000000..3f149b76f --- /dev/null +++ b/tests/testthat/test-ard_aod_wald_test.R @@ -0,0 +1,18 @@ +test_that("ard_aod_wald_test() works", { + # works for a generic case + expect_error( + glm_ard_aod_waldtest <- + suppressWarnings(lm(AGE ~ ARM, data = cards::ADSL)) |> + ard_aod_wald_test(), + NA + ) + expect_equal(nrow(glm_ard_aod_waldtest), 6L) + expect_snapshot(glm_ard_aod_waldtest[, 1:6]) + + # error returned when a regression model isn't passed + + expect_error( + ard_aod_wald_test(cards::ADSL) |> + dplyr::select(c(context, error)) + ) +}) From 452faa69b86d3c881470a242aab1f573adda9f6e Mon Sep 17 00:00:00 2001 From: ddsjoberg Date: Sun, 14 Apr 2024 22:27:25 +0000 Subject: [PATCH 04/14] [skip actions] Bump version to 0.1.0.9013 --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fecb86314..0e09fdf1d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: cardx Title: Extra Analysis Results Data Utilities -Version: 0.1.0.9012 +Version: 0.1.0.9013 Authors@R: c( person("Daniel", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre")), person("Abinaya", "Yogasekaram", , "abinaya.yogasekaram@contractors.roche.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 646f8bbbd..3f905daf5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# cardx 0.1.0.9012 +# cardx 0.1.0.9013 ### Breaking Changes From d01c6a078e56f5cea46fcc640c10060168c9bcf3 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 15:49:27 -0700 Subject: [PATCH 05/14] Adding `ard_stats_anova()` (#107) **What changes are proposed in this pull request?** - `ard_stats_anova()` for calculating ANOVA results using `stats::anova()`. (#12) There are two implementations of this function via S3 methods. 1. The first is when a user calculates the `anova()` object and passes it to `ard_stats_anova()`. 2. The second is when a user passes a data frame. We use that data frame and information from the other arguments to construct the models and pass the models to `anova()` **Reference GitHub issue associated with pull request.** _e.g., 'closes #'_ closes #12 -------------------------------------------------------------------------------- Pre-review Checklist (if item does not apply, mark is as complete) - [ ] **All** GitHub Action workflows pass with a :white_check_mark: - [ ] PR branch has pulled the most recent updates from master branch: `usethis::pr_merge_main()` - [ ] If a bug was fixed, a unit test was added. - [ ] If a new `ard_*()` function was added, it passes the ARD structural checks from `cards::check_ard_structure()`. - [ ] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()` - [ ] Request a reviewer Reviewer Checklist (if item does not apply, mark is as complete) - [x] If a bug was fixed, a unit test was added. - [x] Run `pkgdown::build_site()`. Check the R console for errors, and review the rendered website. - [x] Code coverage is suitable for any new functions/features: `devtools::test_coverage()` When the branch is ready to be merged: - [ ] Update `NEWS.md` with the changes from this pull request under the heading "`# cards (development version)`". If there is an issue associated with the pull request, reference it in parentheses at the end update (see `NEWS.md` for examples). - [ ] **All** GitHub Action workflows pass with a :white_check_mark: - [ ] Approve Pull Request - [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge". --------- Signed-off-by: Daniel Sjoberg Co-authored-by: Emily de la Rua <59304861+edelarua@users.noreply.github.com> --- DESCRIPTION | 4 +- NAMESPACE | 4 + NEWS.md | 3 +- R/ard_stats_anova.R | 217 ++++++++++++++++++++++++++ R/cardx-package.R | 1 + _pkgdown.yml | 1 + inst/WORDLIST | 2 + man/ard_stats_anova.Rd | 98 ++++++++++++ tests/testthat/test-ard_stats_anova.R | 131 ++++++++++++++++ 9 files changed, 459 insertions(+), 2 deletions(-) create mode 100644 R/ard_stats_anova.R create mode 100644 man/ard_stats_anova.Rd create mode 100644 tests/testthat/test-ard_stats_anova.R diff --git a/DESCRIPTION b/DESCRIPTION index 0e09fdf1d..5869c031e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,13 +30,15 @@ Suggests: broom.helpers (>= 1.13.0), car (>= 3.0-11), effectsize (>= 0.6.0), + geepack (>= 1.3.2), + lme4 (>= 1.1-31), parameters (>= 0.20.2), smd (>= 0.6.6), spelling, survey (>= 4.1), survival (>= 3.2-11), testthat (>= 3.2.0), - withr + withr (>= 2.5.0) Remotes: insightsengineering/cards Config/Needs/website: insightsengineering/nesttemplate diff --git a/NAMESPACE b/NAMESPACE index bac2a3508..880fe1b6f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,8 @@ # Generated by roxygen2: do not edit by hand S3method(ard_regression,default) +S3method(ard_stats_anova,anova) +S3method(ard_stats_anova,data.frame) export("%>%") export(all_of) export(any_of) @@ -15,6 +17,7 @@ export(ard_proportion_ci) export(ard_regression) export(ard_regression_basic) export(ard_smd_smd) +export(ard_stats_anova) export(ard_stats_aov) export(ard_stats_chisq_test) export(ard_stats_fisher_test) @@ -49,6 +52,7 @@ export(starts_with) export(where) import(rlang) importFrom(dplyr,"%>%") +importFrom(dplyr,across) importFrom(dplyr,all_of) importFrom(dplyr,any_of) importFrom(dplyr,contains) diff --git a/NEWS.md b/NEWS.md index 3f905daf5..355900c5e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,7 +20,8 @@ ard_moodtest() -> ard_stats_mood_test() * Added the following functions for calculating Analysis Results Data (ARD). - `ard_stats_aov()` for calculating ANOVA results using `stats::aov()`. (#3) - - `ard_aod_wald_test()` for calculating Wald Tests for regression models using `aod::wald.test()`. (#3) + - `ard_stats_anova()` for calculating ANOVA results using `stats::anova()`. (#12) + - `ard_aod_wald_test()` for calculating Wald Tests for regression models using `aod::wald.test()`. (#84) - `ard_car_anova()` for calculating ANOVA results using `car::Anova()`. (#3) - `ard_onewaytest()` for calculating ANOVA results using `stats::oneway.test()`. (#3) - `ard_cohens_d()`, `ard_paired_cohens_d()`, `ard_hedges_g()`, and `ard_paired_hedges_g()` for standardized differences using `effectsize::cohens_d()` and `effectsize::hedges_g()`. (#50) diff --git a/R/ard_stats_anova.R b/R/ard_stats_anova.R new file mode 100644 index 000000000..16059560b --- /dev/null +++ b/R/ard_stats_anova.R @@ -0,0 +1,217 @@ +#' ARD ANOVA +#' +#' Prepare ANOVA results from the `stats::anova()` function. +#' Users may pass a pre-calculated `stats::anova()` object or a list of +#' formulas. In the latter case, the models will be constructed using the +#' information passed and models will be passed to `stats::anova()`. +#' +#' @param x (`anova` or `data.frame`)\cr +#' an object of class `'anova'` created with `stats::anova()` or +#' a data frame +#' @param formulas (`list`)\cr +#' a list of formulas +#' @param fn (`string`)\cr +#' string naming the function to be called, e.g. `"glm"`. +#' If function belongs to a library that is not attached, the package name +#' must be specified in the `package` argument. +#' @param fn.args (named `list`)\cr +#' named list of arguments that will be passed to `fn`. +#' @param package (`string`)\cr +#' string of package name that will be temporarily loaded when function +#' specified in `method` is executed. +#' @param method (`string`)\cr +#' string of the method used. Default is `"ANOVA results from `stats::anova()`"`. +#' We provide the option to change this as `stats::anova()` can produce +#' results from many types of models that may warrant a more precise +#' description. +#' @inheritParams rlang::args_dots_empty +#' +#' @details +#' When a list of formulas is supplied to `ard_stats_anova()`, these formulas +#' along with information from other arguments, are used to construct models +#' and pass those models to `stats::anova()`. +#' +#' The models are constructed using `rlang::exec()`, which is similar to `do.call()`. +#' +#' ```r +#' rlang::exec(.fn = fn, formula = formula, data = data, !!!fn.args) +#' ``` +#' +#' The above function is executed in `withr::with_namespace(package)`, which +#' allows for the use of `ard_stats_anova(fn)` from packages, +#' e.g. `package = 'lme4'` must be specified when `fn = 'glmer'`. +#' See example below. +#' +#' @return ARD data frame +#' @name ard_stats_anova +#' +#' @examplesIf cards::is_pkg_installed(c("broom", "withr", "lme4"), reference_pkg = "cardx") +#' anova( +#' lm(mpg ~ am, mtcars), +#' lm(mpg ~ am + hp, mtcars) +#' ) |> +#' ard_stats_anova() +#' +#' ard_stats_anova( +#' x = mtcars, +#' formulas = list(am ~ mpg, am ~ mpg + hp), +#' fn = "glm", +#' fn.args = list(family = binomial) +#' ) +#' +#' ard_stats_anova( +#' x = mtcars, +#' formulas = list(am ~ 1 + (1 | vs), am ~ mpg + (1 | vs)), +#' fn = "glmer", +#' fn.args = list(family = binomial), +#' package = "lme4" +#' ) +NULL + +#' @rdname ard_stats_anova +#' @export +ard_stats_anova <- function(x, ...) { + UseMethod("ard_stats_anova") +} + +#' @rdname ard_stats_anova +#' @export +ard_stats_anova.anova <- function(x, method = "ANOVA results from `stats::anova()`", ...) { + # check inputs --------------------------------------------------------------- + check_dots_empty() + cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_string(method, message = "Argument {.arg method} must be a string of a function name.") + + # return df in cards formats ------------------------------------------------- + lst_results <- + cards::eval_capture_conditions( + .anova_tidy_and_reshape(x, method = method) + ) + + # final tidying up of cards data frame --------------------------------------- + .anova_final_ard_prep(lst_results, method = method) +} + + +#' @rdname ard_stats_anova +#' @export +ard_stats_anova.data.frame <- function(x, + formulas, + fn, + fn.args = list(), + package = "base", + method = "ANOVA results from `stats::anova()`", + ...) { + # check inputs --------------------------------------------------------------- + check_dots_empty() + check_string(package) + cards::check_pkg_installed(c("broom", "withr", package), reference_pkg = "cardx") + check_not_missing(formulas) + check_not_missing(x) + check_not_missing(fn) + check_string(method, message = "Argument {.arg method} must be a string of a function name.") + check_data_frame(x) + check_string(fn) + if (str_detect(fn, "::")) { + cli::cli_abort(c( + "Argument {.arg fn} cannot be namespaced.", + i = "Put the package name in the {.arg package} argument." + )) + } + + # calculate results and return df in cards formats --------------------------- + # process fn.args argument + fn.args <- rlang::call_args(rlang::enexpr(fn.args)) + + # create models + lst_results <- + cards::eval_capture_conditions({ + # first build the models + models <- + lapply( + formulas, + function(formula) { + withr::with_namespace( + package = package, + call2(.fn = fn, formula = formula, data = x, !!!fn.args) |> + eval_tidy() + ) + } + ) + + # now calculate `stats::anova()` and reshape results + rlang::inject(stats::anova(!!!models)) |> + .anova_tidy_and_reshape(method = method) + }) + + # final tidying up of cards data frame --------------------------------------- + .anova_final_ard_prep(lst_results, method = method) +} + +.anova_tidy_and_reshape <- function(x, method) { + broom::tidy(x) |> + dplyr::mutate( + across(everything(), as.list), + variable = paste0("model_", dplyr::row_number()) + ) |> + tidyr::pivot_longer( + cols = -"variable", + names_to = "stat_name", + values_to = "stat" + ) |> + dplyr::filter(!is.na(.data$stat)) %>% + # add one more row with the method + { + dplyr::bind_rows( + ., + dplyr::filter(., dplyr::n() == dplyr::row_number()) |> + dplyr::mutate( + stat_name = "method", + stat = list(.env$method) + ) + ) + } +} + +.anova_final_ard_prep <- function(lst_results, method) { + # saving the results in data frame ------------------------------------------- + df_card <- + if (!is.null(lst_results[["result"]])) { + lst_results[["result"]] + } else { # if there was an error return a shell of an ARD data frame + dplyr::tibble( + variable = "model_1", + stat_name = c("p.value", "method"), + stat = list(NULL, method) + ) + } + + # final tidying up of cards data frame --------------------------------------- + df_card |> + dplyr::mutate( + warning = lst_results["warning"], + error = lst_results["error"], + context = "stats_anova", + fmt_fn = lapply( + .data$stat, + function(x) { + switch(is.integer(x), + 0L + ) %||% switch(is.numeric(x), + 1L + ) + } + ), + stat_label = + dplyr::case_when( + .data$stat_name %in% "p.value" ~ "p-value", + .data$stat_name %in% "sumsq" ~ "Sum of Squares", + .data$stat_name %in% "rss" ~ "Residual Sum of Squares", + .data$stat_name %in% "df" ~ "Degrees of Freedom", + .data$stat_name %in% "df.residual" ~ "df for residuals", + .default = .data$stat_name + ) + ) |> + cards::tidy_ard_column_order() %>% + {structure(., class = c("card", class(.)))} # styler: off +} diff --git a/R/cardx-package.R b/R/cardx-package.R index df5d79a4b..9a843b1bf 100644 --- a/R/cardx-package.R +++ b/R/cardx-package.R @@ -1,5 +1,6 @@ #' @keywords internal #' @import rlang +#' @importFrom dplyr across "_PACKAGE" ## usethis namespace: start diff --git a/_pkgdown.yml b/_pkgdown.yml index aa0f8415d..0a9b92c05 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -26,6 +26,7 @@ reference: - contents: - ard_aod_wald_test - ard_car_anova + - ard_stats_anova - ard_stats_aov - ard_stats_chisq_test - ard_stats_fisher_test diff --git a/inst/WORDLIST b/inst/WORDLIST index a703d5cda..820556d85 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -17,6 +17,7 @@ VIF XG Xin agresti +anova clopper coull de @@ -24,6 +25,7 @@ deff funder jeffreys pearson +pre sd strat vif diff --git a/man/ard_stats_anova.Rd b/man/ard_stats_anova.Rd new file mode 100644 index 000000000..e3c058051 --- /dev/null +++ b/man/ard_stats_anova.Rd @@ -0,0 +1,98 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ard_stats_anova.R +\name{ard_stats_anova} +\alias{ard_stats_anova} +\alias{ard_stats_anova.anova} +\alias{ard_stats_anova.data.frame} +\title{ARD ANOVA} +\usage{ +ard_stats_anova(x, ...) + +\method{ard_stats_anova}{anova}(x, method = "ANOVA results from `stats::anova()`", ...) + +\method{ard_stats_anova}{data.frame}( + x, + formulas, + fn, + fn.args = list(), + package = "base", + method = "ANOVA results from `stats::anova()`", + ... +) +} +\arguments{ +\item{x}{(\code{anova} or \code{data.frame})\cr +an object of class \code{'anova'} created with \code{stats::anova()} or +a data frame} + +\item{...}{These dots are for future extensions and must be empty.} + +\item{method}{(\code{string})\cr +string of the method used. Default is \verb{"ANOVA results from }stats::anova()\verb{"}. +We provide the option to change this as \code{stats::anova()} can produce +results from many types of models that may warrant a more precise +description.} + +\item{formulas}{(\code{list})\cr +a list of formulas} + +\item{fn}{(\code{string})\cr +string naming the function to be called, e.g. \code{"glm"}. +If function belongs to a library that is not attached, the package name +must be specified in the \code{package} argument.} + +\item{fn.args}{(named \code{list})\cr +named list of arguments that will be passed to \code{fn}.} + +\item{package}{(\code{string})\cr +string of package name that will be temporarily loaded when function +specified in \code{method} is executed.} +} +\value{ +ARD data frame +} +\description{ +Prepare ANOVA results from the \code{stats::anova()} function. +Users may pass a pre-calculated \code{stats::anova()} object or a list of +formulas. In the latter case, the models will be constructed using the +information passed and models will be passed to \code{stats::anova()}. +} +\details{ +When a list of formulas is supplied to \code{ard_stats_anova()}, these formulas +along with information from other arguments, are used to construct models +and pass those models to \code{stats::anova()}. + +The models are constructed using \code{rlang::exec()}, which is similar to \code{do.call()}. + +\if{html}{\out{
}}\preformatted{rlang::exec(.fn = fn, formula = formula, data = data, !!!fn.args) +}\if{html}{\out{
}} + +The above function is executed in \code{withr::with_namespace(package)}, which +allows for the use of \code{ard_stats_anova(fn)} from packages, +e.g. \code{package = 'lme4'} must be specified when \code{fn = 'glmer'}. +See example below. +} +\examples{ +\dontshow{if (cards::is_pkg_installed(c("broom", "withr", "lme4"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +anova( + lm(mpg ~ am, mtcars), + lm(mpg ~ am + hp, mtcars) +) |> + ard_stats_anova() + +ard_stats_anova( + x = mtcars, + formulas = list(am ~ mpg, am ~ mpg + hp), + fn = "glm", + fn.args = list(family = binomial) +) + +ard_stats_anova( + x = mtcars, + formulas = list(am ~ 1 + (1 | vs), am ~ mpg + (1 | vs)), + fn = "glmer", + fn.args = list(family = binomial), + package = "lme4" +) +\dontshow{\}) # examplesIf} +} diff --git a/tests/testthat/test-ard_stats_anova.R b/tests/testthat/test-ard_stats_anova.R new file mode 100644 index 000000000..1982d7b3f --- /dev/null +++ b/tests/testthat/test-ard_stats_anova.R @@ -0,0 +1,131 @@ +skip_if_not(cards::is_pkg_installed(c("broom", "withr", "lme4", "survival"), reference_pkg = "cardx")) + +test_that("ard_stats_anova.anova() works", { + expect_equal( + anova( + lm(mpg ~ am, mtcars), + lm(mpg ~ am + hp, mtcars) + ) |> + ard_stats_anova() |> + dplyr::select(variable, stat_name, stat) |> + dplyr::filter(!stat_name %in% "method"), + anova( + lm(mpg ~ am, mtcars), + lm(mpg ~ am + hp, mtcars) + ) |> + broom::tidy() |> + dplyr::mutate( + across(everything(), as.list), + variable = paste0("model_", dplyr::row_number()) + ) |> + tidyr::pivot_longer( + cols = -variable, + names_to = "stat_name", + values_to = "stat" + ) |> + dplyr::filter(!is.na(stat)), + ignore_attr = TRUE + ) +}) + +test_that("ard_stats_anova.data.frame() works", { + expect_equal( + anova( + lm(mpg ~ am, mtcars), + lm(mpg ~ am + hp, mtcars) + ) |> + ard_stats_anova(), + ard_stats_anova( + x = mtcars, + formulas = list(mpg ~ am, mpg ~ am + hp), + fn = "lm" + ) + ) + + # function works with a non-standard evaluation argument + expect_error( + ard_anova_geeglm <- + ard_stats_anova( + x = mtcars, + formulas = list(mpg ~ hp, mpg ~ hp + vs), + fn = "geeglm", + fn.args = list(id = cyl), + package = "geepack" + ), + NA + ) + expect_equal( + ard_anova_geeglm |> + dplyr::filter(stat_name == "p.value") |> + dplyr::pull(stat) |> + unlist(), + suppressWarnings( + anova( + geepack::geeglm(mpg ~ hp, data = mtcars, id = cyl), + geepack::geeglm(mpg ~ hp + vs, data = mtcars, id = cyl) + ) |> + broom::tidy() |> + dplyr::pull(p.value) + ) + ) + + # function works with a non-base R package + expect_error( + ard_anova_glmer <- + ard_stats_anova( + x = mtcars, + formulas = list(am ~ 1 + (1 | vs), am ~ mpg + (1 | vs)), + fn = "glmer", + fn.args = list(family = binomial), + package = "lme4" + ), + NA + ) + expect_equal( + ard_anova_glmer |> + dplyr::filter(stat_name == "p.value") |> + dplyr::pull(stat) |> + unlist(), + suppressMessages( + anova( + lme4::glmer(am ~ 1 + (1 | vs), data = mtcars, family = binomial), + lme4::glmer(am ~ mpg + (1 | vs), data = mtcars, family = binomial) + ) + ) |> + broom::tidy() |> + dplyr::pull(p.value) |> + keep(~ !is.na(.)) + ) + + # adding a testing with more complex env handling + args_fun <- function(args) { + ard_stats_anova( + x = mtcars, + formulas = list(am ~ 1 + (1 | vs), am ~ mpg + (1 | vs)), + fn = "glmer", + fn.args = {{ args }}, + package = "lme4" + ) + } + ard_anova_glmer2 <- args_fun(list(family = binomial)) + expect_equal( + ard_anova_glmer2, + ard_anova_glmer + ) + + # adding a testing with more complex env handling with NSE + args_fun <- function(args) { + ard_stats_anova( + x = mtcars, + formulas = list(mpg ~ hp, mpg ~ hp + vs), + fn = "geeglm", + fn.args = {{ args }}, + package = "geepack" + ) + } + ard_anova_geeglm2 <- args_fun(list(id = cyl)) + expect_equal( + ard_anova_geeglm2, + ard_anova_geeglm + ) +}) From c633acb06ba84db032154d29b84cd60b4112edb9 Mon Sep 17 00:00:00 2001 From: ddsjoberg Date: Sun, 14 Apr 2024 22:50:17 +0000 Subject: [PATCH 06/14] [skip actions] Bump version to 0.1.0.9014 --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5869c031e..acddf62c4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: cardx Title: Extra Analysis Results Data Utilities -Version: 0.1.0.9013 +Version: 0.1.0.9014 Authors@R: c( person("Daniel", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre")), person("Abinaya", "Yogasekaram", , "abinaya.yogasekaram@contractors.roche.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 355900c5e..1293440df 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# cardx 0.1.0.9013 +# cardx 0.1.0.9014 ### Breaking Changes From b1ff0bff5c451cd8f1b87686dc9ddf3acf4d7426 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 17:14:36 -0700 Subject: [PATCH 07/14] resolving merge conflicts --- R/ard_aod_wald_test.R | 5 +- R/ard_car_vif.R | 4 +- R/ard_effectsize_cohens_d.R | 14 +-- R/ard_effectsize_hedges_g.R | 15 ++-- R/ard_smd_smd.R | 10 ++- R/ard_stats_anova.R | 2 + R/ard_stats_aov.R | 6 +- R/ard_stats_chisq_test.R | 6 +- R/ard_stats_fisher_test.R | 6 +- R/ard_stats_kruskal_test.R | 6 +- R/ard_stats_mcnemar_test.R | 8 +- R/ard_stats_mood_test.R | 8 +- R/ard_stats_oneway_test.R | 6 +- R/ard_stats_prop_test.R | 8 +- R/ard_stats_t_test.R | 12 ++- R/ard_stats_wilcox_test.R | 10 ++- R/ard_survey_svychisq.R | 6 +- R/ard_survey_svycontinuous.R | 19 ++-- R/ard_survey_svyranktest.R | 6 +- R/ard_survey_svyttest.R | 6 +- R/ard_survival_survfit.R | 14 +-- man/ard_aod_wald_test.Rd | 2 +- man/ard_car_vif.Rd | 2 + man/ard_effectsize_cohens_d.Rd | 4 +- man/ard_effectsize_hedges_g.Rd | 6 +- man/ard_smd_smd.Rd | 2 +- man/ard_stats_aov.Rd | 2 +- man/ard_stats_chisq_test.Rd | 2 +- man/ard_stats_fisher_test.Rd | 2 +- man/ard_stats_kruskal_test.Rd | 2 +- man/ard_stats_mcnemar_test.Rd | 4 +- man/ard_stats_mood_test.Rd | 4 +- man/ard_stats_oneway_test.Rd | 2 +- man/ard_stats_prop_test.Rd | 2 +- man/ard_stats_t_test.Rd | 2 +- man/ard_stats_wilcox_test.Rd | 2 +- man/ard_survey_svychisq.Rd | 2 +- man/ard_survey_svycontinuous.Rd | 2 +- man/ard_survey_svyranktest.Rd | 2 +- man/ard_survey_svyttest.Rd | 2 +- man/ard_survival_survfit.Rd | 2 +- .../_snaps/{ard_vif.md => ard_car_vif.md} | 13 ++- tests/testthat/_snaps/ard_stats_chisq_test.md | 17 ++++ ...ard_moodtest.md => ard_stats_mood_test.md} | 4 +- ...onewaytest.md => ard_stats_oneway_test.md} | 4 +- ...ard_svychisq.md => ard_survey_svychisq.md} | 8 +- ...yranktest.md => ard_survey_svyranktest.md} | 2 +- ...ard_survfit.md => ard_survival_survfit.md} | 87 ++++++++++--------- tests/testthat/_snaps/ard_svycontinuous.md | 54 ------------ tests/testthat/_snaps/ard_ttest.md | 73 ---------------- tests/testthat/test-ard_aod_wald_test.R | 2 + tests/testthat/test-ard_car_vif.R | 2 + tests/testthat/test-ard_effectsize_cohens_d.R | 2 +- tests/testthat/test-ard_effectsize_hedges_g.R | 2 +- tests/testthat/test-ard_smd_smd.R | 4 +- tests/testthat/test-ard_stats_anova.R | 2 +- tests/testthat/test-ard_stats_aov.R | 2 +- tests/testthat/test-ard_stats_chisq_test.R | 2 +- tests/testthat/test-ard_stats_fisher_test.R | 2 +- tests/testthat/test-ard_stats_kruskal_test.R | 2 +- tests/testthat/test-ard_stats_mcnemar_test.R | 2 +- tests/testthat/test-ard_stats_mood_test.R | 2 +- tests/testthat/test-ard_stats_oneway_test.R | 2 +- tests/testthat/test-ard_stats_prop_test.R | 2 +- tests/testthat/test-ard_stats_t_test.R | 2 +- tests/testthat/test-ard_stats_wilcox_test.R | 2 +- tests/testthat/test-ard_survey_svychisq.R | 2 +- .../testthat/test-ard_survey_svycontinuous.R | 2 +- tests/testthat/test-ard_survey_svyranktest.R | 2 +- tests/testthat/test-ard_survey_svyttest.R | 2 +- tests/testthat/test-ard_survival_survfit.R | 2 +- 71 files changed, 240 insertions(+), 293 deletions(-) rename tests/testthat/_snaps/{ard_vif.md => ard_car_vif.md} (77%) create mode 100644 tests/testthat/_snaps/ard_stats_chisq_test.md rename tests/testthat/_snaps/{ard_moodtest.md => ard_stats_mood_test.md} (85%) rename tests/testthat/_snaps/{ard_onewaytest.md => ard_stats_oneway_test.md} (68%) rename tests/testthat/_snaps/{ard_svychisq.md => ard_survey_svychisq.md} (76%) rename tests/testthat/_snaps/{ard_svyranktest.md => ard_survey_svyranktest.md} (98%) rename tests/testthat/_snaps/{ard_survfit.md => ard_survival_survfit.md} (79%) delete mode 100644 tests/testthat/_snaps/ard_svycontinuous.md delete mode 100644 tests/testthat/_snaps/ard_ttest.md diff --git a/R/ard_aod_wald_test.R b/R/ard_aod_wald_test.R index b575e11b1..e28f4b7e4 100644 --- a/R/ard_aod_wald_test.R +++ b/R/ard_aod_wald_test.R @@ -10,12 +10,13 @@ #' @return data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("aod"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "aod", reference_pkg = "cardx")) #' lm(AGE ~ ARM, data = cards::ADSL) |> #' ard_aod_wald_test() ard_aod_wald_test <- function(x, ...) { + set_cli_abort_call() # check installed packages --------------------------------------------------- - cards::check_pkg_installed("aod", reference_pkg = "cardx") + check_pkg_installed("aod", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(x) diff --git a/R/ard_car_vif.R b/R/ard_car_vif.R index 66212247e..d1428d7ee 100644 --- a/R/ard_car_vif.R +++ b/R/ard_car_vif.R @@ -14,10 +14,12 @@ #' @rdname ard_car_vif #' @export #' -#' @examples +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "car", reference_pkg = "cardx")) #' lm(AGE ~ ARM + SEX, data = cards::ADSL) |> #' ard_car_vif() ard_car_vif <- function(x, ...) { + set_cli_abort_call() + check_pkg_installed("car", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(x) diff --git a/R/ard_effectsize_cohens_d.R b/R/ard_effectsize_cohens_d.R index ba6b45fd8..99ddd5b29 100644 --- a/R/ard_effectsize_cohens_d.R +++ b/R/ard_effectsize_cohens_d.R @@ -22,13 +22,13 @@ #' For the `ard_effectsize_cohens_d()` function, the data is expected to be one row per subject. #' The data is passed as `effectsize::cohens_d(data[[variable]]~data[[by]], data, paired = FALSE, ...)`. #' -#' For the `ard_effectsize_paired_cohens_d()` function, the data is expected to be one row +#' For the `ard_paired_cohens_d()` function, the data is expected to be one row #' per subject per by level. Before the effect size is calculated, the data are #' reshaped to a wide format to be one row per subject. #' The data are then passed as #' `effectsize::cohens_d(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)`. #' -#' @examplesIf cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters"), reference_pkg = "cardx")) #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' ard_effectsize_cohens_d(by = ARM, variables = AGE) @@ -47,8 +47,10 @@ NULL #' @rdname ard_effectsize_cohens_d #' @export ard_effectsize_cohens_d <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") + check_pkg_installed(pkg = c("effectsize", "parameters"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -88,9 +90,11 @@ ard_effectsize_cohens_d <- function(data, by, variables, ...) { #' @rdname ard_effectsize_cohens_d #' @export ard_effectsize_paired_cohens_d <- function(data, by, variables, id, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("effectsize", reference_pkg = "cardx") - cards::check_pkg_installed("parameters", reference_pkg = "cardx") + check_pkg_installed(pkg = c("effectsize", "parameters"), reference_pkg = "cardx") + # check/process inputs ------------------------------------------------------- check_not_missing(data) check_not_missing(variables) diff --git a/R/ard_effectsize_hedges_g.R b/R/ard_effectsize_hedges_g.R index 4a4cd1bc0..7d514dc08 100644 --- a/R/ard_effectsize_hedges_g.R +++ b/R/ard_effectsize_hedges_g.R @@ -19,16 +19,16 @@ #' @name ard_effectsize_hedges_g #' #' @details -#' For the `ard_effectsize_hedges_g()` function, the data is expected to be one row per subject. +#' For the `ard_hedges_g()` function, the data is expected to be one row per subject. #' The data is passed as `effectsize::hedges_g(data[[variable]]~data[[by]], data, paired = FALSE, ...)`. #' -#' For the `ard_effectsize_paired_hedges_g()` function, the data is expected to be one row +#' For the `ard_paired_hedges_g()` function, the data is expected to be one row #' per subject per by level. Before the effect size is calculated, the data are #' reshaped to a wide format to be one row per subject. #' The data are then passed as #' `effectsize::hedges_g(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)`. #' -#' @examplesIf cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' ard_effectsize_hedges_g(by = ARM, variables = AGE) @@ -47,8 +47,10 @@ NULL #' @rdname ard_effectsize_hedges_g #' @export ard_effectsize_hedges_g <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx") + check_pkg_installed(pkg = c("effectsize", "parameters", "withr"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -92,9 +94,10 @@ ard_effectsize_hedges_g <- function(data, by, variables, ...) { #' @rdname ard_effectsize_hedges_g #' @export ard_effectsize_paired_hedges_g <- function(data, by, variables, id, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("effectsize", reference_pkg = "cardx") - cards::check_pkg_installed("parameters", reference_pkg = "cardx") + check_pkg_installed(pkg = c("effectsize", "parameters", "withr"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_smd_smd.R b/R/ard_smd_smd.R index cb6c4ec8c..d41e380cb 100644 --- a/R/ard_smd_smd.R +++ b/R/ard_smd_smd.R @@ -16,12 +16,14 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("smd", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "smd", reference_pkg = "cardx")) #' ard_smd_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE) #' ard_smd_smd(cards::ADSL, by = ARM, variables = AGEGR1, std.error = TRUE) ard_smd_smd <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("smd", reference_pkg = "cardx") + check_pkg_installed(pkg = "smd", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -56,8 +58,8 @@ ard_smd_smd <- function(data, by, variables, ...) { lst_tidy = cards::eval_capture_conditions( switch(as.character(is_survey), - "TRUE" = smd::smd(x = data[[variable]], g = data[[by]], w = stats::weights(design), na.rm = TRUE, ...), - "FALSE" = smd::smd(x = data[[variable]], g = data[[by]], na.rm = TRUE, ...) + "TRUE" = smd::smd(x = data[[variable]], g = data[[by]], w = stats::weights(design), na.rm = TRUE, ...), + "FALSE" = smd::smd(x = data[[variable]], g = data[[by]], na.rm = TRUE, ...) ) |> dplyr::select(-any_of("term")) ), diff --git a/R/ard_stats_anova.R b/R/ard_stats_anova.R index 16059560b..b1a8a5880 100644 --- a/R/ard_stats_anova.R +++ b/R/ard_stats_anova.R @@ -77,6 +77,7 @@ ard_stats_anova <- function(x, ...) { #' @rdname ard_stats_anova #' @export ard_stats_anova.anova <- function(x, method = "ANOVA results from `stats::anova()`", ...) { + set_cli_abort_call() # check inputs --------------------------------------------------------------- check_dots_empty() cards::check_pkg_installed("broom", reference_pkg = "cardx") @@ -102,6 +103,7 @@ ard_stats_anova.data.frame <- function(x, package = "base", method = "ANOVA results from `stats::anova()`", ...) { + set_cli_abort_call() # check inputs --------------------------------------------------------------- check_dots_empty() check_string(package) diff --git a/R/ard_stats_aov.R b/R/ard_stats_aov.R index 3abdd4759..33f0fd116 100644 --- a/R/ard_stats_aov.R +++ b/R/ard_stats_aov.R @@ -10,11 +10,13 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("broom.helpers"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx")) #' ard_stats_aov(AGE ~ ARM, data = cards::ADSL) ard_stats_aov <- function(formula, data, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("broom.helpers"), reference_pkg = "cardx") + check_pkg_installed(pkg = "broom.helpers", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(formula) diff --git a/R/ard_stats_chisq_test.R b/R/ard_stats_chisq_test.R index 9f76c3118..7af671f8d 100644 --- a/R/ard_stats_chisq_test.R +++ b/R/ard_stats_chisq_test.R @@ -17,12 +17,14 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' ard_stats_chisq_test(by = "ARM", variables = "AGEGR1") ard_stats_chisq_test <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_fisher_test.R b/R/ard_stats_fisher_test.R index a48773c37..a7490f684 100644 --- a/R/ard_stats_fisher_test.R +++ b/R/ard_stats_fisher_test.R @@ -17,12 +17,14 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @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, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_kruskal_test.R b/R/ard_stats_kruskal_test.R index 876d5af00..7f28d21d5 100644 --- a/R/ard_stats_kruskal_test.R +++ b/R/ard_stats_kruskal_test.R @@ -16,12 +16,14 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' ard_stats_kruskal_test(by = "ARM", variables = "AGE") ard_stats_kruskal_test <- function(data, by, variables) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_mcnemar_test.R b/R/ard_stats_mcnemar_test.R index da932885c..41374425d 100644 --- a/R/ard_stats_mcnemar_test.R +++ b/R/ard_stats_mcnemar_test.R @@ -16,16 +16,18 @@ #' @export #' #' @details -#' For the `ard_stats_mcnemar_test()` function, the data is expected to be one row per subject. +#' 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. #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") ard_stats_mcnemar_test <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_mood_test.R b/R/ard_stats_mood_test.R index ad0bb5c8a..d88fc4a92 100644 --- a/R/ard_stats_mood_test.R +++ b/R/ard_stats_mood_test.R @@ -17,17 +17,19 @@ #' @name ard_stats_mood_test #' #' @details -#' For the `ard_stats_mood_test()` function, the data is expected to be one row per subject. +#' 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_stats_mood_test #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' ard_stats_mood_test(by = "SEX", variables = "AGE") ard_stats_mood_test <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_oneway_test.R b/R/ard_stats_oneway_test.R index f2182b4ab..b40589fac 100644 --- a/R/ard_stats_oneway_test.R +++ b/R/ard_stats_oneway_test.R @@ -10,11 +10,13 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) ard_stats_oneway_test <- function(formula, data, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("broom"), reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(formula) diff --git a/R/ard_stats_prop_test.R b/R/ard_stats_prop_test.R index 6ef4a8b4d..a08081903 100644 --- a/R/ard_stats_prop_test.R +++ b/R/ard_stats_prop_test.R @@ -15,11 +15,15 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @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, ...) { - cards::check_pkg_installed("broom", reference_pkg = "cardx") + set_cli_abort_call() + + # check installed packages --------------------------------------------------- + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") + # check inputs --------------------------------------------------------------- check_not_missing(data) check_not_missing(variables) diff --git a/R/ard_stats_t_test.R b/R/ard_stats_t_test.R index 2e1f9214e..f1768b6d6 100644 --- a/R/ard_stats_t_test.R +++ b/R/ard_stats_t_test.R @@ -27,7 +27,7 @@ #' The data are then passed as #' `t.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)`. #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) @@ -44,8 +44,10 @@ NULL #' @rdname ard_stats_t_test #' @export ard_stats_t_test <- function(data, variables, by = NULL, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -85,8 +87,10 @@ 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, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -159,7 +163,7 @@ ard_stats_paired_t_test <- function(data, by, variables, id, ...) { "p.value", "parameter", "conf.low", "conf.high", "method", "alternative" ) |> - # add estimate1 and estimate2 if there is a by variable + # add estimate1 and estimate2 if there is a by variable append(values = switch(!is_empty(by), c("estimate1", "estimate2")), after = 1L), # styler: off fun_args_to_record = c("mu", "paired", "var.equal", "conf.level"), formals = formals(asNamespace("stats")[["t.test.default"]]), diff --git a/R/ard_stats_wilcox_test.R b/R/ard_stats_wilcox_test.R index 7e31f6822..67c39fd46 100644 --- a/R/ard_stats_wilcox_test.R +++ b/R/ard_stats_wilcox_test.R @@ -27,7 +27,7 @@ #' The data are then passed as #' `wilcox.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)`. #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' ard_stats_wilcox_test(by = "ARM", variables = "AGE") @@ -44,8 +44,10 @@ NULL #' @rdname ard_stats_wilcox_test #' @export ard_stats_wilcox_test <- function(data, variables, by = NULL, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -91,8 +93,10 @@ 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, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_survey_svychisq.R b/R/ard_survey_svychisq.R index 2ae37c743..17d5c65a0 100644 --- a/R/ard_survey_svychisq.R +++ b/R/ard_survey_svychisq.R @@ -20,14 +20,16 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx")) #' data(api, package = "survey") #' dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) #' #' ard_survey_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F") ard_survey_svychisq <- function(data, by, variables, statistic = "F", ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") + check_pkg_installed(pkg = c("survey", "broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_survey_svycontinuous.R b/R/ard_survey_svycontinuous.R index 392eabdbe..ddf1b0027 100644 --- a/R/ard_survey_svycontinuous.R +++ b/R/ard_survey_svycontinuous.R @@ -34,7 +34,7 @@ #' @return an ARD data frame of class 'card' #' @export #' -#' @examplesIf cards::is_pkg_installed("survey", reference_pkg = "cardx") +#' @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) #' @@ -44,10 +44,13 @@ #' by = stype #' ) ard_survey_svycontinuous <- function(data, variables, by = NULL, - statistic = everything() ~ c("median", "p25", "p75"), - fmt_fn = NULL, - stat_label = NULL) { - cards::check_pkg_installed("survey", reference_pkg = "cardx") + statistic = everything() ~ c("median", "p25", "p75"), + fmt_fn = NULL, + stat_label = NULL) { + set_cli_abort_call() + + # check installed packages --------------------------------------------------- + check_pkg_installed(pkg = "survey", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(data) @@ -71,7 +74,7 @@ ard_survey_svycontinuous <- function(data, variables, by = NULL, x = statistic, predicate = \(x) all(x %in% accepted_svy_stats()), error_msg = c("Error in the values of the {.arg statistic} argument.", - i = "Values must be in {.val {accepted_svy_stats(FALSE)}}" + i = "Values must be in {.val {accepted_svy_stats(FALSE)}}" ) ) @@ -107,8 +110,8 @@ ard_survey_svycontinuous <- function(data, variables, by = NULL, variable = names(stat_label), stat_name = map(.data$variable, ~ names(stat_label[[.x]])), stat_label = map(.data$variable, ~ stat_label[[.x]] |> - unname() |> - unlist()) + unname() |> + unlist()) ) |> tidyr::unnest(cols = c("stat_name", "stat_label")), by = "stat_name", diff --git a/R/ard_survey_svyranktest.R b/R/ard_survey_svyranktest.R index 3d7fa3c4f..45d7b18bd 100644 --- a/R/ard_survey_svyranktest.R +++ b/R/ard_survey_svyranktest.R @@ -17,7 +17,7 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx")) #' data(api, package = "survey") #' dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) #' @@ -26,8 +26,10 @@ #' ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") #' ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis") ard_survey_svyranktest <- function(data, by, variables, test, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") + check_pkg_installed(pkg = c("survey", "broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_survey_svyttest.R b/R/ard_survey_svyttest.R index d3f01c95b..3c45acd7d 100644 --- a/R/ard_survey_svyttest.R +++ b/R/ard_survey_svyttest.R @@ -17,14 +17,16 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx")) #' data(api, package = "survey") #' dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) #' #' ard_survey_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9) ard_survey_svyttest <- function(data, by, variables, conf.level = 0.95, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") + check_pkg_installed(pkg = c("survey", "broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_survival_survfit.R b/R/ard_survival_survfit.R index 5dcd7ca55..ff541589f 100644 --- a/R/ard_survival_survfit.R +++ b/R/ard_survival_survfit.R @@ -32,7 +32,7 @@ #' * Times should be provided using the same scale as the time variable used to fit the provided #' survival fit model. #' -#' @examplesIf cards::is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "broom"), reference_pkg = "cardx")) #' library(survival) #' #' survfit(Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> @@ -59,8 +59,10 @@ NULL #' @rdname ard_survival_survfit #' @export ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("survival", "broom"), reference_pkg = "cardx") + check_pkg_installed(pkg = c("survival", "broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(x) @@ -91,8 +93,8 @@ ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { # build ARD ------------------------------------------------------------------ est_type <- ifelse(is.null(probs), "times", "probs") tidy_survfit <- switch(est_type, - "times" = .process_survfit_time(x, times, type %||% "survival"), - "probs" = .process_survfit_probs(x, probs) + "times" = .process_survfit_time(x, times, type %||% "survival"), + "probs" = .process_survfit_probs(x, probs) ) .format_survfit_results(tidy_survfit) @@ -312,9 +314,9 @@ extract_multi_strata <- function(x, df_stat) { .data$stat, function(x) { switch(is.integer(x), - 0L + 0L ) %||% switch(is.numeric(x), - 1L + 1L ) } ), diff --git a/man/ard_aod_wald_test.Rd b/man/ard_aod_wald_test.Rd index 1ebc3b0f5..2469ac1ba 100644 --- a/man/ard_aod_wald_test.Rd +++ b/man/ard_aod_wald_test.Rd @@ -19,7 +19,7 @@ Function takes a regression model object and calculates Wald statistical test using \code{\link[aod:wald.test]{aod::wald.test()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("aod"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "aod", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} lm(AGE ~ ARM, data = cards::ADSL) |> ard_aod_wald_test() \dontshow{\}) # examplesIf} diff --git a/man/ard_car_vif.Rd b/man/ard_car_vif.Rd index 0ddbfa572..994a3863e 100644 --- a/man/ard_car_vif.Rd +++ b/man/ard_car_vif.Rd @@ -20,6 +20,8 @@ Function takes a regression model object and returns the variance inflation fact using \code{\link[car:vif]{car::vif()}} and converts it to a ARD structure } \examples{ +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "car", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} lm(AGE ~ ARM + SEX, data = cards::ADSL) |> ard_car_vif() +\dontshow{\}) # examplesIf} } diff --git a/man/ard_effectsize_cohens_d.Rd b/man/ard_effectsize_cohens_d.Rd index a0d1f5a20..7f27382c6 100644 --- a/man/ard_effectsize_cohens_d.Rd +++ b/man/ard_effectsize_cohens_d.Rd @@ -36,14 +36,14 @@ using \code{\link[effectsize:cohens_d]{effectsize::cohens_d()}}. For the \code{ard_effectsize_cohens_d()} function, the data is expected to be one row per subject. The data is passed as \code{effectsize::cohens_d(data[[variable]]~data[[by]], data, paired = FALSE, ...)}. -For the \code{ard_effectsize_paired_cohens_d()} function, the data is expected to be one row +For the \code{ard_paired_cohens_d()} function, the data is expected to be one row per subject per by level. Before the effect size is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as \verb{effectsize::cohens_d(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> ard_effectsize_cohens_d(by = ARM, variables = AGE) diff --git a/man/ard_effectsize_hedges_g.Rd b/man/ard_effectsize_hedges_g.Rd index e726614f1..d07fb1eca 100644 --- a/man/ard_effectsize_hedges_g.Rd +++ b/man/ard_effectsize_hedges_g.Rd @@ -33,17 +33,17 @@ Analysis results data for paired and non-paired Hedge's G Effect Size Test using \code{\link[effectsize:cohens_d]{effectsize::hedges_g()}}. } \details{ -For the \code{ard_effectsize_hedges_g()} function, the data is expected to be one row per subject. +For the \code{ard_hedges_g()} function, the data is expected to be one row per subject. The data is passed as \code{effectsize::hedges_g(data[[variable]]~data[[by]], data, paired = FALSE, ...)}. -For the \code{ard_effectsize_paired_hedges_g()} function, the data is expected to be one row +For the \code{ard_paired_hedges_g()} function, the data is expected to be one row per subject per by level. Before the effect size is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as \verb{effectsize::hedges_g(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters", "withr"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> ard_effectsize_hedges_g(by = ARM, variables = AGE) diff --git a/man/ard_smd_smd.Rd b/man/ard_smd_smd.Rd index 385cb01ed..27ffee4e4 100644 --- a/man/ard_smd_smd.Rd +++ b/man/ard_smd_smd.Rd @@ -34,7 +34,7 @@ ARD data frame Standardized mean difference calculated via \code{\link[smd:smd]{smd::smd()}} with \code{na.rm = TRUE}. } \examples{ -\dontshow{if (cards::is_pkg_installed("smd", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "smd", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ard_smd_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE) ard_smd_smd(cards::ADSL, by = ARM, variables = AGEGR1, std.error = TRUE) \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_aov.Rd b/man/ard_stats_aov.Rd index 3731f0ccd..c38d1a37e 100644 --- a/man/ard_stats_aov.Rd +++ b/man/ard_stats_aov.Rd @@ -23,7 +23,7 @@ Analysis results data for Analysis of Variance. Calculated with \code{stats::aov()} } \examples{ -\dontshow{if (cards::is_pkg_installed(c("broom.helpers"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ard_stats_aov(AGE ~ ARM, data = cards::ADSL) \dontshow{\}) # examplesIf} } diff --git a/man/ard_stats_chisq_test.Rd b/man/ard_stats_chisq_test.Rd index c820e8056..5dc96cb67 100644 --- a/man/ard_stats_chisq_test.Rd +++ b/man/ard_stats_chisq_test.Rd @@ -27,7 +27,7 @@ Analysis results data for Pearson's Chi-squared Test. Calculated with \code{chisq.test(x = data[[variable]], y = data[[by]], ...)} } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> ard_stats_chisq_test(by = "ARM", variables = "AGEGR1") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_fisher_test.Rd b/man/ard_stats_fisher_test.Rd index 5ba78bbc8..1e07809b0 100644 --- a/man/ard_stats_fisher_test.Rd +++ b/man/ard_stats_fisher_test.Rd @@ -27,7 +27,7 @@ Analysis results data for Fisher's Exact Test. Calculated with \code{fisher.test(x = data[[variable]], y = data[[by]], ...)} } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL[1:30, ] |> ard_stats_fisher_test(by = "ARM", variables = "AGEGR1") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_kruskal_test.Rd b/man/ard_stats_kruskal_test.Rd index 59e4bde5c..e9f4596cb 100644 --- a/man/ard_stats_kruskal_test.Rd +++ b/man/ard_stats_kruskal_test.Rd @@ -26,7 +26,7 @@ Analysis results data for Kruskal-Wallis Rank Sum Test. Calculated with \code{kruskal.test(data[[variable]], data[[by]], ...)} } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> ard_stats_kruskal_test(by = "ARM", variables = "AGE") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_mcnemar_test.Rd b/man/ard_stats_mcnemar_test.Rd index 3b47a0498..90db48ebb 100644 --- a/man/ard_stats_mcnemar_test.Rd +++ b/man/ard_stats_mcnemar_test.Rd @@ -26,12 +26,12 @@ ARD data frame Analysis results data for McNemar's statistical test. } \details{ -For the \code{ard_stats_mcnemar_test()} function, the data is expected to be one row per subject. +For the \code{ard_mcnemartest()} function, the data is expected to be one row per subject. The data is passed as \code{stats::mcnemar.test(x = data[[variable]], y = data[[by]], ...)}. Please use \code{table(x = data[[variable]], y = data[[by]])} to check the contingency table. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_mood_test.Rd b/man/ard_stats_mood_test.Rd index 902b54c0f..e551de898 100644 --- a/man/ard_stats_mood_test.Rd +++ b/man/ard_stats_mood_test.Rd @@ -27,11 +27,11 @@ Analysis results data for Mood two sample test of scale. Note this not to be con the Brown-Mood test of medians. } \details{ -For the \code{ard_stats_mood_test()} function, the data is expected to be one row per subject. +For the \code{ard_moodtest()} function, the data is expected to be one row per subject. The data is passed as \code{mood.test(data[[variable]] ~ data[[by]], ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> ard_stats_mood_test(by = "SEX", variables = "AGE") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_oneway_test.Rd b/man/ard_stats_oneway_test.Rd index 639c814f8..439fb9c3f 100644 --- a/man/ard_stats_oneway_test.Rd +++ b/man/ard_stats_oneway_test.Rd @@ -25,7 +25,7 @@ Analysis results data for Testing Equal Means in a One-Way Layout. calculated with \code{oneway.test()} } \examples{ -\dontshow{if (cards::is_pkg_installed(c("broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) \dontshow{\}) # examplesIf} } diff --git a/man/ard_stats_prop_test.Rd b/man/ard_stats_prop_test.Rd index 0dbfbfdc9..cb966e1c4 100644 --- a/man/ard_stats_prop_test.Rd +++ b/man/ard_stats_prop_test.Rd @@ -26,7 +26,7 @@ ARD data frame Analysis results data for a 2-sample test or proportions using \code{\link[stats:prop.test]{stats::prop.test()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} mtcars |> ard_stats_prop_test(by = vs, variables = am) \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_t_test.Rd b/man/ard_stats_t_test.Rd index 5bc92322d..1bfb7fbe9 100644 --- a/man/ard_stats_t_test.Rd +++ b/man/ard_stats_t_test.Rd @@ -42,7 +42,7 @@ The data are then passed as \verb{t.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) diff --git a/man/ard_stats_wilcox_test.Rd b/man/ard_stats_wilcox_test.Rd index 9f52f4f8d..14f48b213 100644 --- a/man/ard_stats_wilcox_test.Rd +++ b/man/ard_stats_wilcox_test.Rd @@ -42,7 +42,7 @@ The data are then passed as \verb{wilcox.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> ard_stats_wilcox_test(by = "ARM", variables = "AGE") diff --git a/man/ard_survey_svychisq.Rd b/man/ard_survey_svychisq.Rd index 5b8465d2b..e645f5c00 100644 --- a/man/ard_survey_svychisq.Rd +++ b/man/ard_survey_svychisq.Rd @@ -32,7 +32,7 @@ Analysis results data for survey Chi-Square test using \code{\link[survey:svychi Only two-way comparisons are supported. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) diff --git a/man/ard_survey_svycontinuous.Rd b/man/ard_survey_svycontinuous.Rd index c60b56add..8e5df93d2 100644 --- a/man/ard_survey_svycontinuous.Rd +++ b/man/ard_survey_svycontinuous.Rd @@ -56,7 +56,7 @@ where 'p##' is are the percentiles and \verb{##} is an integer between 0 and 100 } \examples{ -\dontshow{if (cards::is_pkg_installed("survey", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survey", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) diff --git a/man/ard_survey_svyranktest.Rd b/man/ard_survey_svyranktest.Rd index 33eea727c..e42c17620 100644 --- a/man/ard_survey_svyranktest.Rd +++ b/man/ard_survey_svyranktest.Rd @@ -29,7 +29,7 @@ ARD data frame Analysis results data for survey wilcox test using \code{\link[survey:svyranktest]{survey::svyranktest()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) diff --git a/man/ard_survey_svyttest.Rd b/man/ard_survey_svyttest.Rd index c80254245..b305f4912 100644 --- a/man/ard_survey_svyttest.Rd +++ b/man/ard_survey_svyttest.Rd @@ -29,7 +29,7 @@ ARD data frame Analysis results data for survey t-test using \code{\link[survey:svyttest]{survey::svyttest()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) diff --git a/man/ard_survival_survfit.Rd b/man/ard_survival_survfit.Rd index 93fb00cdc..0ea1ca8dd 100644 --- a/man/ard_survival_survfit.Rd +++ b/man/ard_survival_survfit.Rd @@ -41,7 +41,7 @@ survival fit model. } } \examples{ -\dontshow{if (cards::is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "broom"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(survival) survfit(Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> diff --git a/tests/testthat/_snaps/ard_vif.md b/tests/testthat/_snaps/ard_car_vif.md similarity index 77% rename from tests/testthat/_snaps/ard_vif.md rename to tests/testthat/_snaps/ard_car_vif.md index 2fef8dd36..745c24ef3 100644 --- a/tests/testthat/_snaps/ard_vif.md +++ b/tests/testthat/_snaps/ard_car_vif.md @@ -1,7 +1,7 @@ -# ard_vif() works +# ard_car_vif() works Code - as.data.frame(ard_vif(lm(AGE ~ ARM + SEX, data = cards::ADSL))) + as.data.frame(ard_car_vif(lm(AGE ~ ARM + SEX, data = cards::ADSL))) Output variable context stat_name stat_label stat fmt_fn warning error 1 ARM vif GVIF GVIF 1.015675 1 NULL NULL @@ -14,16 +14,16 @@ --- Code - as.data.frame(ard_vif(lm(AGE ~ BMIBL + EDUCLVL, data = cards::ADSL))) + as.data.frame(ard_car_vif(lm(AGE ~ BMIBL + EDUCLVL, data = cards::ADSL))) Output variable context stat_name stat_label stat fmt_fn warning error 1 BMIBL vif VIF VIF 1.010522 1 NULL NULL 2 EDUCLVL vif VIF VIF 1.010522 1 NULL NULL -# ard_vif() appropriate errors are given for model with only 1 term +# ard_car_vif() appropriate errors are given for model with only 1 term Code - as.data.frame(ard_vif(lm(AGE ~ ARM, data = cards::ADSL))) + as.data.frame(ard_car_vif(lm(AGE ~ ARM, data = cards::ADSL))) Output variable context stat_name stat_label stat fmt_fn warning 1 ARM vif VIF VIF NULL NULL NULL @@ -42,6 +42,5 @@ ard_vif(cards::ADSL) Condition Error in `ard_vif()`: - ! There was an error running `car::vif()`. See below. - x no applicable method for 'vcov' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')" + ! could not find function "ard_vif" diff --git a/tests/testthat/_snaps/ard_stats_chisq_test.md b/tests/testthat/_snaps/ard_stats_chisq_test.md new file mode 100644 index 000000000..c5ad14cf0 --- /dev/null +++ b/tests/testthat/_snaps/ard_stats_chisq_test.md @@ -0,0 +1,17 @@ +# shuffle_ard fills missing group levels if the group is meaningful + + Code + as.data.frame(cards::shuffle_ard(cards::bind_ard(ard_stats_chisq_test(data = adsl_sub, + by = "ARM", variables = "AGEGR1"), ard_stats_chisq_test(data = adsl_sub, by = "SEX", + variables = "AGEGR1")))) + Output + ARM SEX variable context stat_name stat + 1 Overall ARM AGEGR1 chisqtest statistic 5.079442e+00 + 2 Overall ARM AGEGR1 chisqtest p.value 7.888842e-02 + 3 Overall ARM AGEGR1 chisqtest parameter 2.000000e+00 + 4 Overall ARM AGEGR1 chisqtest B 2.000000e+03 + 5 Overall SEX AGEGR1 chisqtest statistic 1.039442e+00 + 6 Overall SEX AGEGR1 chisqtest p.value 5.946864e-01 + 7 Overall SEX AGEGR1 chisqtest parameter 2.000000e+00 + 8 Overall SEX AGEGR1 chisqtest B 2.000000e+03 + diff --git a/tests/testthat/_snaps/ard_moodtest.md b/tests/testthat/_snaps/ard_stats_mood_test.md similarity index 85% rename from tests/testthat/_snaps/ard_moodtest.md rename to tests/testthat/_snaps/ard_stats_mood_test.md index b6bb0e8c2..8e5db79df 100644 --- a/tests/testthat/_snaps/ard_moodtest.md +++ b/tests/testthat/_snaps/ard_stats_mood_test.md @@ -1,7 +1,7 @@ -# ard_moodtest() works +# ard_stats_mood_test() works Code - as.data.frame(ard_moodtest(cards::ADSL, by = SEX, variable = AGE)) + as.data.frame(ard_stats_mood_test(cards::ADSL, by = SEX, variable = AGE)) Output group1 variable context stat_name stat_label 1 SEX AGE moodtest statistic Z-Statistic diff --git a/tests/testthat/_snaps/ard_onewaytest.md b/tests/testthat/_snaps/ard_stats_oneway_test.md similarity index 68% rename from tests/testthat/_snaps/ard_onewaytest.md rename to tests/testthat/_snaps/ard_stats_oneway_test.md index 616b24342..6a597b9d2 100644 --- a/tests/testthat/_snaps/ard_onewaytest.md +++ b/tests/testthat/_snaps/ard_stats_oneway_test.md @@ -1,7 +1,7 @@ -# ard_onewaytest() works +# ard_stats_oneway_test() works Code - head(dplyr::select(ard_onewaytest(AGEGR1 ~ ARM, data = cards::ADSL), c( + head(dplyr::select(ard_stats_oneway_test(AGEGR1 ~ ARM, data = cards::ADSL), c( "stat_name", "stat", "warning")), 3) Message {cards} data frame: 3 x 3 diff --git a/tests/testthat/_snaps/ard_svychisq.md b/tests/testthat/_snaps/ard_survey_svychisq.md similarity index 76% rename from tests/testthat/_snaps/ard_svychisq.md rename to tests/testthat/_snaps/ard_survey_svychisq.md index 46f7f46df..5d9b016f3 100644 --- a/tests/testthat/_snaps/ard_svychisq.md +++ b/tests/testthat/_snaps/ard_survey_svychisq.md @@ -1,9 +1,9 @@ -# ard_svychisq() works +# ard_survey_svychisq() works Code - as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select(ard_svychisq( - dclus2, variables = c(sch.wide, stype), by = comp.imp, statistic = "adjWald"), - c(1:3, 5:6)), variable), n = 3)) + as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select( + ard_survey_svychisq(dclus2, variables = c(sch.wide, stype), by = comp.imp, + statistic = "adjWald"), c(1:3, 5:6)), variable), n = 3)) Output group1 variable context stat_label stat 1 comp.imp sch.wide svychisq Nominator Degrees of Freedom 1 diff --git a/tests/testthat/_snaps/ard_svyranktest.md b/tests/testthat/_snaps/ard_survey_svyranktest.md similarity index 98% rename from tests/testthat/_snaps/ard_svyranktest.md rename to tests/testthat/_snaps/ard_survey_svyranktest.md index 97d6b33eb..85ba37bb8 100644 --- a/tests/testthat/_snaps/ard_svyranktest.md +++ b/tests/testthat/_snaps/ard_survey_svyranktest.md @@ -1,4 +1,4 @@ -# ard_svyranktest() works +# ard_survey_svyranktest() works Code dplyr::select(as.data.frame(svyranktest[[1]]), stat_label, stat) diff --git a/tests/testthat/_snaps/ard_survfit.md b/tests/testthat/_snaps/ard_survival_survfit.md similarity index 79% rename from tests/testthat/_snaps/ard_survfit.md rename to tests/testthat/_snaps/ard_survival_survfit.md index 5d209bb98..da830d66d 100644 --- a/tests/testthat/_snaps/ard_survfit.md +++ b/tests/testthat/_snaps/ard_survival_survfit.md @@ -1,9 +1,9 @@ -# ard_survfit() works with times provided +# ard_survival_survfit() works with times provided Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ - TRTA, cards::ADTTE), times = c(60, 180)), stat = lapply(stat, function(x) - ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(AVAL, + CNSR) ~ TRTA, cards::ADTTE), times = c(60, 180)), stat = lapply(stat, + function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 18 x 11 Output @@ -29,12 +29,12 @@ Message i 4 more variables: context, fmt_fn, warning, error -# ard_survfit() works with different type +# ard_survival_survfit() works with different type Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ - TRTA, cards::ADTTE), times = c(60, 180), type = "risk"), stat = lapply(stat, - function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(AVAL, + CNSR) ~ TRTA, cards::ADTTE), times = c(60, 180), type = "risk"), stat = lapply( + stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 18 x 11 Output @@ -60,12 +60,12 @@ Message i 4 more variables: context, fmt_fn, warning, error -# ard_survfit() works with probs provided +# ard_survival_survfit() works with probs provided Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ - TRTA, cards::ADTTE), probs = c(0.25, 0.75)), stat = lapply(stat, function(x) - ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(AVAL, + CNSR) ~ TRTA, cards::ADTTE), probs = c(0.25, 0.75)), stat = lapply(stat, + function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 18 x 11 Output @@ -91,12 +91,12 @@ Message i 4 more variables: context, fmt_fn, warning, error -# ard_survfit() works with unstratified model +# ard_survival_survfit() works with unstratified model Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(time, status) ~ - 1, data = survival::lung), times = c(60, 180)), stat = lapply(stat, function( - x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(time, + status) ~ 1, data = survival::lung), times = c(60, 180)), stat = lapply(stat, + function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 6 x 9 Output @@ -113,9 +113,9 @@ --- Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(time, status) ~ - 1, data = survival::lung), probs = c(0.5, 0.75)), stat = lapply(stat, - function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(time, + status) ~ 1, data = survival::lung), probs = c(0.5, 0.75)), stat = lapply( + stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 6 x 9 Output @@ -129,13 +129,13 @@ Message i 3 more variables: fmt_fn, warning, error -# ard_survfit() works with multiple stratification variables +# ard_survival_survfit() works with multiple stratification variables Code - print(head(dplyr::select(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv( - time, status) ~ sex + ph.ecog, data = survival::lung), times = c(60, 180)), - stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), - "group1", "group1_level", "group2", "group2_level"), 20), n = Inf) + print(head(dplyr::select(dplyr::mutate(ard_survival_survfit(survival::survfit( + survival::Surv(time, status) ~ sex + ph.ecog, data = survival::lung), times = c( + 60, 180)), stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5( + x, 3), x))), "group1", "group1_level", "group2", "group2_level"), 20), n = Inf) Message {cards} data frame: 20 x 4 Output @@ -164,10 +164,10 @@ --- Code - print(head(dplyr::select(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv( - time, status) ~ sex + ph.ecog, data = survival::lung), probs = c(0.5, 0.75)), - stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), - "group1", "group1_level", "group2", "group2_level"), 20), n = Inf) + print(head(dplyr::select(dplyr::mutate(ard_survival_survfit(survival::survfit( + survival::Surv(time, status) ~ sex + ph.ecog, data = survival::lung), probs = c( + 0.5, 0.75)), stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5( + x, 3), x))), "group1", "group1_level", "group2", "group2_level"), 20), n = Inf) Message {cards} data frame: 20 x 4 Output @@ -193,12 +193,12 @@ 19 sex 1 ph.ecog 3 20 sex 1 ph.ecog 3 -# ard_survfit() works with competing risks +# ard_survival_survfit() works with competing risks Code print(dplyr::mutate(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, data = ADTTE_MS) %>% - ard_survfit(times = c(60, 180)), stat = lapply(stat, function(x) ifelse( - is.numeric(x), cards::round5(x, 3), x))), n = Inf) + ard_survival_survfit(times = c(60, 180)), stat = lapply(stat, function(x) + ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message Multi-state model detected. Showing probabilities into state 'death from cancer'. {cards} data frame: 18 x 11 @@ -225,37 +225,38 @@ Message i 4 more variables: context, fmt_fn, warning, error -# ard_survfit() errors are properly handled +# ard_survival_survfit() errors are properly handled Code - ard_survfit("not_survfit") + ard_survival_survfit("not_survfit") Condition - Error in `ard_survfit()`: + Error in `ard_survival_survfit()`: ! The `x` argument must be class , not a string. --- Code - ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE), - times = 100, type = "notatype") + ard_survival_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, + cards::ADTTE), times = 100, type = "notatype") Condition - Error in `ard_survfit()`: + Error in `ard_survival_survfit()`: ! `type` must be one of "survival", "risk", or "cumhaz", not "notatype". --- Code - ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE), - times = 100, probs = c(0.25, 0.75)) + ard_survival_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, + cards::ADTTE), times = 100, probs = c(0.25, 0.75)) Condition - Error in `ard_survfit()`: + Error in `ard_survival_survfit()`: ! One and only one of `times` and `probs` must be specified. -# ard_survfit() errors with stratified Cox model +# ard_survival_survfit() errors with stratified Cox model Code - ard_survfit(survfit(coxph(Surv(time, status) ~ age + strata(sex), survival::lung))) + ard_survival_survfit(survfit(coxph(Surv(time, status) ~ age + strata(sex), + survival::lung))) Condition - Error in `ard_survfit()`: + Error in `ard_survival_survfit()`: ! Argument `x` cannot be class . diff --git a/tests/testthat/_snaps/ard_svycontinuous.md b/tests/testthat/_snaps/ard_svycontinuous.md deleted file mode 100644 index 28d83bb09..000000000 --- a/tests/testthat/_snaps/ard_svycontinuous.md +++ /dev/null @@ -1,54 +0,0 @@ -# unstratified ard_svycontinuous() works - - Code - ard_uni_svy_cont - Message - {cards} data frame: 10 x 8 - Output - variable context stat_name stat_label stat fmt_fn - 1 api00 continuo… mean Mean 644.169 1 - 2 api00 continuo… median Median 652 1 - 3 api00 continuo… min Minimum 411 1 - 4 api00 continuo… max Maximum 905 1 - 5 api00 continuo… sum Sum 3989985 1 - 6 api00 continuo… var Variance 11182.82 1 - 7 api00 continuo… sd Standard… 105.749 1 - 8 api00 continuo… mean.std.error SE(Mean) 23.542 1 - 9 api00 continuo… deff Design E… 9.346 1 - 10 api00 continuo… p75 75% Perc… 719 1 - Message - i 2 more variables: warning, error - -# ard_svycontinuous(fmt_fn) - - Code - ard_svycontinuous(dclus1, variables = api00, statistic = ~ c("mean", "median", - "min", "max"), fmt_fn = list(api00 = list(mean = 2, median = "xx.xx", min = as.character))) - Message - {cards} data frame: 4 x 8 - Output - variable context stat_name stat_label stat fmt_fn - 1 api00 continuo… mean Mean 644.169 2 - 2 api00 continuo… median Median 652 xx.xx - 3 api00 continuo… min Minimum 411 - 4 api00 continuo… max Maximum 905 1 - Message - i 2 more variables: warning, error - -# ard_svycontinuous(stat_label) - - Code - ard_svycontinuous(dclus1, variables = api00, statistic = ~ c("mean", "median", - "min", "max"), stat_label = list(api00 = list(mean = "MeAn", median = "MEDian", - min = "MINimum"))) - Message - {cards} data frame: 4 x 8 - Output - variable context stat_name stat_label stat fmt_fn - 1 api00 continuo… mean MeAn 644.169 1 - 2 api00 continuo… median MEDian 652 1 - 3 api00 continuo… min MINimum 411 1 - 4 api00 continuo… max Maximum 905 1 - Message - i 2 more variables: warning, error - diff --git a/tests/testthat/_snaps/ard_ttest.md b/tests/testthat/_snaps/ard_ttest.md deleted file mode 100644 index 9fc30da10..000000000 --- a/tests/testthat/_snaps/ard_ttest.md +++ /dev/null @@ -1,73 +0,0 @@ -# ard_ttest() works - - Code - as.data.frame(ard_ttest(cards::ADSL, by = ARM, variable = AGE, var.equal = TRUE)) - Output - group1 variable context stat_name stat_label stat fmt_fn warning - 1 ARM AGE ttest estimate Mean Difference NULL NULL NULL - 2 ARM AGE ttest estimate1 Group 1 Mean NULL NULL NULL - 3 ARM AGE ttest estimate2 Group 2 Mean NULL NULL NULL - 4 ARM AGE ttest statistic t Statistic NULL NULL NULL - 5 ARM AGE ttest p.value p-value NULL NULL NULL - 6 ARM AGE ttest parameter Degrees of Freedom NULL NULL NULL - 7 ARM AGE ttest conf.low CI Lower Bound NULL NULL NULL - 8 ARM AGE ttest conf.high CI Upper Bound NULL NULL NULL - 9 ARM AGE ttest method method NULL NULL NULL - 10 ARM AGE ttest alternative alternative NULL NULL NULL - 11 ARM AGE ttest mu H0 Mean 0 1 NULL - 12 ARM AGE ttest paired Paired t-test FALSE NULL NULL - 13 ARM AGE ttest var.equal Equal Variances TRUE NULL NULL - 14 ARM AGE ttest conf.level CI Confidence Level 0.95 1 NULL - error - 1 grouping factor must have exactly 2 levels - 2 grouping factor must have exactly 2 levels - 3 grouping factor must have exactly 2 levels - 4 grouping factor must have exactly 2 levels - 5 grouping factor must have exactly 2 levels - 6 grouping factor must have exactly 2 levels - 7 grouping factor must have exactly 2 levels - 8 grouping factor must have exactly 2 levels - 9 grouping factor must have exactly 2 levels - 10 grouping factor must have exactly 2 levels - 11 grouping factor must have exactly 2 levels - 12 grouping factor must have exactly 2 levels - 13 grouping factor must have exactly 2 levels - 14 grouping factor must have exactly 2 levels - -# ard_paired_ttest() works - - Code - as.data.frame(ard_paired_ttest(dplyr::mutate(ADSL_paired, ARM = ifelse(dplyr::row_number() == - 1L, "3rd ARM", ARM)), by = ARM, variable = AGE, id = USUBJID, var.equal = TRUE)) - Output - group1 variable context stat_name stat_label stat fmt_fn warning - 1 ARM AGE ttest estimate Mean Difference NULL NULL NULL - 2 ARM AGE ttest estimate1 Group 1 Mean NULL NULL NULL - 3 ARM AGE ttest estimate2 Group 2 Mean NULL NULL NULL - 4 ARM AGE ttest statistic t Statistic NULL NULL NULL - 5 ARM AGE ttest p.value p-value NULL NULL NULL - 6 ARM AGE ttest parameter Degrees of Freedom NULL NULL NULL - 7 ARM AGE ttest conf.low CI Lower Bound NULL NULL NULL - 8 ARM AGE ttest conf.high CI Upper Bound NULL NULL NULL - 9 ARM AGE ttest method method NULL NULL NULL - 10 ARM AGE ttest alternative alternative NULL NULL NULL - 11 ARM AGE ttest mu H0 Mean 0 1 NULL - 12 ARM AGE ttest paired Paired t-test TRUE NULL NULL - 13 ARM AGE ttest var.equal Equal Variances TRUE NULL NULL - 14 ARM AGE ttest conf.level CI Confidence Level 0.95 1 NULL - error - 1 The `by` argument must have two and only two levels. - 2 The `by` argument must have two and only two levels. - 3 The `by` argument must have two and only two levels. - 4 The `by` argument must have two and only two levels. - 5 The `by` argument must have two and only two levels. - 6 The `by` argument must have two and only two levels. - 7 The `by` argument must have two and only two levels. - 8 The `by` argument must have two and only two levels. - 9 The `by` argument must have two and only two levels. - 10 The `by` argument must have two and only two levels. - 11 The `by` argument must have two and only two levels. - 12 The `by` argument must have two and only two levels. - 13 The `by` argument must have two and only two levels. - 14 The `by` argument must have two and only two levels. - diff --git a/tests/testthat/test-ard_aod_wald_test.R b/tests/testthat/test-ard_aod_wald_test.R index 3f149b76f..3576c62bc 100644 --- a/tests/testthat/test-ard_aod_wald_test.R +++ b/tests/testthat/test-ard_aod_wald_test.R @@ -1,3 +1,5 @@ +skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "aod", reference_pkg = "cardx"))) + test_that("ard_aod_wald_test() works", { # works for a generic case expect_error( diff --git a/tests/testthat/test-ard_car_vif.R b/tests/testthat/test-ard_car_vif.R index 6d717b8a3..390fdb77f 100644 --- a/tests/testthat/test-ard_car_vif.R +++ b/tests/testthat/test-ard_car_vif.R @@ -1,3 +1,5 @@ +skip_if_not(is_pkg_installed("car", reference_pkg = "cardx")) + test_that("ard_car_vif() works", { expect_snapshot( lm(AGE ~ ARM + SEX, data = cards::ADSL) |> diff --git a/tests/testthat/test-ard_effectsize_cohens_d.R b/tests/testthat/test-ard_effectsize_cohens_d.R index 25a83bc5b..fe5c771bf 100644 --- a/tests/testthat/test-ard_effectsize_cohens_d.R +++ b/tests/testthat/test-ard_effectsize_cohens_d.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")) test_that("ard_effectsize_cohens_d() works", { # there were some discrepancies in the 7th decimal place on one system diff --git a/tests/testthat/test-ard_effectsize_hedges_g.R b/tests/testthat/test-ard_effectsize_hedges_g.R index f2e0dee97..47f84ed93 100644 --- a/tests/testthat/test-ard_effectsize_hedges_g.R +++ b/tests/testthat/test-ard_effectsize_hedges_g.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) test_that("ard_effectsize_hedges_g() works", { withr::local_namespace("effectsize") diff --git a/tests/testthat/test-ard_smd_smd.R b/tests/testthat/test-ard_smd_smd.R index 5c0fc2f86..85b6ae036 100644 --- a/tests/testthat/test-ard_smd_smd.R +++ b/tests/testthat/test-ard_smd_smd.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("smd", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("smd", reference_pkg = "cardx")) test_that("ard_smd_smd() works", { expect_error( @@ -30,7 +30,7 @@ test_that("ard_smd_smd() works", { }) test_that("ard_smd() works with survey data", { - skip_if_not(cards::is_pkg_installed("survey", reference_pkg = "cardx")) + skip_if_not(is_pkg_installed("survey", reference_pkg = "cardx")) data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) diff --git a/tests/testthat/test-ard_stats_anova.R b/tests/testthat/test-ard_stats_anova.R index 1982d7b3f..b2be9a90b 100644 --- a/tests/testthat/test-ard_stats_anova.R +++ b/tests/testthat/test-ard_stats_anova.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("broom", "withr", "lme4", "survival"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("broom", "withr", "lme4", "survival"), reference_pkg = "cardx")) test_that("ard_stats_anova.anova() works", { expect_equal( diff --git a/tests/testthat/test-ard_stats_aov.R b/tests/testthat/test-ard_stats_aov.R index 99fe86831..01de036ce 100644 --- a/tests/testthat/test-ard_stats_aov.R +++ b/tests/testthat/test-ard_stats_aov.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom.helpers", reference_pkg = "cardx")) test_that("ard_aov() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_chisq_test.R b/tests/testthat/test-ard_stats_chisq_test.R index 37b3ef879..0e99d39aa 100644 --- a/tests/testthat/test-ard_stats_chisq_test.R +++ b/tests/testthat/test-ard_stats_chisq_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_chisq_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_fisher_test.R b/tests/testthat/test-ard_stats_fisher_test.R index 92731eaf4..eb7d2033c 100644 --- a/tests/testthat/test-ard_stats_fisher_test.R +++ b/tests/testthat/test-ard_stats_fisher_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_fisher_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_kruskal_test.R b/tests/testthat/test-ard_stats_kruskal_test.R index cdf1f023d..fb4e96bdb 100644 --- a/tests/testthat/test-ard_stats_kruskal_test.R +++ b/tests/testthat/test-ard_stats_kruskal_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_kruskal_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_mcnemar_test.R b/tests/testthat/test-ard_stats_mcnemar_test.R index 8f757cab2..5b54f50fa 100644 --- a/tests/testthat/test-ard_stats_mcnemar_test.R +++ b/tests/testthat/test-ard_stats_mcnemar_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_mcnemar_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_mood_test.R b/tests/testthat/test-ard_stats_mood_test.R index 34f12a0c4..292399b4c 100644 --- a/tests/testthat/test-ard_stats_mood_test.R +++ b/tests/testthat/test-ard_stats_mood_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_mood_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_oneway_test.R b/tests/testthat/test-ard_stats_oneway_test.R index 2182287bc..55edb7a07 100644 --- a/tests/testthat/test-ard_stats_oneway_test.R +++ b/tests/testthat/test-ard_stats_oneway_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_oneway_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_prop_test.R b/tests/testthat/test-ard_stats_prop_test.R index 7ef180624..51b74adf6 100644 --- a/tests/testthat/test-ard_stats_prop_test.R +++ b/tests/testthat/test-ard_stats_prop_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_prop_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_t_test.R b/tests/testthat/test-ard_stats_t_test.R index 600ec68d7..15bb29a2d 100644 --- a/tests/testthat/test-ard_stats_t_test.R +++ b/tests/testthat/test-ard_stats_t_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_t_test() works", { # One Sample t-test works diff --git a/tests/testthat/test-ard_stats_wilcox_test.R b/tests/testthat/test-ard_stats_wilcox_test.R index 82c7a7837..a8fc09e1d 100644 --- a/tests/testthat/test-ard_stats_wilcox_test.R +++ b/tests/testthat/test-ard_stats_wilcox_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_wilcox_test() works", { # One Sample Wilcox works diff --git a/tests/testthat/test-ard_survey_svychisq.R b/tests/testthat/test-ard_survey_svychisq.R index c94cfd865..894fbbd8b 100644 --- a/tests/testthat/test-ard_survey_svychisq.R +++ b/tests/testthat/test-ard_survey_svychisq.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) test_that("ard_survey_svychisq() works", { data(api, package = "survey") diff --git a/tests/testthat/test-ard_survey_svycontinuous.R b/tests/testthat/test-ard_survey_svycontinuous.R index dfcd27496..85e737ce7 100644 --- a/tests/testthat/test-ard_survey_svycontinuous.R +++ b/tests/testthat/test-ard_survey_svycontinuous.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("survey", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("survey", reference_pkg = "cardx")) test_that("unstratified ard_survey_svycontinuous() works", { data(api, package = "survey") diff --git a/tests/testthat/test-ard_survey_svyranktest.R b/tests/testthat/test-ard_survey_svyranktest.R index eb74b9b6f..610beb4ae 100644 --- a/tests/testthat/test-ard_survey_svyranktest.R +++ b/tests/testthat/test-ard_survey_svyranktest.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) test_that("ard_survey_svyranktest() works", { data(api, package = "survey") diff --git a/tests/testthat/test-ard_survey_svyttest.R b/tests/testthat/test-ard_survey_svyttest.R index 529b7561b..c1d04eb34 100644 --- a/tests/testthat/test-ard_survey_svyttest.R +++ b/tests/testthat/test-ard_survey_svyttest.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) test_that("ard_survey_svyttest() works", { data(api, package = "survey") diff --git a/tests/testthat/test-ard_survival_survfit.R b/tests/testthat/test-ard_survival_survfit.R index 70301e62f..d12d4ac32 100644 --- a/tests/testthat/test-ard_survival_survfit.R +++ b/tests/testthat/test-ard_survival_survfit.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx")) test_that("ard_survival_survfit() works with times provided", { expect_snapshot( From 1a7aedabe2579c45e287eaa187ede0ea6f19306a Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 17:21:21 -0700 Subject: [PATCH 08/14] Update check.yaml --- .github/workflows/check.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 7b65f4a1c..c35021adf 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -8,8 +8,6 @@ on: - synchronize - reopened - ready_for_review - branches: - - main push: branches: - main From ee381e5b4774a7ef579dd8e7bfd64a19b90c3f70 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 17:24:13 -0700 Subject: [PATCH 09/14] workflow updates --- .github/workflows/R-CMD-check.yaml | 1 - .github/workflows/test-coverage.yaml | 1 - 2 files changed, 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 9f9b10800..50de31520 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -8,7 +8,6 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] name: R-CMD-check diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2c5bb5029..1ccc71c5f 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -4,7 +4,6 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] name: test-coverage From 47a7eb0308e0a66376e0e9c1e6ba0cf412248321 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 17:28:00 -0700 Subject: [PATCH 10/14] styler --- R/ard_smd_smd.R | 4 ++-- R/ard_stats_t_test.R | 2 +- R/ard_survey_svycontinuous.R | 12 ++++++------ R/ard_survival_survfit.R | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/R/ard_smd_smd.R b/R/ard_smd_smd.R index d41e380cb..f7c71876f 100644 --- a/R/ard_smd_smd.R +++ b/R/ard_smd_smd.R @@ -58,8 +58,8 @@ ard_smd_smd <- function(data, by, variables, ...) { lst_tidy = cards::eval_capture_conditions( switch(as.character(is_survey), - "TRUE" = smd::smd(x = data[[variable]], g = data[[by]], w = stats::weights(design), na.rm = TRUE, ...), - "FALSE" = smd::smd(x = data[[variable]], g = data[[by]], na.rm = TRUE, ...) + "TRUE" = smd::smd(x = data[[variable]], g = data[[by]], w = stats::weights(design), na.rm = TRUE, ...), + "FALSE" = smd::smd(x = data[[variable]], g = data[[by]], na.rm = TRUE, ...) ) |> dplyr::select(-any_of("term")) ), diff --git a/R/ard_stats_t_test.R b/R/ard_stats_t_test.R index f1768b6d6..194b9cd30 100644 --- a/R/ard_stats_t_test.R +++ b/R/ard_stats_t_test.R @@ -163,7 +163,7 @@ ard_stats_paired_t_test <- function(data, by, variables, id, ...) { "p.value", "parameter", "conf.low", "conf.high", "method", "alternative" ) |> - # add estimate1 and estimate2 if there is a by variable + # add estimate1 and estimate2 if there is a by variable append(values = switch(!is_empty(by), c("estimate1", "estimate2")), after = 1L), # styler: off fun_args_to_record = c("mu", "paired", "var.equal", "conf.level"), formals = formals(asNamespace("stats")[["t.test.default"]]), diff --git a/R/ard_survey_svycontinuous.R b/R/ard_survey_svycontinuous.R index ddf1b0027..88341edd4 100644 --- a/R/ard_survey_svycontinuous.R +++ b/R/ard_survey_svycontinuous.R @@ -44,9 +44,9 @@ #' by = stype #' ) ard_survey_svycontinuous <- function(data, variables, by = NULL, - statistic = everything() ~ c("median", "p25", "p75"), - fmt_fn = NULL, - stat_label = NULL) { + statistic = everything() ~ c("median", "p25", "p75"), + fmt_fn = NULL, + stat_label = NULL) { set_cli_abort_call() # check installed packages --------------------------------------------------- @@ -74,7 +74,7 @@ ard_survey_svycontinuous <- function(data, variables, by = NULL, x = statistic, predicate = \(x) all(x %in% accepted_svy_stats()), error_msg = c("Error in the values of the {.arg statistic} argument.", - i = "Values must be in {.val {accepted_svy_stats(FALSE)}}" + i = "Values must be in {.val {accepted_svy_stats(FALSE)}}" ) ) @@ -110,8 +110,8 @@ ard_survey_svycontinuous <- function(data, variables, by = NULL, variable = names(stat_label), stat_name = map(.data$variable, ~ names(stat_label[[.x]])), stat_label = map(.data$variable, ~ stat_label[[.x]] |> - unname() |> - unlist()) + unname() |> + unlist()) ) |> tidyr::unnest(cols = c("stat_name", "stat_label")), by = "stat_name", diff --git a/R/ard_survival_survfit.R b/R/ard_survival_survfit.R index ff541589f..4b0eeebde 100644 --- a/R/ard_survival_survfit.R +++ b/R/ard_survival_survfit.R @@ -93,8 +93,8 @@ ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { # build ARD ------------------------------------------------------------------ est_type <- ifelse(is.null(probs), "times", "probs") tidy_survfit <- switch(est_type, - "times" = .process_survfit_time(x, times, type %||% "survival"), - "probs" = .process_survfit_probs(x, probs) + "times" = .process_survfit_time(x, times, type %||% "survival"), + "probs" = .process_survfit_probs(x, probs) ) .format_survfit_results(tidy_survfit) @@ -314,9 +314,9 @@ extract_multi_strata <- function(x, df_stat) { .data$stat, function(x) { switch(is.integer(x), - 0L + 0L ) %||% switch(is.numeric(x), - 1L + 1L ) } ), From 294e6674af338b3b0d5dc0e50e4e390528ecab59 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 17:33:16 -0700 Subject: [PATCH 11/14] Update NEWS.md --- NEWS.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1293440df..e3b3f5c91 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,17 +23,17 @@ ard_moodtest() -> ard_stats_mood_test() - `ard_stats_anova()` for calculating ANOVA results using `stats::anova()`. (#12) - `ard_aod_wald_test()` for calculating Wald Tests for regression models using `aod::wald.test()`. (#84) - `ard_car_anova()` for calculating ANOVA results using `car::Anova()`. (#3) - - `ard_onewaytest()` for calculating ANOVA results using `stats::oneway.test()`. (#3) - - `ard_cohens_d()`, `ard_paired_cohens_d()`, `ard_hedges_g()`, and `ard_paired_hedges_g()` for standardized differences using `effectsize::cohens_d()` and `effectsize::hedges_g()`. (#50) - - `ard_proptest()` for tests of proportions using `stats::prop.test()`. (#64) + - `ard_stats_oneway_test()` for calculating ANOVA results using `stats::oneway.test()`. (#3) + - `ard_effectsize_cohens_d()`, `ard_effectsize_paired_cohens_d()`, `ard_effectsize_hedges_g()`, and `ard_effectsize_paired_hedges_g()` for standardized differences using `effectsize::cohens_d()` and `effectsize::hedges_g()`. (#50) + - `ard_stats_prop_test()` for tests of proportions using `stats::prop.test()`. (#64) - `ard_regression_basic()` for basic regression models. The function focuses on matching terms to underlying variables names. (#46) - - `ard_smd()` for calculating standardized mean differences using `smd::smd()`. (#4) - - `ard_survfit()` for survival analyses using `survival::survfit()`. (#43) - - `ard_svycontinuous()` for calculating univariate summary statistics from weighted/survey data using many functions from the {survey} package. (#68) - - `ard_svychisq()` for weighted/survey chi-squared test using `survey::svychisq()`. (#72) - - `ard_svyttest()` for weighted/survey t-tests using `survey::svyttest()`. (#70) - - `ard_svyranktest()` for weighted/survey rank tests using `survey::svyranktest()`. (#71) - - `ard_vif()` for calculating the variance inflation factor using `car::vif()`. (#10) + - `ard_smd_smd()` for calculating standardized mean differences using `smd::smd()`. (#4) + - `ard_survival_survfit()` for survival analyses using `survival::survfit()`. (#43) + - `ard_survey_svycontinuous()` for calculating univariate summary statistics from weighted/survey data using many functions from the {survey} package. (#68) + - `ard_survey_svychisq()` for weighted/survey chi-squared test using `survey::svychisq()`. (#72) + - `ard_survey_svyttest()` for weighted/survey t-tests using `survey::svyttest()`. (#70) + - `ard_survey_svyranktest()` for weighted/survey rank tests using `survey::svyranktest()`. (#71) + - `ard_car_vif()` for calculating the variance inflation factor using `car::vif()`. (#10) * Updated functions `ard_stats_t_test()`, `ard_stats_paired_t_test()`, `ard_stats_wilcox_test()`, `ard_stats_paired_wilcox_test()`, `ard_stats_chisq_test()`, `ard_stats_fisher_test()`, `ard_stats_kruskal_test()`, `ard_stats_mcnemar_test()`, and `ard_stats_mood_test()` to accept multiple variables at once. Independent tests are calculated for each variable. The `variable` argument is renamed to `variables`. (#77) From 83d3805be7c052169776a24c8f7b54a611416d21 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 17:53:02 -0700 Subject: [PATCH 12/14] doc updates --- R/ard_effectsize_cohens_d.R | 2 +- R/ard_effectsize_hedges_g.R | 4 ++-- R/ard_stats_mcnemar_test.R | 2 +- R/ard_stats_mood_test.R | 2 +- man/ard_effectsize_cohens_d.Rd | 2 +- man/ard_effectsize_hedges_g.Rd | 4 ++-- man/ard_stats_mcnemar_test.Rd | 2 +- man/ard_stats_mood_test.Rd | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R/ard_effectsize_cohens_d.R b/R/ard_effectsize_cohens_d.R index 99ddd5b29..e0f10f33a 100644 --- a/R/ard_effectsize_cohens_d.R +++ b/R/ard_effectsize_cohens_d.R @@ -22,7 +22,7 @@ #' For the `ard_effectsize_cohens_d()` function, the data is expected to be one row per subject. #' The data is passed as `effectsize::cohens_d(data[[variable]]~data[[by]], data, paired = FALSE, ...)`. #' -#' For the `ard_paired_cohens_d()` function, the data is expected to be one row +#' For the `ard_effectsize_paired_cohens_d()` function, the data is expected to be one row #' per subject per by level. Before the effect size is calculated, the data are #' reshaped to a wide format to be one row per subject. #' The data are then passed as diff --git a/R/ard_effectsize_hedges_g.R b/R/ard_effectsize_hedges_g.R index 7d514dc08..99c9edb2b 100644 --- a/R/ard_effectsize_hedges_g.R +++ b/R/ard_effectsize_hedges_g.R @@ -19,10 +19,10 @@ #' @name ard_effectsize_hedges_g #' #' @details -#' For the `ard_hedges_g()` function, the data is expected to be one row per subject. +#' For the `ard_effectsize_hedges_g()` function, the data is expected to be one row per subject. #' The data is passed as `effectsize::hedges_g(data[[variable]]~data[[by]], data, paired = FALSE, ...)`. #' -#' For the `ard_paired_hedges_g()` function, the data is expected to be one row +#' For the `ard_effectsize_paired_hedges_g()` function, the data is expected to be one row #' per subject per by level. Before the effect size is calculated, the data are #' reshaped to a wide format to be one row per subject. #' The data are then passed as diff --git a/R/ard_stats_mcnemar_test.R b/R/ard_stats_mcnemar_test.R index 41374425d..4256fdfef 100644 --- a/R/ard_stats_mcnemar_test.R +++ b/R/ard_stats_mcnemar_test.R @@ -16,7 +16,7 @@ #' @export #' #' @details -#' For the `ard_mcnemartest()` function, the data is expected to be one row per subject. +#' For the `ard_stats_mcnemar_test()` 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. #' diff --git a/R/ard_stats_mood_test.R b/R/ard_stats_mood_test.R index d88fc4a92..385361c76 100644 --- a/R/ard_stats_mood_test.R +++ b/R/ard_stats_mood_test.R @@ -17,7 +17,7 @@ #' @name ard_stats_mood_test #' #' @details -#' For the `ard_moodtest()` function, the data is expected to be one row per subject. +#' For the `ard_stats_mood_test()` function, the data is expected to be one row per subject. #' The data is passed as `mood.test(data[[variable]] ~ data[[by]], ...)`. #' @rdname ard_stats_mood_test #' @export diff --git a/man/ard_effectsize_cohens_d.Rd b/man/ard_effectsize_cohens_d.Rd index 7f27382c6..3eb2ac94e 100644 --- a/man/ard_effectsize_cohens_d.Rd +++ b/man/ard_effectsize_cohens_d.Rd @@ -36,7 +36,7 @@ using \code{\link[effectsize:cohens_d]{effectsize::cohens_d()}}. For the \code{ard_effectsize_cohens_d()} function, the data is expected to be one row per subject. The data is passed as \code{effectsize::cohens_d(data[[variable]]~data[[by]], data, paired = FALSE, ...)}. -For the \code{ard_paired_cohens_d()} function, the data is expected to be one row +For the \code{ard_effectsize_paired_cohens_d()} function, the data is expected to be one row per subject per by level. Before the effect size is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as diff --git a/man/ard_effectsize_hedges_g.Rd b/man/ard_effectsize_hedges_g.Rd index d07fb1eca..5ec59117a 100644 --- a/man/ard_effectsize_hedges_g.Rd +++ b/man/ard_effectsize_hedges_g.Rd @@ -33,10 +33,10 @@ Analysis results data for paired and non-paired Hedge's G Effect Size Test using \code{\link[effectsize:cohens_d]{effectsize::hedges_g()}}. } \details{ -For the \code{ard_hedges_g()} function, the data is expected to be one row per subject. +For the \code{ard_effectsize_hedges_g()} function, the data is expected to be one row per subject. The data is passed as \code{effectsize::hedges_g(data[[variable]]~data[[by]], data, paired = FALSE, ...)}. -For the \code{ard_paired_hedges_g()} function, the data is expected to be one row +For the \code{ard_effectsize_paired_hedges_g()} function, the data is expected to be one row per subject per by level. Before the effect size is calculated, the data are reshaped to a wide format to be one row per subject. The data are then passed as diff --git a/man/ard_stats_mcnemar_test.Rd b/man/ard_stats_mcnemar_test.Rd index 90db48ebb..0f1327b8b 100644 --- a/man/ard_stats_mcnemar_test.Rd +++ b/man/ard_stats_mcnemar_test.Rd @@ -26,7 +26,7 @@ ARD data frame Analysis results data for McNemar's statistical test. } \details{ -For the \code{ard_mcnemartest()} function, the data is expected to be one row per subject. +For the \code{ard_stats_mcnemar_test()} function, the data is expected to be one row per subject. The data is passed as \code{stats::mcnemar.test(x = data[[variable]], y = data[[by]], ...)}. Please use \code{table(x = data[[variable]], y = data[[by]])} to check the contingency table. } diff --git a/man/ard_stats_mood_test.Rd b/man/ard_stats_mood_test.Rd index e551de898..5a06c6c76 100644 --- a/man/ard_stats_mood_test.Rd +++ b/man/ard_stats_mood_test.Rd @@ -27,7 +27,7 @@ Analysis results data for Mood two sample test of scale. Note this not to be con the Brown-Mood test of medians. } \details{ -For the \code{ard_moodtest()} function, the data is expected to be one row per subject. +For the \code{ard_stats_mood_test()} function, the data is expected to be one row per subject. The data is passed as \code{mood.test(data[[variable]] ~ data[[by]], ...)}. } \examples{ From c9f75064865e2fae539f46552a93ad37c740cc84 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 18:18:28 -0700 Subject: [PATCH 13/14] more updates --- R/ard_aod_wald_test.R | 9 ++++---- R/ard_car_anova.R | 3 ++- R/ard_car_vif.R | 3 ++- R/ard_stats_anova.R | 3 ++- R/ard_stats_prop_test.R | 3 ++- R/ard_stats_t_test.R | 6 +++--- R/ard_stats_wilcox_test.R | 34 ------------------------------ R/ard_survival_survfit.R | 9 +++++--- man/dot-paired_data_pivot_wider.Rd | 17 ++------------- 9 files changed, 24 insertions(+), 63 deletions(-) diff --git a/R/ard_aod_wald_test.R b/R/ard_aod_wald_test.R index e28f4b7e4..e1e41ee58 100644 --- a/R/ard_aod_wald_test.R +++ b/R/ard_aod_wald_test.R @@ -33,10 +33,11 @@ ard_aod_wald_test <- function(x, ...) { ) if (!is.null(reg_model[["error"]])) { - cli::cli_abort(c( - "Unable to identify underlying variable names in regression model.", - i = "Is this model type supported by {.fun broom.helpers::tidy_plus_plus}, which is the function used to identify variable names?" - )) + cli::cli_abort( + c("Unable to identify underlying variable names in regression model.", + i = "Is this model type supported by {.fun broom.helpers::tidy_plus_plus}, which is the function used to identify variable names?"), + call = get_cli_abort_call() + ) } aod <- reg_model[["result"]] %>% diff --git a/R/ard_car_anova.R b/R/ard_car_anova.R index 82b7ac030..8e8854ec3 100644 --- a/R/ard_car_anova.R +++ b/R/ard_car_anova.R @@ -30,7 +30,8 @@ ard_car_anova <- function(x, ...) { cli::cli_abort(c( "There was an error running {.fun car::Anova}. See error message below.", x = car_anova[["error"]] - )) + ), + call = get_cli_abort_call()) } car_anova[["result"]] |> diff --git a/R/ard_car_vif.R b/R/ard_car_vif.R index d1428d7ee..6d491bf19 100644 --- a/R/ard_car_vif.R +++ b/R/ard_car_vif.R @@ -32,7 +32,8 @@ ard_car_vif <- function(x, ...) { # we cannot get variable names, error out if (!is.null(lst_terms[["error"]])) { cli::cli_abort( - c("There was an error running {.fun car::vif}. See below.", x = vif[["error"]]) + c("There was an error running {.fun car::vif}. See below.", x = vif[["error"]]), + call = get_cli_abort_call() ) } vif$result <- dplyr::tibble( diff --git a/R/ard_stats_anova.R b/R/ard_stats_anova.R index b1a8a5880..822fece1d 100644 --- a/R/ard_stats_anova.R +++ b/R/ard_stats_anova.R @@ -118,7 +118,8 @@ ard_stats_anova.data.frame <- function(x, cli::cli_abort(c( "Argument {.arg fn} cannot be namespaced.", i = "Put the package name in the {.arg package} argument." - )) + ), + call = get_cli_abort_call()) } # calculate results and return df in cards formats --------------------------- diff --git a/R/ard_stats_prop_test.R b/R/ard_stats_prop_test.R index a08081903..c0d051e6d 100644 --- a/R/ard_stats_prop_test.R +++ b/R/ard_stats_prop_test.R @@ -63,7 +63,8 @@ ard_stats_prop_test <- function(data, by, variables, ...) { cli::cli_abort(c( "The {.arg by} column must have exactly 2 levels.", "The levels are {.val {data_counts[[by]]}}" - )) + ), + call = get_cli_abort_call()) } stats::prop.test( diff --git a/R/ard_stats_t_test.R b/R/ard_stats_t_test.R index 194b9cd30..823f0ce46 100644 --- a/R/ard_stats_t_test.R +++ b/R/ard_stats_t_test.R @@ -194,7 +194,6 @@ ard_stats_paired_t_test <- function(data, by, variables, id, ...) { #' @param by (`string`)\cr by column name #' @param variable (`string`)\cr variable column name #' @param id (`string`)\cr subject id column name -#' @param env (`environment`) used for error messaging. Default is `rlang::caller_env()` #' #' @return a wide data frame #' @keywords internal @@ -204,10 +203,11 @@ ard_stats_paired_t_test <- function(data, by, variables, id, ...) { #' dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> #' dplyr::arrange(USUBJID, ARM) |> #' cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID") -.paired_data_pivot_wider <- function(data, by, variable, id, env = rlang::caller_env()) { +.paired_data_pivot_wider <- function(data, by, variable, id) { # check the number of levels before pivoting data to wider format if (dplyr::n_distinct(data[[by]], na.rm = TRUE) != 2L) { - cli::cli_abort("The {.arg by} argument must have two and only two levels.", call = env) + cli::cli_abort("The {.arg by} argument must have two and only two levels.", + call = get_cli_abort_call()) } data |> diff --git a/R/ard_stats_wilcox_test.R b/R/ard_stats_wilcox_test.R index 67c39fd46..972131fc9 100644 --- a/R/ard_stats_wilcox_test.R +++ b/R/ard_stats_wilcox_test.R @@ -197,40 +197,6 @@ ard_stats_paired_wilcox_test <- function(data, by, variables, id, ...) { } -#' Convert long paired data to wide -#' -#' -#' @param data (`data.frame`)\cr a data frame that is one line per subject per group -#' @param by (`string`)\cr by column name -#' @param variable (`string`)\cr variable column name -#' @param id (`string`)\cr subject id column name -#' @param env (`environment`) used for error messaging. Default is `rlang::caller_env()` -#' -#' @return a wide data frame -#' @keywords internal -#' @examples -#' cards::ADSL[c("ARM", "AGE")] |> -#' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> -#' dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> -#' dplyr::arrange(USUBJID, ARM) |> -#' cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID") -.paired_data_pivot_wider <- function(data, by, variable, id, env = rlang::caller_env()) { - # check the number of levels before pivoting data to wider format - if (dplyr::n_distinct(data[[by]], na.rm = TRUE) != 2L) { - cli::cli_abort("The {.arg by} argument must have two and only two levels.", call = env) - } - - data |> - # arrange data so the first group always appears first - dplyr::arrange(.data[[by]]) |> - tidyr::pivot_wider( - id_cols = all_of(id), - names_from = all_of(by), - values_from = all_of(variable) - ) |> - stats::setNames(c(id, "by1", "by2")) -} - .df_wilcoxtest_stat_labels <- function(by = NULL) { dplyr::tribble( ~stat_name, ~stat_label, diff --git a/R/ard_survival_survfit.R b/R/ard_survival_survfit.R index 4b0eeebde..4d6d62c54 100644 --- a/R/ard_survival_survfit.R +++ b/R/ard_survival_survfit.R @@ -68,12 +68,14 @@ ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { check_not_missing(x) check_class(x, cls = "survfit") if (inherits(x, "survfitcox")) { - cli::cli_abort("Argument {.arg x} cannot be class {.cls survfitcox}.") + cli::cli_abort("Argument {.arg x} cannot be class {.cls survfitcox}.", + call = get_cli_abort_call()) } # competing risks models cannot use the type argument if (inherits(x, c("survfitms", "survfitcoxms")) && !is.null(type)) { - cli::cli_abort("Cannot use {.arg type} argument with {.code survfit} models with class {.cls {c('survfitms', 'survfitcoxms')}}.") + cli::cli_abort("Cannot use {.arg type} argument with {.code survfit} models with class {.cls {c('survfitms', 'survfitcoxms')}}.", + call = get_cli_abort_call()) } if (!is.null(probs)) check_range(probs, c(0, 1)) if (sum(is.null(times), is.null(probs)) != 1) { @@ -87,7 +89,8 @@ ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { # cannot specify type arg when probs supplied if (!is.null(probs) && !is.null(type)) { - cli::cli_abort("Cannot use {.arg type} argument when {.arg probs} argument specifed.") + cli::cli_abort("Cannot use {.arg type} argument when {.arg probs} argument specifed.", + call = get_cli_abort_call()) } # build ARD ------------------------------------------------------------------ diff --git a/man/dot-paired_data_pivot_wider.Rd b/man/dot-paired_data_pivot_wider.Rd index 4de078355..e51632add 100644 --- a/man/dot-paired_data_pivot_wider.Rd +++ b/man/dot-paired_data_pivot_wider.Rd @@ -1,12 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_stats_t_test.R, R/ard_stats_wilcox_test.R +% Please edit documentation in R/ard_stats_t_test.R \name{.paired_data_pivot_wider} \alias{.paired_data_pivot_wider} \title{Convert long paired data to wide} \usage{ -.paired_data_pivot_wider(data, by, variable, id, env = rlang::caller_env()) - -.paired_data_pivot_wider(data, by, variable, id, env = rlang::caller_env()) +.paired_data_pivot_wider(data, by, variable, id) } \arguments{ \item{data}{(\code{data.frame})\cr a data frame that is one line per subject per group} @@ -16,25 +14,14 @@ \item{variable}{(\code{string})\cr variable column name} \item{id}{(\code{string})\cr subject id column name} - -\item{env}{(\code{environment}) used for error messaging. Default is \code{rlang::caller_env()}} } \value{ -a wide data frame - a wide data frame } \description{ -Convert long paired data to wide - Convert long paired data to wide } \examples{ -cards::ADSL[c("ARM", "AGE")] |> - dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> - dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> - dplyr::arrange(USUBJID, ARM) |> - cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID") cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> From e04c13a21d819b45e2f3cf8082b57d6f3eba2ece Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Sun, 14 Apr 2024 18:22:48 -0700 Subject: [PATCH 14/14] style --- R/ard_aod_wald_test.R | 3 ++- R/ard_car_anova.R | 12 +++++++----- R/ard_stats_anova.R | 12 +++++++----- R/ard_stats_prop_test.R | 12 +++++++----- R/ard_stats_t_test.R | 3 ++- R/ard_survival_survfit.R | 9 ++++++--- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/R/ard_aod_wald_test.R b/R/ard_aod_wald_test.R index e1e41ee58..6e068c82c 100644 --- a/R/ard_aod_wald_test.R +++ b/R/ard_aod_wald_test.R @@ -35,7 +35,8 @@ ard_aod_wald_test <- function(x, ...) { if (!is.null(reg_model[["error"]])) { cli::cli_abort( c("Unable to identify underlying variable names in regression model.", - i = "Is this model type supported by {.fun broom.helpers::tidy_plus_plus}, which is the function used to identify variable names?"), + i = "Is this model type supported by {.fun broom.helpers::tidy_plus_plus}, which is the function used to identify variable names?" + ), call = get_cli_abort_call() ) } diff --git a/R/ard_car_anova.R b/R/ard_car_anova.R index 8e8854ec3..2b4f91270 100644 --- a/R/ard_car_anova.R +++ b/R/ard_car_anova.R @@ -27,11 +27,13 @@ ard_car_anova <- function(x, ...) { car_anova <- cards::eval_capture_conditions(car::Anova(x, ...)) if (!is.null(car_anova[["error"]])) { - cli::cli_abort(c( - "There was an error running {.fun car::Anova}. See error message below.", - x = car_anova[["error"]] - ), - call = get_cli_abort_call()) + cli::cli_abort( + c( + "There was an error running {.fun car::Anova}. See error message below.", + x = car_anova[["error"]] + ), + call = get_cli_abort_call() + ) } car_anova[["result"]] |> diff --git a/R/ard_stats_anova.R b/R/ard_stats_anova.R index 822fece1d..ac05a55bb 100644 --- a/R/ard_stats_anova.R +++ b/R/ard_stats_anova.R @@ -115,11 +115,13 @@ ard_stats_anova.data.frame <- function(x, check_data_frame(x) check_string(fn) if (str_detect(fn, "::")) { - cli::cli_abort(c( - "Argument {.arg fn} cannot be namespaced.", - i = "Put the package name in the {.arg package} argument." - ), - call = get_cli_abort_call()) + cli::cli_abort( + c( + "Argument {.arg fn} cannot be namespaced.", + i = "Put the package name in the {.arg package} argument." + ), + call = get_cli_abort_call() + ) } # calculate results and return df in cards formats --------------------------- diff --git a/R/ard_stats_prop_test.R b/R/ard_stats_prop_test.R index c0d051e6d..ce3958c89 100644 --- a/R/ard_stats_prop_test.R +++ b/R/ard_stats_prop_test.R @@ -60,11 +60,13 @@ ard_stats_prop_test <- function(data, by, variables, ...) { ) if (nrow(data_counts) != 2) { - cli::cli_abort(c( - "The {.arg by} column must have exactly 2 levels.", - "The levels are {.val {data_counts[[by]]}}" - ), - call = get_cli_abort_call()) + cli::cli_abort( + c( + "The {.arg by} column must have exactly 2 levels.", + "The levels are {.val {data_counts[[by]]}}" + ), + call = get_cli_abort_call() + ) } stats::prop.test( diff --git a/R/ard_stats_t_test.R b/R/ard_stats_t_test.R index 823f0ce46..b6ce34430 100644 --- a/R/ard_stats_t_test.R +++ b/R/ard_stats_t_test.R @@ -207,7 +207,8 @@ ard_stats_paired_t_test <- function(data, by, variables, id, ...) { # check the number of levels before pivoting data to wider format if (dplyr::n_distinct(data[[by]], na.rm = TRUE) != 2L) { cli::cli_abort("The {.arg by} argument must have two and only two levels.", - call = get_cli_abort_call()) + call = get_cli_abort_call() + ) } data |> diff --git a/R/ard_survival_survfit.R b/R/ard_survival_survfit.R index 4d6d62c54..909ab8dd7 100644 --- a/R/ard_survival_survfit.R +++ b/R/ard_survival_survfit.R @@ -69,13 +69,15 @@ ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { check_class(x, cls = "survfit") if (inherits(x, "survfitcox")) { cli::cli_abort("Argument {.arg x} cannot be class {.cls survfitcox}.", - call = get_cli_abort_call()) + call = get_cli_abort_call() + ) } # competing risks models cannot use the type argument if (inherits(x, c("survfitms", "survfitcoxms")) && !is.null(type)) { cli::cli_abort("Cannot use {.arg type} argument with {.code survfit} models with class {.cls {c('survfitms', 'survfitcoxms')}}.", - call = get_cli_abort_call()) + call = get_cli_abort_call() + ) } if (!is.null(probs)) check_range(probs, c(0, 1)) if (sum(is.null(times), is.null(probs)) != 1) { @@ -90,7 +92,8 @@ ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { # cannot specify type arg when probs supplied if (!is.null(probs) && !is.null(type)) { cli::cli_abort("Cannot use {.arg type} argument when {.arg probs} argument specifed.", - call = get_cli_abort_call()) + call = get_cli_abort_call() + ) } # build ARD ------------------------------------------------------------------