├── .Rbuildignore ├── .github ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── cran-release.yml │ ├── feature.yml │ └── release.yml ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── R-CMD-check.yaml │ ├── check.yaml │ ├── cla.yaml │ ├── docs.yaml │ ├── post-release.yaml │ ├── recheck.yml │ ├── release.yaml │ ├── scheduled.yaml │ └── test-coverage.yaml ├── .gitignore ├── .gitlab-ci.yml ├── CRAN-SUBMISSION ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── add_total_n.survey.design.R ├── ard_aod_wald_test.R ├── ard_attributes.survey.design.R ├── ard_car_anova.R ├── ard_car_vif.R ├── ard_categorical.survey.design.R ├── ard_categorical_ci.R ├── ard_categorical_ci.survey.design.R ├── ard_categorical_max.R ├── ard_continuous.survey.design.R ├── ard_continuous_ci.R ├── ard_continuous_ci.survey.design.R ├── ard_dichotomous.survey.design.R ├── ard_effectsize_cohens_d.R ├── ard_effectsize_hedges_g.R ├── ard_emmeans_mean_difference.R ├── ard_incidence_rate.R ├── ard_missing.survey.design.R ├── ard_regression.R ├── ard_regression_basic.R ├── ard_smd_smd.R ├── ard_stats_anova.R ├── ard_stats_aov.R ├── ard_stats_chisq_test.R ├── ard_stats_fisher_test.R ├── ard_stats_kruskal_test.R ├── ard_stats_mantelhaen_test.R ├── ard_stats_mcnemar_test.R ├── ard_stats_mood_test.R ├── ard_stats_oneway_test.R ├── ard_stats_poisson_test.R ├── ard_stats_prop_test.R ├── ard_stats_t_test.R ├── ard_stats_t_test_onesample.R ├── ard_stats_wilcox_test.R ├── ard_stats_wilcox_test_onesample.R ├── ard_survey_svychisq.R ├── ard_survey_svyranktest.R ├── ard_survey_svyttest.R ├── ard_survival_survdiff.R ├── ard_survival_survfit.R ├── ard_survival_survfit_diff.R ├── cardx-package.R ├── construction_helpers.R ├── import-standalone-check_pkg_installed.R ├── import-standalone-checks.R ├── import-standalone-cli_call_env.R ├── import-standalone-forcats.R ├── import-standalone-purrr.R ├── import-standalone-stringr.R ├── import-standalone-tibble.R ├── proportion_ci.R └── reexports.R ├── README.Rmd ├── README.md ├── SECURITY.md ├── _pkgdown.yml ├── cardx.Rproj ├── codecov.yml ├── cran-comments.md ├── data-raw └── cardx-hex-sticker.png ├── inst └── WORDLIST ├── man ├── ard_aod_wald_test.Rd ├── ard_attributes.Rd ├── ard_car_anova.Rd ├── ard_car_vif.Rd ├── ard_categorical.survey.design.Rd ├── ard_categorical_ci.Rd ├── ard_categorical_ci.survey.design.Rd ├── ard_categorical_max.Rd ├── ard_continuous.survey.design.Rd ├── ard_continuous_ci.Rd ├── ard_continuous_ci.survey.design.Rd ├── ard_dichotomous.survey.design.Rd ├── ard_effectsize_cohens_d.Rd ├── ard_effectsize_hedges_g.Rd ├── ard_emmeans_mean_difference.Rd ├── ard_incidence_rate.Rd ├── ard_missing.survey.design.Rd ├── ard_regression.Rd ├── ard_regression_basic.Rd ├── ard_smd_smd.Rd ├── ard_stats_anova.Rd ├── ard_stats_aov.Rd ├── ard_stats_chisq_test.Rd ├── ard_stats_fisher_test.Rd ├── ard_stats_kruskal_test.Rd ├── ard_stats_mantelhaen_test.Rd ├── ard_stats_mcnemar_test.Rd ├── ard_stats_mood_test.Rd ├── ard_stats_oneway_test.Rd ├── ard_stats_poisson_test.Rd ├── ard_stats_prop_test.Rd ├── ard_stats_t_test.Rd ├── ard_stats_t_test_onesample.Rd ├── ard_stats_wilcox_test.Rd ├── ard_stats_wilcox_test_onesample.Rd ├── ard_survey_svychisq.Rd ├── ard_survey_svyranktest.Rd ├── ard_survey_svyttest.Rd ├── ard_survival_survdiff.Rd ├── ard_survival_survfit.Rd ├── ard_survival_survfit_diff.Rd ├── ard_total_n.survey.design.Rd ├── cardx-package.Rd ├── construction_helpers.Rd ├── dot-check_dichotomous_value.Rd ├── dot-extract_wald_results.Rd ├── dot-format_cohens_d_results.Rd ├── dot-format_hedges_g_results.Rd ├── dot-format_mcnemartest_results.Rd ├── dot-format_moodtest_results.Rd ├── dot-format_poissontest_results.Rd ├── dot-format_proptest_results.Rd ├── dot-format_survfit_results.Rd ├── dot-format_ttest_results.Rd ├── dot-format_wilcoxtest_results.Rd ├── dot-paired_data_pivot_wider.Rd ├── dot-process_nested_list_as_df.Rd ├── dot-process_survfit_probs.Rd ├── dot-process_survfit_time.Rd ├── dot-strata_normal_quantile.Rd ├── dot-unique_and_sorted.Rd ├── dot-update_weights_strat_wilson.Rd ├── figures │ ├── lifecycle-archived.svg │ ├── lifecycle-defunct.svg │ ├── lifecycle-deprecated.svg │ ├── lifecycle-experimental.svg │ ├── lifecycle-maturing.svg │ ├── lifecycle-questioning.svg │ ├── lifecycle-soft-deprecated.svg │ ├── lifecycle-stable.svg │ ├── lifecycle-superseded.svg │ └── logo.png ├── proportion_ci.Rd └── reexports.Rd ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── favicon-96x96.png │ ├── favicon.ico │ ├── favicon.svg │ ├── site.webmanifest │ ├── web-app-manifest-192x192.png │ └── web-app-manifest-512x512.png ├── revdep ├── .gitignore ├── README.md ├── cran.md ├── failures.md └── problems.md └── tests ├── testthat.R └── testthat ├── _snaps ├── ard_aod_wald_test.md ├── ard_attributes.survey.design.md ├── ard_car_anova.md ├── ard_car_vif.md ├── ard_categorical.survey.design.md ├── ard_categorical_ci.survey.design.md ├── ard_categorical_max.md ├── ard_continuous.survey.design.md ├── ard_continuous_ci.survey.design.md ├── ard_dichotomous.survey.design.md ├── ard_effectsize_cohens_d.md ├── ard_effectsize_hedges_g.md ├── ard_emmeans_mean_difference.md ├── ard_incidence_rate.md ├── ard_proportion_ci.md ├── ard_regression.md ├── ard_regression_basic.md ├── ard_stats_aov.md ├── ard_stats_kruskal_test.md ├── ard_stats_mantelhaen_test.md ├── ard_stats_mood_test.md ├── ard_stats_oneway_test.md ├── ard_stats_poisson_test.md ├── ard_survey_svychisq.md ├── ard_survey_svyranktest.md ├── ard_survival_survfit.md ├── ard_survival_survfit_diff.md ├── ard_total_n.survey.design.md ├── construction_helpers.md └── proportion_ci.md ├── test-ard_aod_wald_test.R ├── test-ard_attributes.survey.design.R ├── test-ard_car_anova.R ├── test-ard_car_vif.R ├── test-ard_categorical.survey.design.R ├── test-ard_categorical_ci.data.frame.R ├── test-ard_categorical_ci.survey.design.R ├── test-ard_categorical_max.R ├── test-ard_continuous.survey.design.R ├── test-ard_continuous_ci.data.frame.R ├── test-ard_continuous_ci.survey.design.R ├── test-ard_dichotomous.survey.design.R ├── test-ard_effectsize_cohens_d.R ├── test-ard_effectsize_hedges_g.R ├── test-ard_emmeans_mean_difference.R ├── test-ard_incidence_rate.R ├── test-ard_missing.survey.design.R ├── test-ard_proportion_ci.R ├── test-ard_regression.R ├── test-ard_regression_basic.R ├── test-ard_smd_smd.R ├── test-ard_stats_anova.R ├── test-ard_stats_aov.R ├── test-ard_stats_chisq_test.R ├── test-ard_stats_fisher_test.R ├── test-ard_stats_kruskal_test.R ├── test-ard_stats_mantelhaen_test.R ├── test-ard_stats_mcnemar_test.R ├── test-ard_stats_mood_test.R ├── test-ard_stats_oneway_test.R ├── test-ard_stats_poisson_test.R ├── test-ard_stats_prop_test.R ├── test-ard_stats_t_test.R ├── test-ard_stats_t_test_onesample.R ├── test-ard_stats_wilcox_test.R ├── test-ard_stats_wilcox_test_onesample.R ├── test-ard_survey_svychisq.R ├── test-ard_survey_svyranktest.R ├── test-ard_survey_svyttest.R ├── test-ard_survival_survdiff.R ├── test-ard_survival_survfit.R ├── test-ard_survival_survfit_diff.R ├── test-ard_total_n.survey.design.R ├── test-construction_helpers.R └── test-proportion_ci.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | # cicd 2 | ^\.pre-commit-config\.yaml$ 3 | 4 | # data 5 | ^data-raw$ 6 | 7 | # doc 8 | ^CODE_OF_CONDUCT\.md$ 9 | ^docs$ 10 | LICENSE 11 | ^LICENSE\.md$ 12 | ^SECURITY\.md$ 13 | 14 | # git 15 | ^\.git$ 16 | ^\.github$ 17 | ^\.gitlab-ci\.yml$ 18 | ^codecov\.yml$ 19 | 20 | # lintr 21 | ^\.lintr$ 22 | 23 | # pkgdown 24 | ^_pkgdown\.yml$ 25 | pkgdown 26 | ^pkgdown$ 27 | 28 | # rstudio 29 | ^.*\.Rproj$ 30 | ^\.Rproj\.user$ 31 | 32 | # staded dependencies 33 | ^staged_dependencies\.yaml$ 34 | 35 | # others 36 | ^renv$ 37 | ^renv\.lock$ 38 | ^README\.Rmd$ 39 | ^.revdeprefs\.yaml$ 40 | ^revdep$ 41 | ^\.covrignore$ 42 | ^cran-comments\.md$ 43 | ^CRAN-SUBMISSION$ 44 | 45 | # reverse dep cehcks 46 | ^checked$ 47 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: File a bug report. 3 | title: 'Bug Report: ' 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Do not use this form to ask a question, or ask for assistance. Instead, ask on using the `r-cards` tag. 9 | - type: textarea 10 | id: what-happened 11 | attributes: 12 | label: What happened? 13 | description: INCLUDE a *minimal* reproducible example (AKA a reprex). If you've never heard of a [reprex](https://reprex.tidyverse.org/) before, start by reading . It'll take minutes to master creating a reprex. 14 | placeholder: Tell us what you see! 15 | value: "Brief description of the problem." 16 | validations: 17 | required: true 18 | 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: Ask a Question 4 | url: https://stackoverflow.com/questions/ask?tags=r-cards,r 5 | about: Question must include a minimal reproducible example, aka a reprex. 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.yml: -------------------------------------------------------------------------------- 1 | name: ✨ Feature Request 2 | description: Request or propose a new feature 3 | title: 'Feature Request: ' 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Do not use this form to ask a question, or ask for assistance. Instead, ask on using the `r-cards` tag. 9 | - type: textarea 10 | id: feature 11 | attributes: 12 | label: What's the feature? 13 | description: Describe the feature and, if applicable, create a mock-up of what you'd like to see. 14 | placeholder: Tell us what you see! 15 | value: "Brief description of the feature request." 16 | validations: 17 | required: true 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **What changes are proposed in this pull request?** 2 | * Style this entry in a way that can be copied directly into `NEWS.md`. (#, @) 3 | 4 | Provide more detail here as needed. 5 | 6 | **Reference GitHub issue associated with pull request.** _e.g., 'closes #'_ 7 | 8 | 9 | -------------------------------------------------------------------------------- 10 | 11 | Pre-review Checklist (if item does not apply, mark is as complete) 12 | - [ ] **All** GitHub Action workflows pass with a :white_check_mark: 13 | - [ ] PR branch has pulled the most recent updates from master branch: `usethis::pr_merge_main()` 14 | - [ ] If a bug was fixed, a unit test was added. 15 | - [ ] If a new `ard_*()` function was added, it passes the ARD structural checks from `cards::check_ard_structure()`. 16 | - [ ] If a new `ard_*()` function was added, `set_cli_abort_call()` has been set. 17 | - [ ] If a new `ard_*()` function was added and it depends on another package (such as, `broom`), `is_pkg_installed("broom")` has been set in the function call and the following added to the roxygen comments: `@examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom""))` 18 | - [ ] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()` 19 | 20 | Reviewer Checklist (if item does not apply, mark is as complete) 21 | 22 | - [ ] If a bug was fixed, a unit test was added. 23 | - [ ] Code coverage is suitable for any new functions/features: `devtools::test_coverage()` 24 | 25 | When the branch is ready to be merged: 26 | - [ ] 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). 27 | - [ ] **All** GitHub Action workflows pass with a :white_check_mark: 28 | - [ ] Approve Pull Request 29 | - [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge". 30 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | # 4 | # NOTE: This workflow is overkill for most R packages and 5 | # check-standard.yaml is likely a better choice. 6 | # usethis::use_github_action("check-standard") will install it. 7 | on: 8 | push: 9 | branches: [main, master] 10 | pull_request: 11 | 12 | name: R-CMD-check 13 | 14 | jobs: 15 | R-CMD-check: 16 | runs-on: ${{ matrix.config.os }} 17 | 18 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 19 | 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | config: 24 | - {os: macos-latest, r: 'release'} 25 | 26 | - {os: windows-latest, r: 'release'} 27 | # use 4.1 to check with rtools40's older compiler 28 | # - {os: windows-latest, r: '4.1'} 29 | 30 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 31 | - {os: ubuntu-latest, r: 'release'} 32 | - {os: ubuntu-latest, r: 'oldrel-1'} 33 | # - {os: ubuntu-latest, r: 'oldrel-2'} 34 | # - {os: ubuntu-latest, r: 'oldrel-3'} 35 | # - {os: ubuntu-latest, r: 'oldrel-4'} 36 | 37 | env: 38 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 39 | R_KEEP_PKG_SOURCE: yes 40 | 41 | steps: 42 | - uses: actions/checkout@v3 43 | 44 | - uses: r-lib/actions/setup-pandoc@v2 45 | 46 | - uses: r-lib/actions/setup-r@v2 47 | with: 48 | r-version: ${{ matrix.config.r }} 49 | http-user-agent: ${{ matrix.config.http-user-agent }} 50 | use-public-rspm: true 51 | 52 | - uses: r-lib/actions/setup-r-dependencies@v2 53 | with: 54 | extra-packages: any::rcmdcheck 55 | needs: check 56 | 57 | # https://github.com/lme4/lme4/issues/763 58 | - name: Install Matrix/lme4 59 | shell: Rscript {0} 60 | run: | 61 | utils::install.packages("Matrix", repos = c(CRAN = "https://cloud.r-project.org")) 62 | utils::install.packages("lme4", repos = c(CRAN = "https://cloud.r-project.org")) 63 | 64 | - uses: r-lib/actions/check-r-package@v2 65 | with: 66 | upload-snapshots: true 67 | -------------------------------------------------------------------------------- /.github/workflows/cla.yaml: -------------------------------------------------------------------------------- 1 | name: CLA 🔏 2 | 3 | on: 4 | issue_comment: 5 | types: 6 | - created 7 | # For PRs that originate from forks 8 | pull_request_target: 9 | types: 10 | - opened 11 | - closed 12 | - synchronize 13 | 14 | jobs: 15 | CLA: 16 | name: CLA 📝 17 | uses: insightsengineering/.github/.github/workflows/cla.yaml@main 18 | secrets: inherit 19 | -------------------------------------------------------------------------------- /.github/workflows/docs.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Docs 📚 3 | 4 | on: 5 | push: 6 | branches: 7 | - main 8 | paths: 9 | - "inst/templates/**" 10 | - "_pkgdown.*" 11 | - DESCRIPTION 12 | - "**.md" 13 | - "**.Rmd" 14 | - "man/**" 15 | - "LICENSE.*" 16 | - NAMESPACE 17 | pull_request: 18 | types: 19 | - opened 20 | - synchronize 21 | - reopened 22 | - ready_for_review 23 | branches: 24 | - main 25 | paths: 26 | - "inst/templates/**" 27 | - "_pkgdown.*" 28 | - DESCRIPTION 29 | - "**.md" 30 | - "**.Rmd" 31 | - "man/**" 32 | - "LICENSE.*" 33 | - NAMESPACE 34 | workflow_dispatch: 35 | 36 | jobs: 37 | docs: 38 | name: Pkgdown Docs 📚 39 | uses: insightsengineering/r.pkg.template/.github/workflows/pkgdown.yaml@main 40 | secrets: 41 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 42 | with: 43 | default-landing-page: main 44 | additional-unit-test-report-directories: unit-test-report-non-cran 45 | -------------------------------------------------------------------------------- /.github/workflows/post-release.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Post release ✨ 3 | 4 | on: 5 | release: 6 | types: ["released"] 7 | 8 | jobs: 9 | vbump: 10 | name: Version Bump 🤜🤛 11 | uses: insightsengineering/r.pkg.template/.github/workflows/version-bump.yaml@main 12 | secrets: 13 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 14 | with: 15 | vbump-after-release: true 16 | -------------------------------------------------------------------------------- /.github/workflows/recheck.yml: -------------------------------------------------------------------------------- 1 | on: 2 | workflow_dispatch: 3 | inputs: 4 | which: 5 | type: choice 6 | description: Which dependents to check 7 | options: 8 | - strong 9 | - most 10 | 11 | name: Reverse dependency check 12 | 13 | jobs: 14 | revdep_check: 15 | name: Reverse check ${{ inputs.which }} dependents 16 | uses: r-devel/recheck/.github/workflows/recheck.yml@v1 17 | with: 18 | which: ${{ inputs.which }} 19 | subdirectory: '' #if your package is in a git subdir 20 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release 🎈 3 | 4 | on: 5 | push: 6 | tags: 7 | - "v*" 8 | workflow_dispatch: 9 | 10 | jobs: 11 | docs: 12 | name: Pkgdown Docs 📚 13 | needs: release 14 | uses: insightsengineering/r.pkg.template/.github/workflows/pkgdown.yaml@main 15 | secrets: 16 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 17 | with: 18 | default-landing-page: latest-tag 19 | validation: 20 | name: R Package Validation report 📃 21 | needs: release 22 | uses: insightsengineering/r.pkg.template/.github/workflows/validation.yaml@main 23 | secrets: 24 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 25 | release: 26 | name: Create release 🎉 27 | uses: insightsengineering/r.pkg.template/.github/workflows/release.yaml@main 28 | secrets: 29 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 30 | build: 31 | name: Build package and reports 🎁 32 | needs: [release, docs] 33 | uses: insightsengineering/r.pkg.template/.github/workflows/build-check-install.yaml@main 34 | secrets: 35 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 36 | with: 37 | additional-env-vars: | 38 | _R_CHECK_CRAN_INCOMING_REMOTE_=false 39 | additional-r-cmd-check-params: --as-cran 40 | enforce-note-blocklist: true 41 | note-blocklist: | 42 | checking dependencies in R code .* NOTE 43 | checking R code for possible problems .* NOTE 44 | checking examples .* NOTE 45 | checking Rd line widths .* NOTE 46 | checking top-level files .* NOTE 47 | coverage: 48 | name: Coverage 📔 49 | needs: [release, docs] 50 | uses: insightsengineering/r.pkg.template/.github/workflows/test-coverage.yaml@main 51 | secrets: 52 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 53 | with: 54 | additional-env-vars: | 55 | NOT_CRAN=true 56 | wasm: 57 | name: Build WASM packages 🧑‍🏭 58 | needs: release 59 | uses: insightsengineering/r.pkg.template/.github/workflows/wasm.yaml@main 60 | -------------------------------------------------------------------------------- /.github/workflows/scheduled.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Scheduled 🕰️ 3 | 4 | on: 5 | schedule: 6 | - cron: '45 3 * * 0' 7 | workflow_dispatch: 8 | inputs: 9 | chosen-workflow: 10 | description: | 11 | Select which workflow you'd like to run 12 | required: true 13 | type: choice 14 | default: rhub 15 | options: 16 | - rhub 17 | - dependency-test 18 | - branch-cleanup 19 | - revdepcheck 20 | 21 | jobs: 22 | dependency-test: 23 | if: > 24 | github.event_name == 'schedule' || ( 25 | github.event_name == 'workflow_dispatch' && 26 | inputs.chosen-workflow == 'dependency-test' 27 | ) 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | test-strategy: ["min_cohort", "min_isolated", "release", "max"] 32 | uses: insightsengineering/r.pkg.template/.github/workflows/verdepcheck.yaml@main 33 | name: Dependency Test - ${{ matrix.test-strategy }} 🔢 34 | secrets: 35 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 36 | GCHAT_WEBHOOK: ${{ secrets.GCHAT_WEBHOOK }} 37 | with: 38 | strategy: ${{ matrix.test-strategy }} 39 | additional-env-vars: | 40 | PKG_SYSREQS_DRY_RUN=true 41 | branch-cleanup: 42 | if: > 43 | github.event_name == 'schedule' || ( 44 | github.event_name == 'workflow_dispatch' && 45 | inputs.chosen-workflow == 'branch-cleanup' 46 | ) 47 | name: Branch Cleanup 🧹 48 | uses: insightsengineering/r.pkg.template/.github/workflows/branch-cleanup.yaml@main 49 | secrets: 50 | REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }} 51 | with: 52 | last-commit-age-days: 365 53 | cran-status: 54 | name: CRAN Status Monitor 📺 55 | uses: insightsengineering/r.pkg.template/.github/workflows/cran-status.yaml@main 56 | with: 57 | issue-assignees: "ddsjoberg" 58 | revdepcheck: 59 | if: > 60 | github.event_name == 'schedule' || ( 61 | github.event_name == 'workflow_dispatch' && 62 | inputs.chosen-workflow == 'revdepcheck' 63 | ) 64 | name: revdepcheck ↩️ 65 | uses: insightsengineering/r.pkg.template/.github/workflows/revdepcheck.yaml@main 66 | rhub: 67 | if: > 68 | github.event_name == 'schedule' || ( 69 | github.event_name == 'workflow_dispatch' && 70 | inputs.chosen-workflow == 'rhub' 71 | ) 72 | name: R-hub 🌐 73 | uses: insightsengineering/r.pkg.template/.github/workflows/rhub.yaml@main 74 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | 8 | name: test-coverage.yaml 9 | 10 | permissions: read-all 11 | 12 | jobs: 13 | test-coverage: 14 | runs-on: ubuntu-latest 15 | env: 16 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - uses: r-lib/actions/setup-r@v2 22 | with: 23 | use-public-rspm: true 24 | 25 | - uses: r-lib/actions/setup-r-dependencies@v2 26 | with: 27 | extra-packages: any::covr, any::xml2 28 | needs: coverage 29 | 30 | - name: Test coverage 31 | run: | 32 | cov <- covr::package_coverage( 33 | quiet = FALSE, 34 | clean = FALSE, 35 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 36 | ) 37 | covr::to_cobertura(cov) 38 | shell: Rscript {0} 39 | 40 | - uses: codecov/codecov-action@v4 41 | with: 42 | # Fail if error if not on PR, or if on PR and token is given 43 | fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} 44 | file: ./cobertura.xml 45 | plugin: noop 46 | disable_search: true 47 | token: ${{ secrets.CODECOV_TOKEN }} 48 | 49 | - name: Show testthat output 50 | if: always() 51 | run: | 52 | ## -------------------------------------------------------------------- 53 | find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true 54 | shell: bash 55 | 56 | - name: Upload test results 57 | if: failure() 58 | uses: actions/upload-artifact@v4 59 | with: 60 | name: coverage-test-failures 61 | path: ${{ runner.temp }}/package 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # R-related 2 | .Rproj.user 3 | .Rhistory 4 | .RData 5 | .Ruserdata 6 | 7 | # docs 8 | inst/doc 9 | docs 10 | 11 | # others 12 | .DS_Store 13 | temp/ 14 | 15 | .pre-commit-config.yaml 16 | tests/testthat/_snaps/**/*.new.md 17 | tests/testthat/_snaps/**/*.new.svg 18 | 19 | # reverse dep cehcks 20 | checked/ 21 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | include: 3 | - project: 'nest/automation/gitlab-shared-library' 4 | ref: main 5 | file: R/R_NEST_min.gitlab-ci.yml 6 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.2.4 2 | Date: 2025-04-12 01:30:52 UTC 3 | SHA: 7eed4ab400e03eb6a5cd1ed1612cb2bd0bf8af55 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: cardx 2 | Title: Extra Analysis Results Data Utilities 3 | Version: 0.2.4.9004 4 | Authors@R: c( 5 | person("Daniel D.", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre"), 6 | comment = c(ORCID = "0000-0003-0862-2018")), 7 | person("Abinaya", "Yogasekaram", , "abinaya.yogasekaram@contractors.roche.com", role = "aut"), 8 | person("Emily", "de la Rua", , "emily.de_la_rua@contractors.roche.com", role = "aut"), 9 | person("F. Hoffmann-La Roche AG", role = c("cph", "fnd")) 10 | ) 11 | Description: Create extra Analysis Results Data (ARD) summary objects. 12 | The package supplements the simple ARD functions from the 'cards' 13 | package, exporting functions to put statistical results in the ARD 14 | format. These objects are used and re-used to construct summary 15 | tables, visualizations, and written reports. 16 | License: Apache License 2.0 17 | URL: https://github.com/insightsengineering/cardx, 18 | https://insightsengineering.github.io/cardx/ 19 | BugReports: https://github.com/insightsengineering/cardx/issues 20 | Depends: 21 | R (>= 4.2) 22 | Imports: 23 | cards (>= 0.5.1), 24 | cli (>= 3.6.1), 25 | dplyr (>= 1.1.2), 26 | glue (>= 1.6.2), 27 | lifecycle (>= 1.0.3), 28 | rlang (>= 1.1.1), 29 | tidyr (>= 1.3.0) 30 | Suggests: 31 | aod (>= 1.3.3), 32 | broom (>= 1.0.8), 33 | broom.helpers (>= 1.17.0), 34 | broom.mixed (>= 0.2.9), 35 | car (>= 3.1-2), 36 | effectsize (>= 0.8.8), 37 | emmeans (>= 1.7.3), 38 | geepack (>= 1.3.2), 39 | ggsurvfit (>= 1.1.0), 40 | lme4 (>= 1.1-37), 41 | parameters (>= 0.20.2), 42 | smd (>= 0.6.6), 43 | survey (>= 4.2), 44 | survival (>= 3.6-4), 45 | testthat (>= 3.2.0), 46 | withr (>= 2.5.0) 47 | Config/Needs/website: insightsengineering/nesttemplate 48 | Config/testthat/edition: 3 49 | Config/testthat/parallel: true 50 | Encoding: UTF-8 51 | Language: en-US 52 | LazyData: true 53 | Roxygen: list(markdown = TRUE) 54 | RoxygenNote: 7.3.2 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2024 F. Hoffmann-La Roche AG 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /R/add_total_n.survey.design.R: -------------------------------------------------------------------------------- 1 | #' ARD Total N 2 | #' 3 | #' Returns the total N for a survey object. 4 | #' The placeholder variable name returned in the object is `"..ard_total_n.."` 5 | #' 6 | #' @inheritParams ard_dichotomous.survey.design 7 | #' @inheritParams rlang::args_dots_empty 8 | #' 9 | #' @return an ARD data frame of class 'card' 10 | #' @export 11 | #' 12 | #' @examplesIf cardx:::is_pkg_installed("survey") 13 | #' svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) 14 | #' 15 | #' ard_total_n(svy_titanic) 16 | ard_total_n.survey.design <- function(data, ...) { 17 | # process inputs ------------------------------------------------------------- 18 | set_cli_abort_call() 19 | check_dots_empty() 20 | 21 | # calculate total N ---------------------------------------------------------- 22 | data$variables <- 23 | data$variables |> 24 | dplyr::mutate(..ard_total_n.. = TRUE) 25 | 26 | data |> 27 | ard_dichotomous( 28 | variables = "..ard_total_n..", 29 | statistic = list(..ard_total_n.. = c("N", "N_unweighted")) 30 | ) |> 31 | dplyr::mutate(context = "total_n") |> 32 | dplyr::select(-cards::all_ard_variables("levels")) 33 | } 34 | -------------------------------------------------------------------------------- /R/ard_attributes.survey.design.R: -------------------------------------------------------------------------------- 1 | #' ARD Attributes 2 | #' 3 | #' @description 4 | #' Add variable attributes to an ARD data frame. 5 | #' - The `label` attribute will be added for all columns, and when no label 6 | #' is specified and no label has been set for a column using the `label=` argument, 7 | #' the column name will be placed in the label statistic. 8 | #' - The `class` attribute will also be returned for all columns. 9 | #' - Any other attribute returned by `attributes()` will also be added, e.g. factor levels. 10 | #' 11 | #' @rdname ard_attributes 12 | #' @param data (`survey.design`)\cr 13 | #' a design object often created with [`survey::svydesign()`]. 14 | #' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr 15 | #' variables to include 16 | #' @param label (named `list`)\cr 17 | #' named list of variable labels, e.g. `list(cyl = "No. Cylinders")`. 18 | #' Default is `NULL` 19 | #' @inheritParams rlang::args_dots_empty 20 | #' 21 | #' @return an ARD data frame of class 'card' 22 | #' @export 23 | #' 24 | #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survey")) 25 | #' data(api, package = "survey") 26 | #' dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) 27 | #' 28 | #' ard_attributes( 29 | #' data = dclus1, 30 | #' variables = c(sname, dname), 31 | #' label = list(sname = "School Name", dname = "District Name") 32 | #' ) 33 | ard_attributes.survey.design <- function(data, variables = everything(), label = NULL, ...) { 34 | set_cli_abort_call() 35 | 36 | cards::ard_attributes(data = data[["variables"]], variables = {{ variables }}, label = label, ...) 37 | } 38 | -------------------------------------------------------------------------------- /R/ard_car_anova.R: -------------------------------------------------------------------------------- 1 | #' ARD ANOVA from car Package 2 | #' 3 | #' Function takes a regression model object and calculated ANOVA using [`car::Anova()`]. 4 | #' 5 | #' @param x regression model object 6 | #' @param ... arguments passed to `car::Anova(...)` 7 | #' 8 | #' @return data frame 9 | #' @export 10 | #' 11 | #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom.helpers", "car", "parameters"))) 12 | #' lm(AGE ~ ARM, data = cards::ADSL) |> 13 | #' ard_car_anova() 14 | #' 15 | #' glm(vs ~ factor(cyl) + factor(am), data = mtcars, family = binomial) |> 16 | #' ard_car_anova(test.statistic = "Wald") 17 | ard_car_anova <- function(x, ...) { 18 | set_cli_abort_call() 19 | 20 | # check installed packages --------------------------------------------------- 21 | check_pkg_installed(pkg = c("broom.helpers", "car", "parameters")) 22 | 23 | # check inputs --------------------------------------------------------------- 24 | check_not_missing(x) 25 | 26 | # run car::Anova() ----------------------------------------------------------- 27 | car_anova <- cards::eval_capture_conditions(car::Anova(x, ...)) 28 | 29 | if (!is.null(car_anova[["error"]])) { 30 | cli::cli_abort( 31 | c( 32 | "There was an error running {.fun car::Anova}. See error message below.", 33 | x = car_anova[["error"]] 34 | ), 35 | call = get_cli_abort_call() 36 | ) 37 | } 38 | 39 | car_anova[["result"]] |> 40 | broom.helpers::tidy_parameters(conf.int = FALSE) |> # using broom.helpers, because it handle non-syntactic names for us 41 | dplyr::filter(!(dplyr::row_number() == dplyr::n() & .data$term %in% "Residuals")) |> # removing Residual rows 42 | dplyr::rename(variable = "term") |> 43 | tidyr::pivot_longer( 44 | cols = -"variable", 45 | names_to = "stat_name", 46 | values_to = "stat" 47 | ) |> 48 | dplyr::mutate( 49 | stat = as.list(.data$stat), 50 | stat_label = 51 | dplyr::case_when( 52 | .data$stat_name %in% "statistic" ~ "Statistic", 53 | .data$stat_name %in% "df" ~ "Degrees of Freedom", 54 | .data$stat_name %in% "p.value" ~ "p-value", 55 | TRUE ~ .data$stat_name 56 | ), 57 | fmt_fn = 58 | map( 59 | .data$stat, 60 | function(.x) { 61 | # styler: off 62 | if (is.integer(.x)) return(0L) 63 | if (is.numeric(.x)) return(1L) 64 | # styler: on 65 | NULL 66 | } 67 | ), 68 | context = "car_anova", 69 | warning = car_anova["warning"], 70 | error = car_anova["error"] 71 | ) |> 72 | cards::as_card() |> 73 | cards::tidy_ard_column_order() 74 | } 75 | -------------------------------------------------------------------------------- /R/ard_continuous_ci.R: -------------------------------------------------------------------------------- 1 | #' ARD continuous CIs 2 | #' 3 | #' One-sample confidence intervals for continuous variable means and medians. 4 | #' 5 | #' @inheritParams ard_stats_t_test 6 | #' @param method (`string`)\cr 7 | #' a string indicating the method to use for the confidence interval 8 | #' calculation. Must be one of `"t.test"` or `"wilcox.test"` 9 | #' @param ... arguments passed to `t.test()` or `wilcox.test()` 10 | #' 11 | #' @return ARD data frame 12 | #' @name ard_continuous_ci 13 | #' 14 | #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom")) 15 | #' ard_continuous_ci(mtcars, variables = c(mpg, hp), method = "wilcox.test") 16 | #' ard_continuous_ci(mtcars, variables = mpg, by = am, method = "t.test") 17 | NULL 18 | 19 | #' @rdname ard_continuous_ci 20 | #' @export 21 | ard_continuous_ci <- function(data, ...) { 22 | check_not_missing(data) 23 | UseMethod("ard_continuous_ci") 24 | } 25 | 26 | #' @rdname ard_continuous_ci 27 | #' @export 28 | ard_continuous_ci.data.frame <- function(data, variables, by = dplyr::group_vars(data), conf.level = 0.95, method = c("t.test", "wilcox.test"), ...) { 29 | set_cli_abort_call() 30 | 31 | # check inputs --------------------------------------------------------------- 32 | method <- arg_match(method) 33 | check_not_missing(variables) 34 | cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) 35 | 36 | # return empty ARD if no variables selected ---------------------------------- 37 | if (is_empty(variables)) { 38 | return(dplyr::tibble() |> cards::as_card()) 39 | } 40 | 41 | # calculate CIs -------------------------------------------------------------- 42 | switch(method, 43 | "t.test" = 44 | ard_stats_t_test_onesample( 45 | data = data, 46 | variables = {{ variables }}, 47 | by = {{ by }}, 48 | conf.level = conf.level, 49 | ... 50 | ), 51 | "wilcox.test" = 52 | ard_stats_wilcox_test_onesample( 53 | data = data, 54 | variables = {{ variables }}, 55 | by = {{ by }}, 56 | conf.level = conf.level, 57 | conf.int = TRUE, 58 | ... 59 | ) 60 | ) |> 61 | dplyr::mutate(context = "continuous_ci") 62 | } 63 | -------------------------------------------------------------------------------- /R/ard_stats_aov.R: -------------------------------------------------------------------------------- 1 | #' ARD ANOVA 2 | #' 3 | #' @description 4 | #' Analysis results data for Analysis of Variance. 5 | #' Calculated with `stats::aov()` 6 | #' 7 | #' @inheritParams stats::aov 8 | #' @param ... arguments passed to `stats::aov(...)` 9 | #' 10 | #' @return ARD data frame 11 | #' @export 12 | #' 13 | #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom.helpers", "parameters"))) 14 | #' ard_stats_aov(AGE ~ ARM, data = cards::ADSL) 15 | ard_stats_aov <- function(formula, data, ...) { 16 | set_cli_abort_call() 17 | 18 | # check installed packages --------------------------------------------------- 19 | check_pkg_installed(c("broom.helpers", "parameters")) 20 | 21 | # check/process inputs ------------------------------------------------------- 22 | check_not_missing(formula) 23 | check_not_missing(data) 24 | check_data_frame(data) 25 | check_class(formula, cls = "formula") 26 | 27 | # build ARD ------------------------------------------------------------------ 28 | aov <- 29 | cards::eval_capture_conditions( 30 | stats::aov(formula, data, ...) 31 | ) 32 | aov[["result"]] |> 33 | broom.helpers::tidy_parameters() |> # using broom.helpers, because it handle non-syntactic names 34 | dplyr::filter(!(dplyr::row_number() == dplyr::n() & .data$term %in% "Residuals")) |> # removing Residual rows 35 | dplyr::rename(variable = "term") |> 36 | tidyr::pivot_longer( 37 | cols = -"variable", 38 | names_to = "stat_name", 39 | values_to = "stat" 40 | ) |> 41 | dplyr::mutate( 42 | stat = as.list(.data$stat), 43 | stat_label = 44 | dplyr::case_when( 45 | .data$stat_name %in% "statistic" ~ "Statistic", 46 | .data$stat_name %in% "df" ~ "Degrees of Freedom", 47 | .data$stat_name %in% "p.value" ~ "p-value", 48 | .data$stat_name %in% "sumsq" ~ "Sum of Squares", 49 | .data$stat_name %in% "meansq" ~ "Mean of Sum of Squares", 50 | TRUE ~ .data$stat_name 51 | ), 52 | context = "stats_aov", 53 | fmt_fn = lapply( 54 | .data$stat, 55 | function(x) { 56 | switch(is.integer(x), 57 | 0L 58 | ) %||% switch(is.numeric(x), 59 | 1L 60 | ) 61 | } 62 | ), 63 | warning = aov["warning"], 64 | error = aov["error"] 65 | ) |> 66 | cards::as_card() |> 67 | cards::tidy_ard_column_order() 68 | } 69 | -------------------------------------------------------------------------------- /R/ard_stats_chisq_test.R: -------------------------------------------------------------------------------- 1 | #' ARD Chi-squared Test 2 | #' 3 | #' @description 4 | #' Analysis results data for Pearson's Chi-squared Test. 5 | #' Calculated with `chisq.test(x = data[[variable]], y = data[[by]], ...)` 6 | #' 7 | #' 8 | #' @param data (`data.frame`)\cr 9 | #' a data frame. 10 | #' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr 11 | #' column name to compare by. 12 | #' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr 13 | #' column names to be compared. Independent tests will be computed for 14 | #' each variable. 15 | #' @param ... additional arguments passed to `chisq.test(...)` 16 | #' 17 | #' @return ARD data frame 18 | #' @export 19 | #' 20 | #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom")) 21 | #' cards::ADSL |> 22 | #' ard_stats_chisq_test(by = "ARM", variables = "AGEGR1") 23 | ard_stats_chisq_test <- function(data, by, variables, ...) { 24 | set_cli_abort_call() 25 | 26 | # check installed packages --------------------------------------------------- 27 | check_pkg_installed("broom") 28 | 29 | # check/process inputs ------------------------------------------------------- 30 | check_not_missing(data) 31 | check_not_missing(variables) 32 | check_not_missing(by) 33 | check_data_frame(data) 34 | cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) 35 | check_scalar(by) 36 | 37 | # return empty ARD if no variables selected ---------------------------------- 38 | if (is_empty(variables)) { 39 | return(dplyr::tibble() |> cards::as_card()) 40 | } 41 | 42 | # build ARD ------------------------------------------------------------------ 43 | lapply( 44 | variables, 45 | function(variable) { 46 | cards::tidy_as_ard( 47 | lst_tidy = 48 | cards::eval_capture_conditions( 49 | stats::chisq.test(x = data[[variable]], y = data[[by]], ...) |> 50 | broom::tidy() 51 | ), 52 | tidy_result_names = c("statistic", "p.value", "parameter", "method"), 53 | fun_args_to_record = 54 | c("correct", "p", "rescale.p", "simulate.p.value", "B"), 55 | formals = formals(stats::chisq.test), 56 | passed_args = dots_list(...), 57 | lst_ard_columns = list(group1 = by, variable = variable, context = "stats_chisq_test") 58 | ) |> 59 | dplyr::mutate( 60 | .after = "stat_name", 61 | stat_label = 62 | dplyr::case_when( 63 | .data$stat_name %in% "statistic" ~ "X-squared Statistic", 64 | .data$stat_name %in% "p.value" ~ "p-value", 65 | .data$stat_name %in% "parameter" ~ "Degrees of Freedom", 66 | TRUE ~ .data$stat_name, 67 | ) 68 | ) 69 | } 70 | ) |> 71 | dplyr::bind_rows() |> 72 | cards::as_card() 73 | } 74 | -------------------------------------------------------------------------------- /R/ard_stats_kruskal_test.R: -------------------------------------------------------------------------------- 1 | #' ARD Kruskal-Wallis Test 2 | #' 3 | #' @description 4 | #' Analysis results data for Kruskal-Wallis Rank Sum Test. 5 | #' 6 | #' Calculated with `kruskal.test(data[[variable]], data[[by]], ...)` 7 | #' 8 | #' @param data (`data.frame`)\cr 9 | #' a data frame. 10 | #' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr 11 | #' column name to compare by. 12 | #' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr 13 | #' column names to be compared. Independent tests will 14 | #' be computed for each variable. 15 | #' 16 | #' @return ARD data frame 17 | #' @export 18 | #' 19 | #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom")) 20 | #' cards::ADSL |> 21 | #' ard_stats_kruskal_test(by = "ARM", variables = "AGE") 22 | ard_stats_kruskal_test <- function(data, by, variables) { 23 | set_cli_abort_call() 24 | 25 | # check installed packages --------------------------------------------------- 26 | check_pkg_installed("broom") 27 | 28 | # check/process inputs ------------------------------------------------------- 29 | check_not_missing(data) 30 | check_not_missing(variables) 31 | check_not_missing(by) 32 | check_data_frame(data) 33 | cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) 34 | check_scalar(by) 35 | 36 | # return empty ARD if no variables selected ---------------------------------- 37 | if (is_empty(variables)) { 38 | return(dplyr::tibble() |> cards::as_card()) 39 | } 40 | 41 | # build ARD ------------------------------------------------------------------ 42 | lapply( 43 | variables, 44 | function(variable) { 45 | cards::tidy_as_ard( 46 | lst_tidy = 47 | cards::eval_capture_conditions( 48 | stats::kruskal.test(x = data[[variable]], g = data[[by]]) |> 49 | broom::tidy() 50 | ), 51 | tidy_result_names = c("statistic", "p.value", "parameter", "method"), 52 | lst_ard_columns = list(group1 = by, variable = variable, context = "stats_kruskal_test") 53 | ) |> 54 | dplyr::mutate( 55 | .after = "stat_name", 56 | stat_label = 57 | dplyr::case_when( 58 | .data$stat_name %in% "statistic" ~ "Kruskal-Wallis chi-squared Statistic", 59 | .data$stat_name %in% "p.value" ~ "p-value", 60 | .data$stat_name %in% "parameter" ~ "Degrees of Freedom", 61 | TRUE ~ .data$stat_name, 62 | ) 63 | ) 64 | } 65 | ) |> 66 | dplyr::bind_rows() |> 67 | cards::as_card() 68 | } 69 | -------------------------------------------------------------------------------- /R/ard_stats_oneway_test.R: -------------------------------------------------------------------------------- 1 | #' ARD One-way Test 2 | #' 3 | #' @description 4 | #' Analysis results data for Testing Equal Means in a One-Way Layout. 5 | #' calculated with `oneway.test()` 6 | #' 7 | #' @inheritParams stats::oneway.test 8 | #' @param ... additional arguments passed to `oneway.test(...)` 9 | #' 10 | #' @return ARD data frame 11 | #' @export 12 | #' 13 | #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom")) 14 | #' ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) 15 | ard_stats_oneway_test <- function(formula, data, ...) { 16 | set_cli_abort_call() 17 | 18 | # check installed packages --------------------------------------------------- 19 | check_pkg_installed(c("broom")) 20 | 21 | # check/process inputs ------------------------------------------------------- 22 | check_not_missing(formula) 23 | check_not_missing(data) 24 | check_data_frame(data) 25 | check_class(formula, cls = "formula") 26 | 27 | # build ARD ------------------------------------------------------------------ 28 | df_results <- 29 | cards::tidy_as_ard( 30 | lst_tidy = 31 | cards::eval_capture_conditions( 32 | stats::oneway.test(formula, data = data, ...) |> 33 | broom::tidy() 34 | ), 35 | tidy_result_names = c("num.df", "den.df", "statistic", "p.value", "method"), 36 | fun_args_to_record = 37 | c("var.equal"), 38 | formals = formals(stats::oneway.test), 39 | passed_args = dots_list(...), 40 | lst_ard_columns = list(context = "stats_oneway_test") 41 | ) |> 42 | dplyr::mutate( 43 | .after = "stat_name", 44 | stat_label = 45 | dplyr::case_when( 46 | .data$stat_name %in% "num.df" ~ "Degrees of Freedom", 47 | .data$stat_name %in% "den.df" ~ "Denominator Degrees of Freedom", 48 | .data$stat_name %in% "statistic" ~ "F Statistic", 49 | .data$stat_name %in% "p.value" ~ "p-value", 50 | .data$stat_name %in% "method" ~ "Method", 51 | TRUE ~ .data$stat_name, 52 | ) 53 | ) 54 | 55 | # add variable/groups to results and return result 56 | df_results |> 57 | dplyr::bind_cols( 58 | dplyr::tibble(!!!map(as.list(attr(stats::terms(formula), "variables"))[-1], as_label)) %>% 59 | set_names(., c("variable", paste0("group", seq_len(length(.) - 1L)))) 60 | ) |> 61 | cards::as_card() |> 62 | cards::tidy_ard_column_order() 63 | } 64 | -------------------------------------------------------------------------------- /R/ard_stats_t_test_onesample.R: -------------------------------------------------------------------------------- 1 | #' ARD one-sample t-test 2 | #' 3 | #' @description 4 | #' Analysis results data for one-sample t-tests. 5 | #' Result may be stratified by including the `by` argument. 6 | #' 7 | #' @param data (`data.frame`)\cr 8 | #' a data frame. See below for details. 9 | #' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select])\cr 10 | #' column names to be analyzed. Independent t-tests will be computed for 11 | #' each variable. 12 | #' @param by ([`tidy-select`][dplyr::dplyr_tidy_select])\cr 13 | #' optional column name to stratify results by. 14 | #' @inheritParams ard_stats_t_test 15 | #' 16 | #' @return ARD data frame 17 | #' @export 18 | #' 19 | #' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom")) 20 | #' cards::ADSL |> 21 | #' ard_stats_t_test_onesample(by = ARM, variables = AGE) 22 | ard_stats_t_test_onesample <- function(data, variables, by = dplyr::group_vars(data), conf.level = 0.95, ...) { 23 | set_cli_abort_call() 24 | 25 | # check installed packages --------------------------------------------------- 26 | check_pkg_installed("broom") 27 | 28 | # check/process inputs ------------------------------------------------------- 29 | check_not_missing(data) 30 | check_not_missing(variables) 31 | check_data_frame(data) 32 | data <- dplyr::ungroup(data) 33 | cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) 34 | check_scalar_range(conf.level, range = c(0, 1)) 35 | 36 | # return empty ARD if no variables selected ---------------------------------- 37 | if (is_empty(variables)) { 38 | return(dplyr::tibble() |> cards::as_card()) 39 | } 40 | 41 | cards::ard_continuous( 42 | data = data, 43 | variables = all_of(variables), 44 | by = all_of(by), 45 | statistic = all_of(variables) ~ list(t_test_onesample = \(x) stats::t.test(x = x, conf.level = conf.level, ...) |> broom::tidy()) 46 | ) |> 47 | cards::bind_ard( 48 | cards::ard_continuous( 49 | data = data, 50 | variables = all_of(variables), 51 | by = all_of(by), 52 | statistic = 53 | all_of(variables) ~ 54 | list(conf.level = \(x) { 55 | formals(asNamespace("stats")[["t.test.default"]])["mu"] |> 56 | utils::modifyList(list(conf.level = conf.level, ...)) 57 | }) 58 | ) 59 | ) |> 60 | dplyr::select(-"stat_label") |> 61 | dplyr::left_join( 62 | .df_ttest_stat_labels(by = NULL), 63 | by = "stat_name" 64 | ) |> 65 | dplyr::mutate( 66 | stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name), 67 | context = "stats_t_test_onesample", 68 | ) |> 69 | cards::as_card() |> 70 | cards::tidy_ard_column_order() |> 71 | cards::tidy_ard_row_order() 72 | } 73 | -------------------------------------------------------------------------------- /R/cardx-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | #' @import rlang 3 | #' @importFrom dplyr across 4 | "_PACKAGE" 5 | 6 | ## usethis namespace: start 7 | ## usethis namespace: end 8 | NULL 9 | 10 | utils::globalVariables(c(".")) 11 | -------------------------------------------------------------------------------- /R/import-standalone-cli_call_env.R: -------------------------------------------------------------------------------- 1 | # Standalone file: do not edit by hand 2 | # Source: 3 | # ---------------------------------------------------------------------- 4 | # 5 | # --- 6 | # repo: insightsengineering/standalone 7 | # file: standalone-cli_call_env.R 8 | # last-updated: 2024-04-10 9 | # license: https://unlicense.org 10 | # imports: [rlang, cli] 11 | # --- 12 | # 13 | # This file provides functions to set and access the call environment to use in cli::cli_abort() in check functions. 14 | # 15 | # ## Changelog 16 | # nocov start 17 | # styler: off 18 | 19 | #' Set Call Environment for [cli::cli_abort()] 20 | #' 21 | #' Set a call environment to be used as the `call` parameter in [cli::cli_abort()] for package checks. This function 22 | #' is used to ensure that the correct user-facing function is reported for errors generated by internal checks that 23 | #' use [cli::cli_abort()]. 24 | #' 25 | #' @param env (`enviroment`)\cr 26 | #' call environment used as the `call` parameter in [cli::cli_abort()] for package checks 27 | #' 28 | #' @seealso [get_cli_abort_call()] 29 | #' 30 | #' @keywords internal 31 | #' @noRd 32 | set_cli_abort_call <- function(env = rlang::caller_env()) { 33 | if (getOption("cli_abort_call") |> is.null()) { 34 | options(cli_abort_call = env) 35 | set_call <- as.call(list(function() options(cli_abort_call = NULL))) 36 | do.call(on.exit, list(expr = set_call, add = TRUE, after = FALSE), envir = env) 37 | } 38 | invisible() 39 | } 40 | 41 | #' Get Call Environment for [cli::cli_abort()] 42 | #' 43 | #' @inheritParams set_cli_abort_call 44 | #' @seealso [set_cli_abort_call()] 45 | #' 46 | #' @keywords internal 47 | #' @noRd 48 | get_cli_abort_call <- function() { 49 | getOption("cli_abort_call", default = parent.frame()) 50 | } 51 | 52 | # nocov end 53 | # styler: on 54 | -------------------------------------------------------------------------------- /R/import-standalone-tibble.R: -------------------------------------------------------------------------------- 1 | # Standalone file: do not edit by hand 2 | # Source: 3 | # ---------------------------------------------------------------------- 4 | # 5 | # --- 6 | # repo: insightsengineering/standalone 7 | # file: standalone-tibble.R 8 | # last-updated: 2024-05-07 9 | # license: https://unlicense.org 10 | # imports: [dplyr] 11 | # --- 12 | # 13 | # This file provides a minimal shim to provide a tibble-like API on top of 14 | # base R functions. They are not drop-in replacements but allow a similar style 15 | # of programming. 16 | # 17 | # ## Changelog 18 | # 19 | # nocov start 20 | # styler: off 21 | 22 | deframe <- function(x) { 23 | if (ncol(x) == 1L) return(x[[1]]) 24 | x[[2]] |> stats::setNames(x[[1]]) 25 | } 26 | 27 | enframe <- function(x, name = "name", value = "value") { 28 | if (!is.null(names(x))) { 29 | lst <- list(names(x), unname(x)) |> stats::setNames(c(name, value)) 30 | } 31 | else { 32 | lst <- list(seq_along(x), unname(x)) |> stats::setNames(c(name, value)) 33 | } 34 | dplyr::tibble(!!!lst) 35 | } 36 | 37 | remove_rownames <- function(.data) { 38 | rownames(.data) <- NULL 39 | .data 40 | } 41 | 42 | rownames_to_column <- function(.data, var = "rowname") { 43 | .data[[var]] <- rownames(.data) 44 | 45 | dplyr::relocate(.data, dplyr::all_of(var), .before = 1L) 46 | } 47 | 48 | # nocov end 49 | # styler: on 50 | -------------------------------------------------------------------------------- /R/reexports.R: -------------------------------------------------------------------------------- 1 | # cards ------------------------------------------------------------------------ 2 | #' @importFrom cards ard_continuous 3 | #' @export 4 | cards::ard_continuous 5 | 6 | #' @importFrom cards ard_categorical 7 | #' @export 8 | cards::ard_categorical 9 | 10 | #' @importFrom cards ard_dichotomous 11 | #' @export 12 | cards::ard_dichotomous 13 | 14 | #' @importFrom cards ard_missing 15 | #' @export 16 | cards::ard_missing 17 | 18 | #' @importFrom cards ard_attributes 19 | #' @export 20 | cards::ard_attributes 21 | 22 | #' @importFrom cards ard_total_n 23 | #' @export 24 | cards::ard_total_n 25 | 26 | # dplyr ------------------------------------------------------------------------ 27 | #' @export 28 | #' @importFrom dplyr %>% 29 | dplyr::`%>%` 30 | 31 | #' @importFrom dplyr starts_with 32 | #' @export 33 | dplyr::starts_with 34 | 35 | #' @importFrom dplyr ends_with 36 | #' @export 37 | dplyr::ends_with 38 | 39 | #' @importFrom dplyr contains 40 | #' @export 41 | dplyr::contains 42 | 43 | #' @importFrom dplyr matches 44 | #' @export 45 | dplyr::matches 46 | 47 | #' @importFrom dplyr num_range 48 | #' @export 49 | dplyr::num_range 50 | 51 | #' @importFrom dplyr all_of 52 | #' @export 53 | dplyr::all_of 54 | 55 | #' @importFrom dplyr any_of 56 | #' @export 57 | dplyr::any_of 58 | 59 | #' @importFrom dplyr everything 60 | #' @export 61 | dplyr::everything 62 | 63 | #' @importFrom dplyr where 64 | #' @export 65 | dplyr::where 66 | 67 | #' @importFrom dplyr last_col 68 | #' @export 69 | dplyr::last_col 70 | 71 | #' @importFrom dplyr one_of 72 | #' @export 73 | dplyr::one_of 74 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting Security Issues 4 | 5 | If you believe you have found a security vulnerability in any of the repositories in this organization, please report it to us through coordinated disclosure. 6 | 7 | **Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.** 8 | 9 | Instead, please send an email to vulnerability.management[@]roche.com. 10 | 11 | Please include as much of the information listed below as you can to help us better understand and resolve the issue: 12 | 13 | * The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting) 14 | * Full paths of source file(s) related to the manifestation of the issue 15 | * The location of the affected source code (tag/branch/commit or direct URL) 16 | * Any special configuration required to reproduce the issue 17 | * Step-by-step instructions to reproduce the issue 18 | * Proof-of-concept or exploit code (if possible) 19 | * Impact of the issue, including how an attacker might exploit the issue 20 | 21 | This information will help us triage your report more quickly. 22 | 23 | ## Data Security Standards (DSS) 24 | 25 | Please make sure that while reporting issues in the form a bug, feature, or pull request, *all* sensitive information such as [PII](https://www.dhs.gov/privacy-training/what-personally-identifiable-information), [PHI](https://www.hhs.gov/hipaa/for-professionals/security/laws-regulations/index.html), and [PCI](https://www.pcisecuritystandards.org/pci_security/standards_overview) is completely removed from any text and attachments, including pictures and videos. 26 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | --- 2 | url: https://insightsengineering.github.io/cardx 3 | 4 | template: 5 | math-rendering: mathjax 6 | package: nesttemplate 7 | 8 | # navbar: 9 | # structure: 10 | # left: [intro, reference, articles, tutorials, news, reports] 11 | # right: [search, github] 12 | # github: 13 | # icon: fa-github 14 | # href: https://github.com/insightsengineering/cardx 15 | # 16 | # development: 17 | # mode: auto 18 | # version_label: default 19 | 20 | authors: 21 | Daniel D. Sjoberg: 22 | href: "http://www.danieldsjoberg.com/" 23 | 24 | reference: 25 | - title: "ARD Creation" 26 | - subtitle: "{stats} package" 27 | - contents: 28 | - ard_stats_anova 29 | - ard_stats_aov 30 | - ard_stats_chisq_test 31 | - ard_stats_fisher_test 32 | - ard_stats_kruskal_test 33 | - ard_stats_mantelhaen_test 34 | - ard_stats_mood_test 35 | - ard_stats_mcnemar_test 36 | - ard_stats_oneway_test 37 | - ard_stats_poisson_test 38 | - ard_stats_prop_test 39 | - ard_stats_t_test 40 | - ard_stats_t_test_onesample 41 | - ard_stats_wilcox_test 42 | - ard_stats_wilcox_test_onesample 43 | 44 | - subtitle: "{aod} package" 45 | - contents: 46 | - ard_aod_wald_test 47 | 48 | - subtitle: "{car} package" 49 | - contents: 50 | - ard_car_anova 51 | - ard_car_vif 52 | 53 | - subtitle: "{effectsize} package" 54 | - contents: 55 | - ard_effectsize_cohens_d 56 | - ard_effectsize_hedges_g 57 | 58 | - subtitle: "{emmeans} package" 59 | - contents: 60 | - ard_emmeans_mean_difference 61 | 62 | - subtitle: "{smd} package" 63 | - contents: 64 | - ard_smd_smd 65 | 66 | - subtitle: "{survey} package" 67 | - contents: 68 | - ard_continuous.survey.design 69 | - ard_categorical.survey.design 70 | - ard_dichotomous.survey.design 71 | - ard_missing.survey.design 72 | - ard_attributes.survey.design 73 | - ard_continuous_ci.survey.design 74 | - ard_categorical_ci.survey.design 75 | - ard_total_n.survey.design 76 | - ard_survey_svychisq 77 | - ard_survey_svyranktest 78 | - ard_survey_svyttest 79 | 80 | - subtitle: "{survival} package" 81 | - contents: 82 | - ard_survival_survfit 83 | - ard_survival_survfit_diff 84 | - ard_survival_survdiff 85 | 86 | - subtitle: "Other ARD functions" 87 | - contents: 88 | - ard_continuous_ci.data.frame 89 | - ard_categorical_ci.data.frame 90 | - ard_regression 91 | - ard_regression_basic 92 | - ard_categorical_max 93 | - ard_incidence_rate 94 | 95 | - title: "Helpers" 96 | - contents: 97 | - proportion_ci 98 | - construction_helpers 99 | -------------------------------------------------------------------------------- /cardx.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: 0d5b97b9-45bb-4e71-a188-5ec06222a470 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | LineEndingConversion: Posix 19 | 20 | BuildType: Package 21 | PackageUseDevtools: Yes 22 | PackageInstallArgs: --no-multiarch --with-keep.source 23 | PackageRoxygenize: rd,collate,namespace 24 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | * Ubuntu 18.04 LTS (on github actions), devel, release, oldrel-1, oldrel-2, oldrel-3, oldrel-4 3 | * Windows Server 2019 (on github actions), release 4 | * macOS (on github actions), release 5 | * win-builder devel 6 | 7 | ## R CMD check results 8 | 9 | 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ 10 | 11 | ## revdepcheck results 12 | 13 | We checked 4 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 14 | 15 | * We saw 1 new problem in the 'gtsummary' package. I maintain this package and the break is expected. I will submit a new version as soon as 'cardx' is on CRAN. 16 | 17 | ## Additional Comments 18 | 19 | * Thank you for your time! 20 | -------------------------------------------------------------------------------- /data-raw/cardx-hex-sticker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/data-raw/cardx-hex-sticker.png -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | ARD 2 | ARDs 3 | Biopharmaceutical 4 | Byar's 5 | CMD 6 | Chisq 7 | Clopper 8 | Codecov 9 | Haenszel 10 | Hoffmann 11 | Jeffreys 12 | Kaplan 13 | Lifecycle 14 | McNemar's 15 | Newcombe 16 | ORCID 17 | Rao 18 | Rua 19 | SMD 20 | Su 21 | VIF 22 | XG 23 | Xin 24 | anova 25 | backtick 26 | cli 27 | de 28 | deff 29 | emmeans 30 | funder 31 | gtsummary 32 | mmrm 33 | pre 34 | quosures 35 | renv 36 | rlang's 37 | sd 38 | tidyselect 39 | unlist 40 | unnests 41 | unstratified 42 | vif 43 | wald 44 | wilcox 45 | -------------------------------------------------------------------------------- /man/ard_aod_wald_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_aod_wald_test.R 3 | \name{ard_aod_wald_test} 4 | \alias{ard_aod_wald_test} 5 | \title{ARD Wald Test} 6 | \usage{ 7 | ard_aod_wald_test( 8 | x, 9 | tidy_fun = broom.helpers::tidy_with_broom_or_parameters, 10 | ... 11 | ) 12 | } 13 | \arguments{ 14 | \item{x}{regression model object} 15 | 16 | \item{tidy_fun}{(\code{function})\cr 17 | a tidier. Default is \code{\link[broom.helpers:tidy_with_broom_or_parameters]{broom.helpers::tidy_with_broom_or_parameters}}} 18 | 19 | \item{...}{arguments passed to \code{aod::wald.test(...)}} 20 | } 21 | \value{ 22 | data frame 23 | } 24 | \description{ 25 | Function takes a regression model object and calculates Wald 26 | statistical test using \code{\link[aod:wald.test]{aod::wald.test()}}. 27 | } 28 | \examples{ 29 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("aod", "broom.helpers")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 30 | lm(AGE ~ ARM, data = cards::ADSL) |> 31 | ard_aod_wald_test() 32 | \dontshow{\}) # examplesIf} 33 | } 34 | -------------------------------------------------------------------------------- /man/ard_attributes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_attributes.survey.design.R 3 | \name{ard_attributes.survey.design} 4 | \alias{ard_attributes.survey.design} 5 | \title{ARD Attributes} 6 | \usage{ 7 | \method{ard_attributes}{survey.design}(data, variables = everything(), label = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{survey.design})\cr 11 | a design object often created with \code{\link[survey:svydesign]{survey::svydesign()}}.} 12 | 13 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | variables to include} 15 | 16 | \item{label}{(named \code{list})\cr 17 | named list of variable labels, e.g. \code{list(cyl = "No. Cylinders")}. 18 | Default is \code{NULL}} 19 | 20 | \item{...}{These dots are for future extensions and must be empty.} 21 | } 22 | \value{ 23 | an ARD data frame of class 'card' 24 | } 25 | \description{ 26 | Add variable attributes to an ARD data frame. 27 | \itemize{ 28 | \item The \code{label} attribute will be added for all columns, and when no label 29 | is specified and no label has been set for a column using the \verb{label=} argument, 30 | the column name will be placed in the label statistic. 31 | \item The \code{class} attribute will also be returned for all columns. 32 | \item Any other attribute returned by \code{attributes()} will also be added, e.g. factor levels. 33 | } 34 | } 35 | \examples{ 36 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survey"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 37 | data(api, package = "survey") 38 | dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) 39 | 40 | ard_attributes( 41 | data = dclus1, 42 | variables = c(sname, dname), 43 | label = list(sname = "School Name", dname = "District Name") 44 | ) 45 | \dontshow{\}) # examplesIf} 46 | } 47 | -------------------------------------------------------------------------------- /man/ard_car_anova.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_car_anova.R 3 | \name{ard_car_anova} 4 | \alias{ard_car_anova} 5 | \title{ARD ANOVA from car Package} 6 | \usage{ 7 | ard_car_anova(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{regression model object} 11 | 12 | \item{...}{arguments passed to \code{car::Anova(...)}} 13 | } 14 | \value{ 15 | data frame 16 | } 17 | \description{ 18 | Function takes a regression model object and calculated ANOVA using \code{\link[car:Anova]{car::Anova()}}. 19 | } 20 | \examples{ 21 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom.helpers", "car", "parameters")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 22 | lm(AGE ~ ARM, data = cards::ADSL) |> 23 | ard_car_anova() 24 | 25 | glm(vs ~ factor(cyl) + factor(am), data = mtcars, family = binomial) |> 26 | ard_car_anova(test.statistic = "Wald") 27 | \dontshow{\}) # examplesIf} 28 | } 29 | -------------------------------------------------------------------------------- /man/ard_car_vif.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_car_vif.R 3 | \name{ard_car_vif} 4 | \alias{ard_car_vif} 5 | \title{Regression VIF ARD} 6 | \usage{ 7 | ard_car_vif(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{regression model object 11 | See car::vif() for details} 12 | 13 | \item{...}{arguments passed to \code{car::vif(...)}} 14 | } 15 | \value{ 16 | data frame 17 | } 18 | \description{ 19 | Function takes a regression model object and returns the variance inflation factor (VIF) 20 | using \code{\link[car:vif]{car::vif()}} and converts it to a ARD structure 21 | } 22 | \examples{ 23 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "car"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 24 | lm(AGE ~ ARM + SEX, data = cards::ADSL) |> 25 | ard_car_vif() 26 | \dontshow{\}) # examplesIf} 27 | } 28 | -------------------------------------------------------------------------------- /man/ard_categorical_ci.survey.design.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_categorical_ci.survey.design.R 3 | \name{ard_categorical_ci.survey.design} 4 | \alias{ard_categorical_ci.survey.design} 5 | \title{ARD survey categorical CIs} 6 | \usage{ 7 | \method{ard_categorical_ci}{survey.design}( 8 | data, 9 | variables, 10 | by = NULL, 11 | method = c("logit", "likelihood", "asin", "beta", "mean", "xlogit"), 12 | conf.level = 0.95, 13 | value = list(where(is_binary) ~ 1L, where(is.logical) ~ TRUE), 14 | df = survey::degf(data), 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{data}{(\code{survey.design})\cr 20 | a design object often created with \code{\link[survey:svydesign]{survey::svydesign()}}.} 21 | 22 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 23 | columns to include in summaries.} 24 | 25 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 26 | results are calculated for \strong{all combinations} of the columns specified, 27 | including unobserved combinations and unobserved factor levels.} 28 | 29 | \item{method}{(\code{string})\cr 30 | Method passed to \code{survey::svyciprop(method)}} 31 | 32 | \item{conf.level}{(scalar \code{numeric})\cr 33 | a scalar in \verb{(0,1)} indicating the confidence level. 34 | Default is \code{0.95}} 35 | 36 | \item{value}{(\code{\link[cards:syntax]{formula-list-selector}})\cr 37 | function will calculate the CIs for all levels of the variables specified. 38 | Use this argument to instead request only a single level by summarized. 39 | Default is \code{list(where(is_binary) ~ 1L, where(is.logical) ~ TRUE)}, where 40 | columns coded as \code{0}/\code{1} and \code{TRUE}/\code{FALSE} will summarize the \code{1} and \code{TRUE} levels.} 41 | 42 | \item{df}{(\code{numeric})\cr 43 | denominator degrees of freedom, passed to \code{survey::svyciprop(df)}. 44 | Default is \code{survey::degf(data)}.} 45 | 46 | \item{...}{arguments passed to \code{survey::svyciprop()}} 47 | } 48 | \value{ 49 | ARD data frame 50 | } 51 | \description{ 52 | Confidence intervals for categorical variables calculated via 53 | \code{\link[survey:svyciprop]{survey::svyciprop()}}. 54 | } 55 | \examples{ 56 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survey"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 57 | data(api, package = "survey") 58 | dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) 59 | 60 | ard_categorical_ci(dclus1, variables = sch.wide) 61 | ard_categorical_ci(dclus1, variables = sch.wide, value = sch.wide ~ "Yes", method = "xlogit") 62 | \dontshow{\}) # examplesIf} 63 | } 64 | -------------------------------------------------------------------------------- /man/ard_continuous_ci.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_continuous_ci.R 3 | \name{ard_continuous_ci} 4 | \alias{ard_continuous_ci} 5 | \alias{ard_continuous_ci.data.frame} 6 | \title{ARD continuous CIs} 7 | \usage{ 8 | ard_continuous_ci(data, ...) 9 | 10 | \method{ard_continuous_ci}{data.frame}( 11 | data, 12 | variables, 13 | by = dplyr::group_vars(data), 14 | conf.level = 0.95, 15 | method = c("t.test", "wilcox.test"), 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{data}{(\code{data.frame})\cr 21 | a data frame. See below for details.} 22 | 23 | \item{...}{arguments passed to \code{t.test()} or \code{wilcox.test()}} 24 | 25 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 26 | column names to be compared. Independent t-tests will be computed for 27 | each variable.} 28 | 29 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 30 | optional column name to compare by.} 31 | 32 | \item{conf.level}{(scalar \code{numeric})\cr 33 | confidence level for confidence interval. Default is \code{0.95}.} 34 | 35 | \item{method}{(\code{string})\cr 36 | a string indicating the method to use for the confidence interval 37 | calculation. Must be one of \code{"t.test"} or \code{"wilcox.test"}} 38 | } 39 | \value{ 40 | ARD data frame 41 | } 42 | \description{ 43 | One-sample confidence intervals for continuous variable means and medians. 44 | } 45 | \examples{ 46 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 47 | ard_continuous_ci(mtcars, variables = c(mpg, hp), method = "wilcox.test") 48 | ard_continuous_ci(mtcars, variables = mpg, by = am, method = "t.test") 49 | \dontshow{\}) # examplesIf} 50 | } 51 | -------------------------------------------------------------------------------- /man/ard_continuous_ci.survey.design.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_continuous_ci.survey.design.R 3 | \name{ard_continuous_ci.survey.design} 4 | \alias{ard_continuous_ci.survey.design} 5 | \title{ARD survey continuous CIs} 6 | \usage{ 7 | \method{ard_continuous_ci}{survey.design}( 8 | data, 9 | variables, 10 | by = NULL, 11 | method = c("svymean", "svymedian.mean", "svymedian.beta", "svymedian.xlogit", 12 | "svymedian.asin", "svymedian.score"), 13 | conf.level = 0.95, 14 | df = survey::degf(data), 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{data}{(\code{survey.design})\cr 20 | a design object often created with \code{\link[survey:svydesign]{survey::svydesign()}}.} 21 | 22 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 23 | columns to include in summaries.} 24 | 25 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 26 | results are calculated for \strong{all combinations} of the columns specified, 27 | including unobserved combinations and unobserved factor levels.} 28 | 29 | \item{method}{(\code{string})\cr 30 | Method for confidence interval calculation. 31 | When \code{"svymean"}, the calculation is computed via \code{survey::svymean()}. 32 | Otherwise, it is calculated via\code{survey::svyquantile(interval.type=method)}} 33 | 34 | \item{conf.level}{(scalar \code{numeric})\cr 35 | confidence level for confidence interval. Default is \code{0.95}.} 36 | 37 | \item{df}{(\code{numeric})\cr 38 | denominator degrees of freedom, passed to \code{survey::confint(df)}. 39 | Default is \code{survey::degf(data)}.} 40 | 41 | \item{...}{arguments passed to \code{survey::confint()}} 42 | } 43 | \value{ 44 | ARD data frame 45 | } 46 | \description{ 47 | One-sample confidence intervals for continuous variables' means and medians. 48 | Confidence limits are calculated with \code{survey::svymean()} and \code{survey::svyquantile()}. 49 | } 50 | \examples{ 51 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survey"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 52 | data(api, package = "survey") 53 | dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) 54 | 55 | ard_continuous_ci(dclus1, variables = api00) 56 | ard_continuous_ci(dclus1, variables = api00, method = "svymedian.xlogit") 57 | \dontshow{\}) # examplesIf} 58 | } 59 | -------------------------------------------------------------------------------- /man/ard_regression.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_regression.R 3 | \name{ard_regression} 4 | \alias{ard_regression} 5 | \alias{ard_regression.default} 6 | \alias{ard_regression.data.frame} 7 | \title{Regression ARD} 8 | \usage{ 9 | ard_regression(x, ...) 10 | 11 | \method{ard_regression}{default}(x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, ...) 12 | 13 | \method{ard_regression}{data.frame}( 14 | x, 15 | formula, 16 | method, 17 | method.args = list(), 18 | package = "base", 19 | tidy_fun = broom.helpers::tidy_with_broom_or_parameters, 20 | ... 21 | ) 22 | } 23 | \arguments{ 24 | \item{x}{(regression model/\code{data.frame})\cr 25 | regression model object or a data frame} 26 | 27 | \item{...}{Arguments passed to \code{\link[broom.helpers:tidy_plus_plus]{broom.helpers::tidy_plus_plus()}}} 28 | 29 | \item{tidy_fun}{(\code{function})\cr 30 | a tidier. Default is \code{\link[broom.helpers:tidy_with_broom_or_parameters]{broom.helpers::tidy_with_broom_or_parameters}}} 31 | 32 | \item{formula}{(\code{formula})\cr 33 | a formula} 34 | 35 | \item{method}{(\code{string})\cr 36 | string of function naming the function to be called, e.g. \code{"glm"}. 37 | If function belongs to a library that is not attached, the package name 38 | must be specified in the \code{package} argument.} 39 | 40 | \item{method.args}{(named \code{list})\cr 41 | named list of arguments that will be passed to \code{method}. 42 | 43 | Note that this list may contain non-standard evaluation components. 44 | If you are wrapping this function in other functions, the argument 45 | must be passed in a way that does not evaluate the list, e.g. 46 | using rlang's embrace operator \code{{{ . }}}.} 47 | 48 | \item{package}{(\code{string})\cr 49 | a package name that will be temporarily loaded when function 50 | specified in \code{method} is executed.} 51 | } 52 | \value{ 53 | data frame 54 | } 55 | \description{ 56 | Function takes a regression model object and converts it to a ARD 57 | structure using the \code{broom.helpers} package. 58 | } 59 | \examples{ 60 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 61 | lm(AGE ~ ARM, data = cards::ADSL) |> 62 | ard_regression(add_estimate_to_reference_rows = TRUE) 63 | 64 | ard_regression( 65 | x = cards::ADSL, 66 | formula = AGE ~ ARM, 67 | method = "lm" 68 | ) 69 | \dontshow{\}) # examplesIf} 70 | } 71 | -------------------------------------------------------------------------------- /man/ard_smd_smd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_smd_smd.R 3 | \name{ard_smd_smd} 4 | \alias{ard_smd_smd} 5 | \title{ARD Standardized Mean Difference} 6 | \usage{ 7 | ard_smd_smd(data, by, variables, std.error = TRUE, conf.level = 0.95, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame}/\code{survey.design})\cr 11 | a data frame or object of class 'survey.design' 12 | (typically created with \code{\link[survey:svydesign]{survey::svydesign()}}).} 13 | 14 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 15 | column name to compare by.} 16 | 17 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 18 | column names to be compared. Independent tests will be computed for 19 | each variable.} 20 | 21 | \item{std.error}{(scalar \code{logical})\cr 22 | Logical indicator for computing standard errors using \code{smd::compute_smd_var()}. 23 | Default is \code{TRUE}.} 24 | 25 | \item{conf.level}{(scalar \code{numeric})\cr 26 | confidence level for confidence interval. Default is \code{0.95}.} 27 | 28 | \item{...}{arguments passed to \code{smd::smd()}} 29 | } 30 | \value{ 31 | ARD data frame 32 | } 33 | \description{ 34 | Standardized mean difference calculated via \code{\link[smd:smd]{smd::smd()}} with \code{na.rm = TRUE}. 35 | Additionally, this function add a confidence interval to the SMD when 36 | \code{std.error=TRUE}, which the original \code{smd::smd()} does not include. 37 | } 38 | \examples{ 39 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "smd"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 40 | ard_smd_smd(cards::ADSL, by = SEX, variables = AGE) 41 | ard_smd_smd(cards::ADSL, by = SEX, variables = AGEGR1) 42 | \dontshow{\}) # examplesIf} 43 | } 44 | -------------------------------------------------------------------------------- /man/ard_stats_aov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_aov.R 3 | \name{ard_stats_aov} 4 | \alias{ard_stats_aov} 5 | \title{ARD ANOVA} 6 | \usage{ 7 | ard_stats_aov(formula, data, ...) 8 | } 9 | \arguments{ 10 | \item{formula}{A formula specifying the model.} 11 | 12 | \item{data}{A data frame in which the variables specified in the 13 | formula will be found. If missing, the variables are searched for in 14 | the standard way.} 15 | 16 | \item{...}{arguments passed to \code{stats::aov(...)}} 17 | } 18 | \value{ 19 | ARD data frame 20 | } 21 | \description{ 22 | Analysis results data for Analysis of Variance. 23 | Calculated with \code{stats::aov()} 24 | } 25 | \examples{ 26 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom.helpers", "parameters")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 27 | ard_stats_aov(AGE ~ ARM, data = cards::ADSL) 28 | \dontshow{\}) # examplesIf} 29 | } 30 | -------------------------------------------------------------------------------- /man/ard_stats_chisq_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_chisq_test.R 3 | \name{ard_stats_chisq_test} 4 | \alias{ard_stats_chisq_test} 5 | \title{ARD Chi-squared Test} 6 | \usage{ 7 | ard_stats_chisq_test(data, by, variables, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr 11 | a data frame.} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by.} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent tests will be computed for 18 | each variable.} 19 | 20 | \item{...}{additional arguments passed to \code{chisq.test(...)}} 21 | } 22 | \value{ 23 | ARD data frame 24 | } 25 | \description{ 26 | Analysis results data for Pearson's Chi-squared Test. 27 | Calculated with \code{chisq.test(x = data[[variable]], y = data[[by]], ...)} 28 | } 29 | \examples{ 30 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 31 | cards::ADSL |> 32 | ard_stats_chisq_test(by = "ARM", variables = "AGEGR1") 33 | \dontshow{\}) # examplesIf} 34 | } 35 | -------------------------------------------------------------------------------- /man/ard_stats_fisher_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_fisher_test.R 3 | \name{ard_stats_fisher_test} 4 | \alias{ard_stats_fisher_test} 5 | \title{ARD Fisher's Exact Test} 6 | \usage{ 7 | ard_stats_fisher_test(data, by, variables, conf.level = 0.95, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr 11 | a data frame.} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent tests will be computed for 18 | each variable.} 19 | 20 | \item{conf.level}{(scalar \code{numeric})\cr 21 | confidence level for confidence interval. Default is \code{0.95}.} 22 | 23 | \item{...}{additional arguments passed to \code{fisher.test(...)}} 24 | } 25 | \value{ 26 | ARD data frame 27 | } 28 | \description{ 29 | Analysis results data for Fisher's Exact Test. 30 | Calculated with \code{fisher.test(x = data[[variable]], y = data[[by]], ...)} 31 | } 32 | \examples{ 33 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 34 | cards::ADSL[1:30, ] |> 35 | ard_stats_fisher_test(by = "ARM", variables = "AGEGR1") 36 | \dontshow{\}) # examplesIf} 37 | } 38 | -------------------------------------------------------------------------------- /man/ard_stats_kruskal_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_kruskal_test.R 3 | \name{ard_stats_kruskal_test} 4 | \alias{ard_stats_kruskal_test} 5 | \title{ARD Kruskal-Wallis Test} 6 | \usage{ 7 | ard_stats_kruskal_test(data, by, variables) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr 11 | a data frame.} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by.} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent tests will 18 | be computed for each variable.} 19 | } 20 | \value{ 21 | ARD data frame 22 | } 23 | \description{ 24 | Analysis results data for Kruskal-Wallis Rank Sum Test. 25 | 26 | Calculated with \code{kruskal.test(data[[variable]], data[[by]], ...)} 27 | } 28 | \examples{ 29 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 30 | cards::ADSL |> 31 | ard_stats_kruskal_test(by = "ARM", variables = "AGE") 32 | \dontshow{\}) # examplesIf} 33 | } 34 | -------------------------------------------------------------------------------- /man/ard_stats_mantelhaen_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_mantelhaen_test.R 3 | \name{ard_stats_mantelhaen_test} 4 | \alias{ard_stats_mantelhaen_test} 5 | \title{ARD Cochran-Mantel-Haenszel Chi-Squared Test} 6 | \usage{ 7 | ard_stats_mantelhaen_test(data, by, variables, strata, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr 11 | a data frame.} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by.} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent tests will be computed for each variable.} 18 | 19 | \item{strata}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 20 | column name to stratify by.} 21 | 22 | \item{...}{additional arguments passed to \code{stats::mantelhaen.test(...)}} 23 | } 24 | \value{ 25 | ARD data frame 26 | } 27 | \description{ 28 | Analysis results data for Cochran-Mantel-Haenszel Chi-Squared Test for count data. 29 | Calculated with \code{mantelhaen.test(x = data[[variables]], y = data[[by]], z = data[[strata]], ...)}. 30 | } 31 | \examples{ 32 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 33 | cards::ADSL |> 34 | ard_stats_mantelhaen_test(by = "ARM", variables = "AGEGR1", strata = "SEX") 35 | \dontshow{\}) # examplesIf} 36 | } 37 | -------------------------------------------------------------------------------- /man/ard_stats_mcnemar_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_mcnemar_test.R 3 | \name{ard_stats_mcnemar_test} 4 | \alias{ard_stats_mcnemar_test} 5 | \alias{ard_stats_mcnemar_test_long} 6 | \title{ARD McNemar's Test} 7 | \usage{ 8 | ard_stats_mcnemar_test(data, by, variables, ...) 9 | 10 | ard_stats_mcnemar_test_long(data, by, variables, id, ...) 11 | } 12 | \arguments{ 13 | \item{data}{(\code{data.frame})\cr 14 | a data frame. See below for details.} 15 | 16 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column name to compare by.} 18 | 19 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 20 | column names to be compared. Independent tests will 21 | be computed for each variable.} 22 | 23 | \item{...}{arguments passed to \code{stats::mcnemar.test(...)}} 24 | 25 | \item{id}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 26 | column name of the subject or participant ID} 27 | } 28 | \value{ 29 | ARD data frame 30 | } 31 | \description{ 32 | Analysis results data for McNemar's statistical test. 33 | We have two functions depending on the structure of the data. 34 | \itemize{ 35 | \item \code{ard_stats_mcnemar_test()} is the structure expected by \code{\link[stats:mcnemar.test]{stats::mcnemar.test()}} 36 | \item \code{ard_stats_mcnemar_test_long()} is one row per ID per group 37 | } 38 | } 39 | \details{ 40 | For the \code{ard_stats_mcnemar_test()} function, the data is expected to be one row per subject. 41 | The data is passed as \code{stats::mcnemar.test(x = data[[variable]], y = data[[by]], ...)}. 42 | Please use \code{table(x = data[[variable]], y = data[[by]])} to check the contingency table. 43 | } 44 | \examples{ 45 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 46 | cards::ADSL |> 47 | ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") 48 | 49 | set.seed(1234) 50 | cards::ADSL[c("USUBJID", "TRT01P")] |> 51 | dplyr::mutate(TYPE = "PLANNED") |> 52 | dplyr::rename(TRT01 = TRT01P) \%>\% 53 | dplyr::bind_rows(dplyr::mutate(., TYPE = "ACTUAL", TRT01 = sample(TRT01))) |> 54 | ard_stats_mcnemar_test_long( 55 | by = TYPE, 56 | variable = TRT01, 57 | id = USUBJID 58 | ) 59 | \dontshow{\}) # examplesIf} 60 | } 61 | -------------------------------------------------------------------------------- /man/ard_stats_mood_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_mood_test.R 3 | \name{ard_stats_mood_test} 4 | \alias{ard_stats_mood_test} 5 | \title{ARD Mood Test} 6 | \usage{ 7 | ard_stats_mood_test(data, by, variables, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr 11 | a data frame. See below for details.} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by.} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column name to be compared. Independent tests will 18 | be run for each variable.} 19 | 20 | \item{...}{arguments passed to \code{mood.test(...)}} 21 | } 22 | \value{ 23 | ARD data frame 24 | } 25 | \description{ 26 | Analysis results data for Mood two sample test of scale. Note this not to be confused with 27 | the Brown-Mood test of medians. 28 | } 29 | \details{ 30 | For the \code{ard_stats_mood_test()} function, the data is expected to be one row per subject. 31 | The data is passed as \code{mood.test(data[[variable]] ~ data[[by]], ...)}. 32 | } 33 | \examples{ 34 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 35 | cards::ADSL |> 36 | ard_stats_mood_test(by = "SEX", variables = "AGE") 37 | \dontshow{\}) # examplesIf} 38 | } 39 | -------------------------------------------------------------------------------- /man/ard_stats_oneway_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_oneway_test.R 3 | \name{ard_stats_oneway_test} 4 | \alias{ard_stats_oneway_test} 5 | \title{ARD One-way Test} 6 | \usage{ 7 | ard_stats_oneway_test(formula, data, ...) 8 | } 9 | \arguments{ 10 | \item{formula}{a formula of the form \code{lhs ~ rhs} where \code{lhs} 11 | gives the sample values and \code{rhs} the corresponding groups.} 12 | 13 | \item{data}{an optional matrix or data frame (or similar: see 14 | \code{\link[stats]{model.frame}}) containing the variables in the 15 | formula \code{formula}. By default the variables are taken from 16 | \code{environment(formula)}.} 17 | 18 | \item{...}{additional arguments passed to \code{oneway.test(...)}} 19 | } 20 | \value{ 21 | ARD data frame 22 | } 23 | \description{ 24 | Analysis results data for Testing Equal Means in a One-Way Layout. 25 | calculated with \code{oneway.test()} 26 | } 27 | \examples{ 28 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 29 | ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) 30 | \dontshow{\}) # examplesIf} 31 | } 32 | -------------------------------------------------------------------------------- /man/ard_stats_poisson_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_poisson_test.R 3 | \name{ard_stats_poisson_test} 4 | \alias{ard_stats_poisson_test} 5 | \title{ARD Poisson Test} 6 | \usage{ 7 | ard_stats_poisson_test( 8 | data, 9 | variables, 10 | na.rm = TRUE, 11 | by = NULL, 12 | conf.level = 0.95, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{(\code{data.frame})\cr 18 | a data frame. See below for details.} 19 | 20 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 21 | names of the event and time variables (in that order) to be used in computations. Must be of length 2.} 22 | 23 | \item{na.rm}{(scalar \code{logical})\cr 24 | whether missing values should be removed before computations. Default is \code{TRUE}.} 25 | 26 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 27 | optional column name to compare by.} 28 | 29 | \item{conf.level}{(scalar \code{numeric})\cr 30 | confidence level for confidence interval. Default is \code{0.95}.} 31 | 32 | \item{...}{arguments passed to \code{\link[=poisson.test]{poisson.test()}}.} 33 | } 34 | \value{ 35 | an ARD data frame of class 'card' 36 | } 37 | \description{ 38 | Analysis results data for exact tests of a simple null hypothesis about the rate parameter 39 | in Poisson distribution, or the comparison of two rate parameters. 40 | } 41 | \details{ 42 | \itemize{ 43 | \item For the \code{ard_stats_poisson_test()} function, the data is expected to be one row per subject. 44 | \item If \code{by} is not specified, an exact Poisson test of the rate parameter will be performed. Otherwise, a 45 | Poisson comparison of two rate parameters will be performed on the levels of \code{by}. If \code{by} has more than 2 46 | levels, an error will occur. 47 | } 48 | } 49 | \examples{ 50 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 51 | # Exact test of rate parameter against null hypothesis 52 | cards::ADTTE |> 53 | ard_stats_poisson_test(variables = c(CNSR, AVAL)) 54 | 55 | # Comparison test of ratio of 2 rate parameters against null hypothesis 56 | cards::ADTTE |> 57 | dplyr::filter(TRTA \%in\% c("Placebo", "Xanomeline High Dose")) |> 58 | ard_stats_poisson_test(by = TRTA, variables = c(CNSR, AVAL)) 59 | \dontshow{\}) # examplesIf} 60 | } 61 | -------------------------------------------------------------------------------- /man/ard_stats_prop_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_prop_test.R 3 | \name{ard_stats_prop_test} 4 | \alias{ard_stats_prop_test} 5 | \title{ARD 2-sample proportion test} 6 | \usage{ 7 | ard_stats_prop_test(data, by, variables, conf.level = 0.95, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr 11 | a data frame.} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Must be a binary column coded as \code{TRUE}/\code{FALSE} 18 | or \code{1}/\code{0}. Independent tests will be computed for each variable.} 19 | 20 | \item{conf.level}{(scalar \code{numeric})\cr 21 | confidence level for confidence interval. Default is \code{0.95}.} 22 | 23 | \item{...}{arguments passed to \code{prop.test(...)}} 24 | } 25 | \value{ 26 | ARD data frame 27 | } 28 | \description{ 29 | Analysis results data for a 2-sample test or proportions using \code{\link[stats:prop.test]{stats::prop.test()}}. 30 | } 31 | \examples{ 32 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 33 | mtcars |> 34 | ard_stats_prop_test(by = vs, variables = am) 35 | \dontshow{\}) # examplesIf} 36 | } 37 | -------------------------------------------------------------------------------- /man/ard_stats_t_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_t_test.R 3 | \name{ard_stats_t_test} 4 | \alias{ard_stats_t_test} 5 | \alias{ard_stats_paired_t_test} 6 | \title{ARD t-test} 7 | \usage{ 8 | ard_stats_t_test(data, variables, by = NULL, conf.level = 0.95, ...) 9 | 10 | ard_stats_paired_t_test(data, by, variables, id, conf.level = 0.95, ...) 11 | } 12 | \arguments{ 13 | \item{data}{(\code{data.frame})\cr 14 | a data frame. See below for details.} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent t-tests will be computed for 18 | each variable.} 19 | 20 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 21 | optional column name to compare by.} 22 | 23 | \item{conf.level}{(scalar \code{numeric})\cr 24 | confidence level for confidence interval. Default is \code{0.95}.} 25 | 26 | \item{...}{arguments passed to \code{t.test()}} 27 | 28 | \item{id}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 29 | column name of the subject or participant ID} 30 | } 31 | \value{ 32 | ARD data frame 33 | } 34 | \description{ 35 | Analysis results data for paired and non-paired t-tests. 36 | } 37 | \details{ 38 | For the \code{ard_stats_t_test()} function, the data is expected to be one row per subject. 39 | The data is passed as \code{t.test(data[[variable]] ~ data[[by]], paired = FALSE, ...)}. 40 | 41 | For the \code{ard_stats_paired_t_test()} function, the data is expected to be one row 42 | per subject per by level. Before the t-test is calculated, the data are 43 | reshaped to a wide format to be one row per subject. 44 | The data are then passed as 45 | \verb{t.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. 46 | } 47 | \examples{ 48 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 49 | cards::ADSL |> 50 | dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> 51 | ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) 52 | 53 | # constructing a paired data set, 54 | # where patients receive both treatments 55 | cards::ADSL[c("ARM", "AGE")] |> 56 | dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> 57 | dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> 58 | dplyr::arrange(USUBJID, ARM) |> 59 | ard_stats_paired_t_test(by = ARM, variables = AGE, id = USUBJID) 60 | \dontshow{\}) # examplesIf} 61 | } 62 | -------------------------------------------------------------------------------- /man/ard_stats_t_test_onesample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_t_test_onesample.R 3 | \name{ard_stats_t_test_onesample} 4 | \alias{ard_stats_t_test_onesample} 5 | \title{ARD one-sample t-test} 6 | \usage{ 7 | ard_stats_t_test_onesample( 8 | data, 9 | variables, 10 | by = dplyr::group_vars(data), 11 | conf.level = 0.95, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{(\code{data.frame})\cr 17 | a data frame. See below for details.} 18 | 19 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 20 | column names to be analyzed. Independent t-tests will be computed for 21 | each variable.} 22 | 23 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 24 | optional column name to stratify results by.} 25 | 26 | \item{conf.level}{(scalar \code{numeric})\cr 27 | confidence level for confidence interval. Default is \code{0.95}.} 28 | 29 | \item{...}{arguments passed to \code{t.test()}} 30 | } 31 | \value{ 32 | ARD data frame 33 | } 34 | \description{ 35 | Analysis results data for one-sample t-tests. 36 | Result may be stratified by including the \code{by} argument. 37 | } 38 | \examples{ 39 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 40 | cards::ADSL |> 41 | ard_stats_t_test_onesample(by = ARM, variables = AGE) 42 | \dontshow{\}) # examplesIf} 43 | } 44 | -------------------------------------------------------------------------------- /man/ard_stats_wilcox_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_wilcox_test.R 3 | \name{ard_stats_wilcox_test} 4 | \alias{ard_stats_wilcox_test} 5 | \alias{ard_stats_paired_wilcox_test} 6 | \title{ARD Wilcoxon Rank-Sum Test} 7 | \usage{ 8 | ard_stats_wilcox_test(data, variables, by = NULL, conf.level = 0.95, ...) 9 | 10 | ard_stats_paired_wilcox_test(data, by, variables, id, conf.level = 0.95, ...) 11 | } 12 | \arguments{ 13 | \item{data}{(\code{data.frame})\cr 14 | a data frame. See below for details.} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent tests will be computed for 18 | each variable.} 19 | 20 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 21 | optional column name to compare by.} 22 | 23 | \item{conf.level}{(scalar \code{numeric})\cr 24 | confidence level for confidence interval. Default is \code{0.95}.} 25 | 26 | \item{...}{arguments passed to \code{wilcox.test(...)}} 27 | 28 | \item{id}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 29 | column name of the subject or participant ID.} 30 | } 31 | \value{ 32 | ARD data frame 33 | } 34 | \description{ 35 | Analysis results data for paired and non-paired Wilcoxon Rank-Sum tests. 36 | } 37 | \details{ 38 | For the \code{ard_stats_wilcox_test()} function, the data is expected to be one row per subject. 39 | The data is passed as \code{wilcox.test(data[[variable]] ~ data[[by]], paired = FALSE, ...)}. 40 | 41 | For the \code{ard_stats_paired_wilcox_test()} function, the data is expected to be one row 42 | per subject per by level. Before the test is calculated, the data are 43 | reshaped to a wide format to be one row per subject. 44 | The data are then passed as 45 | \verb{wilcox.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. 46 | } 47 | \examples{ 48 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 49 | cards::ADSL |> 50 | dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> 51 | ard_stats_wilcox_test(by = "ARM", variables = "AGE") 52 | 53 | # constructing a paired data set, 54 | # where patients receive both treatments 55 | cards::ADSL[c("ARM", "AGE")] |> 56 | dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> 57 | dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> 58 | dplyr::arrange(USUBJID, ARM) |> 59 | ard_stats_paired_wilcox_test(by = ARM, variables = AGE, id = USUBJID) 60 | \dontshow{\}) # examplesIf} 61 | } 62 | -------------------------------------------------------------------------------- /man/ard_stats_wilcox_test_onesample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_wilcox_test_onesample.R 3 | \name{ard_stats_wilcox_test_onesample} 4 | \alias{ard_stats_wilcox_test_onesample} 5 | \title{ARD one-sample Wilcox Rank-sum} 6 | \usage{ 7 | ard_stats_wilcox_test_onesample( 8 | data, 9 | variables, 10 | by = dplyr::group_vars(data), 11 | conf.level = 0.95, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{(\code{data.frame})\cr 17 | a data frame. See below for details.} 18 | 19 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 20 | column names to be analyzed. Independent Wilcox Rank-sum tests will be computed for 21 | each variable.} 22 | 23 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 24 | optional column name to stratify results by.} 25 | 26 | \item{conf.level}{(scalar \code{numeric})\cr 27 | confidence level for confidence interval. Default is \code{0.95}.} 28 | 29 | \item{...}{arguments passed to \code{wilcox.test(...)}} 30 | } 31 | \value{ 32 | ARD data frame 33 | } 34 | \description{ 35 | Analysis results data for one-sample Wilcox Rank-sum. 36 | Result may be stratified by including the \code{by} argument. 37 | } 38 | \examples{ 39 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 40 | cards::ADSL |> 41 | ard_stats_wilcox_test_onesample(by = ARM, variables = AGE) 42 | \dontshow{\}) # examplesIf} 43 | } 44 | -------------------------------------------------------------------------------- /man/ard_survey_svychisq.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_survey_svychisq.R 3 | \name{ard_survey_svychisq} 4 | \alias{ard_survey_svychisq} 5 | \title{ARD Survey Chi-Square Test} 6 | \usage{ 7 | ard_survey_svychisq(data, by, variables, statistic = "F", ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{survey.design})\cr 11 | a survey design object often created with the \{survey\} package} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by.} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent tests will be computed for 18 | each variable.} 19 | 20 | \item{statistic}{(\code{character})\cr 21 | statistic used to estimate Chisq p-value. 22 | Default is the Rao-Scott second-order correction ("F"). See \code{\link[survey:svychisq]{survey::svychisq}} 23 | for available statistics options.} 24 | 25 | \item{...}{arguments passed to \code{\link[survey:svychisq]{survey::svychisq()}}.} 26 | } 27 | \value{ 28 | ARD data frame 29 | } 30 | \description{ 31 | Analysis results data for survey Chi-Square test using \code{\link[survey:svychisq]{survey::svychisq()}}. 32 | Only two-way comparisons are supported. 33 | } 34 | \examples{ 35 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 36 | data(api, package = "survey") 37 | dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) 38 | 39 | ard_survey_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F") 40 | \dontshow{\}) # examplesIf} 41 | } 42 | -------------------------------------------------------------------------------- /man/ard_survey_svyranktest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_survey_svyranktest.R 3 | \name{ard_survey_svyranktest} 4 | \alias{ard_survey_svyranktest} 5 | \title{ARD Survey rank test} 6 | \usage{ 7 | ard_survey_svyranktest(data, by, variables, test, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{survey.design})\cr 11 | a survey design object often created with \code{\link[survey:svydesign]{survey::svydesign()}}} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent tests will be run for each variable.} 18 | 19 | \item{test}{(\code{string})\cr 20 | a string to denote which rank test to use: 21 | \code{"wilcoxon"}, \code{"vanderWaerden"}, \code{"median"}, \code{"KruskalWallis"}} 22 | 23 | \item{...}{arguments passed to \code{\link[survey:svyranktest]{survey::svyranktest()}}} 24 | } 25 | \value{ 26 | ARD data frame 27 | } 28 | \description{ 29 | Analysis results data for survey wilcox test using \code{\link[survey:svyranktest]{survey::svyranktest()}}. 30 | } 31 | \examples{ 32 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 33 | data(api, package = "survey") 34 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 35 | 36 | ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "wilcoxon") 37 | ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "vanderWaerden") 38 | ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") 39 | ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis") 40 | \dontshow{\}) # examplesIf} 41 | } 42 | -------------------------------------------------------------------------------- /man/ard_survey_svyttest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_survey_svyttest.R 3 | \name{ard_survey_svyttest} 4 | \alias{ard_survey_svyttest} 5 | \title{ARD Survey t-test} 6 | \usage{ 7 | ard_survey_svyttest(data, by, variables, conf.level = 0.95, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{survey.design})\cr 11 | a survey design object often created with \code{\link[survey:svydesign]{survey::svydesign()}}} 12 | 13 | \item{by}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 14 | column name to compare by} 15 | 16 | \item{variables}{(\code{\link[dplyr:dplyr_tidy_select]{tidy-select}})\cr 17 | column names to be compared. Independent tests will be run for each variable.} 18 | 19 | \item{conf.level}{(\code{double})\cr 20 | confidence level of the returned confidence interval. Must be between \code{c(0, 1)}. 21 | Default is \code{0.95}} 22 | 23 | \item{...}{arguments passed to \code{\link[survey:svyttest]{survey::svyttest()}}} 24 | } 25 | \value{ 26 | ARD data frame 27 | } 28 | \description{ 29 | Analysis results data for survey t-test using \code{\link[survey:svyttest]{survey::svyttest()}}. 30 | } 31 | \examples{ 32 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 33 | data(api, package = "survey") 34 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 35 | 36 | ard_survey_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9) 37 | \dontshow{\}) # examplesIf} 38 | } 39 | -------------------------------------------------------------------------------- /man/ard_survival_survdiff.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_survival_survdiff.R 3 | \name{ard_survival_survdiff} 4 | \alias{ard_survival_survdiff} 5 | \title{ARD for Difference in Survival} 6 | \usage{ 7 | ard_survival_survdiff(formula, data, rho = 0, ...) 8 | } 9 | \arguments{ 10 | \item{formula}{(\code{formula})\cr 11 | a formula} 12 | 13 | \item{data}{(\code{data.frame})\cr 14 | a data frame} 15 | 16 | \item{rho}{(\verb{scalar numeric})\cr 17 | numeric scalar passed to \code{survival::survdiff(rho)}. Default is \code{rho=0}.} 18 | 19 | \item{...}{additional arguments passed to \code{survival::survdiff()}} 20 | } 21 | \value{ 22 | an ARD data frame of class 'card' 23 | } 24 | \description{ 25 | Analysis results data for comparison of survival using \code{\link[survival:survdiff]{survival::survdiff()}}. 26 | } 27 | \examples{ 28 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "broom", "ggsurvfit")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 29 | library(survival) 30 | library(ggsurvfit) 31 | 32 | ard_survival_survdiff(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE) 33 | \dontshow{\}) # examplesIf} 34 | } 35 | -------------------------------------------------------------------------------- /man/ard_survival_survfit_diff.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_survival_survfit_diff.R 3 | \name{ard_survival_survfit_diff} 4 | \alias{ard_survival_survfit_diff} 5 | \title{ARD Survival Differences} 6 | \usage{ 7 | ard_survival_survfit_diff(x, times, conf.level = 0.95) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{survift})\cr 11 | object of class \code{'survfit'} typically created with \code{\link[survival:survfit]{survival::survfit()}}} 12 | 13 | \item{times}{(\code{numeric})\cr 14 | a vector of times for which to return survival probabilities.} 15 | 16 | \item{conf.level}{(scalar \code{numeric})\cr 17 | confidence level for confidence interval. Default is \code{0.95}.} 18 | } 19 | \value{ 20 | an ARD data frame of class 'card' 21 | } 22 | \description{ 23 | Calculate differences in the Kaplan-Meier estimator of survival using the 24 | results from \code{\link[survival:survfit]{survival::survfit()}}. 25 | } 26 | \examples{ 27 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "ggsurvfit")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 28 | library(ggsurvfit) 29 | library(survival) 30 | 31 | survfit(Surv_CNSR() ~ TRTA, data = cards::ADTTE) |> 32 | ard_survival_survfit_diff(times = c(25, 50)) 33 | \dontshow{\}) # examplesIf} 34 | } 35 | -------------------------------------------------------------------------------- /man/ard_total_n.survey.design.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/add_total_n.survey.design.R 3 | \name{ard_total_n.survey.design} 4 | \alias{ard_total_n.survey.design} 5 | \title{ARD Total N} 6 | \usage{ 7 | \method{ard_total_n}{survey.design}(data, ...) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{survey.design})\cr 11 | a design object often created with \code{\link[survey:svydesign]{survey::svydesign()}}.} 12 | 13 | \item{...}{These dots are for future extensions and must be empty.} 14 | } 15 | \value{ 16 | an ARD data frame of class 'card' 17 | } 18 | \description{ 19 | Returns the total N for a survey object. 20 | The placeholder variable name returned in the object is \code{"..ard_total_n.."} 21 | } 22 | \examples{ 23 | \dontshow{if (cardx:::is_pkg_installed("survey")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 24 | svy_titanic <- survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) 25 | 26 | ard_total_n(svy_titanic) 27 | \dontshow{\}) # examplesIf} 28 | } 29 | -------------------------------------------------------------------------------- /man/cardx-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cardx-package.R 3 | \docType{package} 4 | \name{cardx-package} 5 | \alias{cardx} 6 | \alias{cardx-package} 7 | \title{cardx: Extra Analysis Results Data Utilities} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} 10 | 11 | Create extra Analysis Results Data (ARD) summary objects. The package supplements the simple ARD functions from the 'cards' package, exporting functions to put statistical results in the ARD format. These objects are used and re-used to construct summary tables, visualizations, and written reports. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item \url{https://github.com/insightsengineering/cardx} 17 | \item \url{https://insightsengineering.github.io/cardx/} 18 | \item Report bugs at \url{https://github.com/insightsengineering/cardx/issues} 19 | } 20 | 21 | } 22 | \author{ 23 | \strong{Maintainer}: Daniel D. Sjoberg \email{danield.sjoberg@gmail.com} (\href{https://orcid.org/0000-0003-0862-2018}{ORCID}) 24 | 25 | Authors: 26 | \itemize{ 27 | \item Abinaya Yogasekaram \email{abinaya.yogasekaram@contractors.roche.com} 28 | \item Emily de la Rua \email{emily.de_la_rua@contractors.roche.com} 29 | } 30 | 31 | Other contributors: 32 | \itemize{ 33 | \item F. Hoffmann-La Roche AG [copyright holder, funder] 34 | } 35 | 36 | } 37 | \keyword{internal} 38 | -------------------------------------------------------------------------------- /man/dot-check_dichotomous_value.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_dichotomous.survey.design.R 3 | \name{.check_dichotomous_value} 4 | \alias{.check_dichotomous_value} 5 | \title{Perform Value Checks} 6 | \usage{ 7 | .check_dichotomous_value(data, value) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr 11 | a data frame} 12 | 13 | \item{value}{(named \code{list})\cr 14 | a named list} 15 | } 16 | \value{ 17 | returns invisible if check is successful, throws an error message if not. 18 | } 19 | \description{ 20 | Check the validity of the values passed in \code{ard_dichotomous(value)}. 21 | } 22 | \examples{ 23 | cardx:::.check_dichotomous_value(mtcars, list(cyl = 4)) 24 | } 25 | \keyword{internal} 26 | -------------------------------------------------------------------------------- /man/dot-extract_wald_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_aod_wald_test.R 3 | \name{.extract_wald_results} 4 | \alias{.extract_wald_results} 5 | \title{Extract data from wald.test object} 6 | \usage{ 7 | .extract_wald_results(wald_test) 8 | } 9 | \arguments{ 10 | \item{wald_test}{(\code{data.frame})\cr wald test object object from \code{aod::wald.test()}} 11 | } 12 | \value{ 13 | a data frame containing the wald test results. 14 | } 15 | \description{ 16 | Extract data from wald.test object 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /man/dot-format_cohens_d_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_effectsize_cohens_d.R 3 | \name{.format_cohens_d_results} 4 | \alias{.format_cohens_d_results} 5 | \title{Convert Cohen's D Test to ARD} 6 | \usage{ 7 | .format_cohens_d_results(by, variable, lst_tidy, paired, ...) 8 | } 9 | \arguments{ 10 | \item{by}{(\code{string})\cr by column name} 11 | 12 | \item{variable}{(\code{string})\cr variable column name} 13 | 14 | \item{lst_tidy}{(named \code{list})\cr 15 | list of tidied results constructed with \code{\link[cards:eval_capture_conditions]{eval_capture_conditions()}}, 16 | e.g. \code{eval_capture_conditions(t.test(mtcars$mpg ~ mtcars$am) |> broom::tidy())}.} 17 | 18 | \item{paired}{If \code{TRUE}, the values of \code{x} and \code{y} are considered as paired. 19 | This produces an effect size that is equivalent to the one-sample effect 20 | size on \code{x - y}. See also \code{\link[effectsize:repeated_measures_d]{repeated_measures_d()}} for more options.} 21 | 22 | \item{...}{passed to \code{cohens_d(...)}} 23 | } 24 | \value{ 25 | ARD data frame 26 | } 27 | \description{ 28 | Convert Cohen's D Test to ARD 29 | } 30 | \examples{ 31 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 32 | cardx:::.format_cohens_d_results( 33 | by = "ARM", 34 | variable = "AGE", 35 | paired = FALSE, 36 | lst_tidy = 37 | cards::eval_capture_conditions( 38 | effectsize::hedges_g(data[[variable]] ~ data[[by]], paired = FALSE) |> 39 | parameters::standardize_names(style = "broom") 40 | ) 41 | ) 42 | \dontshow{\}) # examplesIf} 43 | } 44 | \keyword{internal} 45 | -------------------------------------------------------------------------------- /man/dot-format_hedges_g_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_effectsize_hedges_g.R 3 | \name{.format_hedges_g_results} 4 | \alias{.format_hedges_g_results} 5 | \title{Convert Hedge's G Test to ARD} 6 | \usage{ 7 | .format_hedges_g_results(by, variable, lst_tidy, paired, ...) 8 | } 9 | \arguments{ 10 | \item{by}{(\code{string})\cr by column name} 11 | 12 | \item{variable}{(\code{string})\cr variable column name} 13 | 14 | \item{lst_tidy}{(named \code{list})\cr 15 | list of tidied results constructed with \code{\link[cards:eval_capture_conditions]{eval_capture_conditions()}}, 16 | e.g. \code{eval_capture_conditions(t.test(mtcars$mpg ~ mtcars$am) |> broom::tidy())}.} 17 | 18 | \item{paired}{If \code{TRUE}, the values of \code{x} and \code{y} are considered as paired. 19 | This produces an effect size that is equivalent to the one-sample effect 20 | size on \code{x - y}. See also \code{\link[effectsize:repeated_measures_d]{repeated_measures_d()}} for more options.} 21 | 22 | \item{...}{passed to \code{hedges_g(...)}} 23 | } 24 | \value{ 25 | ARD data frame 26 | } 27 | \description{ 28 | Convert Hedge's G Test to ARD 29 | } 30 | \examples{ 31 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 32 | cardx:::.format_hedges_g_results( 33 | by = "ARM", 34 | variable = "AGE", 35 | paired = FALSE, 36 | lst_tidy = 37 | cards::eval_capture_conditions( 38 | effectsize::hedges_g(data[[variable]] ~ data[[by]], paired = FALSE) |> 39 | parameters::standardize_names(style = "broom") 40 | ) 41 | ) 42 | \dontshow{\}) # examplesIf} 43 | } 44 | \keyword{internal} 45 | -------------------------------------------------------------------------------- /man/dot-format_mcnemartest_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_mcnemar_test.R 3 | \name{.format_mcnemartest_results} 4 | \alias{.format_mcnemartest_results} 5 | \title{Convert McNemar's test to ARD} 6 | \usage{ 7 | .format_mcnemartest_results(by, variable, lst_tidy, ...) 8 | } 9 | \arguments{ 10 | \item{by}{(\code{string})\cr by column name} 11 | 12 | \item{variable}{(\code{string})\cr variable column name} 13 | 14 | \item{lst_tidy}{(named \code{list})\cr 15 | list of tidied results constructed with \code{\link[cards:eval_capture_conditions]{eval_capture_conditions()}}, 16 | e.g. \code{eval_capture_conditions(t.test(mtcars$mpg ~ mtcars$am) |> broom::tidy())}.} 17 | 18 | \item{...}{passed to \code{stats::mcnemar.test(...)}} 19 | } 20 | \value{ 21 | ARD data frame 22 | } 23 | \description{ 24 | Convert McNemar's test to ARD 25 | } 26 | \examples{ 27 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 28 | cardx:::.format_mcnemartest_results( 29 | by = "ARM", 30 | variable = "AGE", 31 | lst_tidy = 32 | cards::eval_capture_conditions( 33 | stats::mcnemar.test(cards::ADSL[["SEX"]], cards::ADSL[["EFFFL"]]) |> 34 | broom::tidy() 35 | ) 36 | ) 37 | \dontshow{\}) # examplesIf} 38 | } 39 | \keyword{internal} 40 | -------------------------------------------------------------------------------- /man/dot-format_moodtest_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_mood_test.R 3 | \name{.format_moodtest_results} 4 | \alias{.format_moodtest_results} 5 | \title{Convert mood test results to ARD} 6 | \usage{ 7 | .format_moodtest_results(by, variable, lst_tidy, ...) 8 | } 9 | \arguments{ 10 | \item{by}{(\code{string})\cr by column name} 11 | 12 | \item{variable}{(\code{string})\cr variable column name} 13 | 14 | \item{lst_tidy}{(named \code{list})\cr 15 | list of tidied results constructed with \code{\link[cards:eval_capture_conditions]{eval_capture_conditions()}}, 16 | e.g. \code{eval_capture_conditions(t.test(mtcars$mpg ~ mtcars$am) |> broom::tidy())}.} 17 | 18 | \item{...}{passed to \code{mood.test(...)}} 19 | } 20 | \value{ 21 | ARD data frame 22 | } 23 | \description{ 24 | Convert mood test results to ARD 25 | } 26 | \examples{ 27 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 28 | cardx:::.format_moodtest_results( 29 | by = "SEX", 30 | variable = "AGE", 31 | lst_tidy = 32 | cards::eval_capture_conditions( 33 | stats::mood.test(ADSL[["AGE"]] ~ ADSL[["SEX"]]) |> 34 | broom::tidy() 35 | ) 36 | ) 37 | \dontshow{\}) # examplesIf} 38 | } 39 | \keyword{internal} 40 | -------------------------------------------------------------------------------- /man/dot-format_poissontest_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_poisson_test.R 3 | \name{.format_poissontest_results} 4 | \alias{.format_poissontest_results} 5 | \title{Convert Poisson test to ARD} 6 | \usage{ 7 | .format_poissontest_results(by = NULL, variables, lst_tidy, ...) 8 | } 9 | \arguments{ 10 | \item{by}{(\code{string})\cr by column name} 11 | 12 | \item{variables}{(\code{character})\cr names of the event and time variables} 13 | 14 | \item{lst_tidy}{(named \code{list})\cr 15 | list of tidied results constructed with \code{\link[cards:eval_capture_conditions]{eval_capture_conditions()}}, 16 | e.g. \code{eval_capture_conditions(t.test(mtcars$mpg ~ mtcars$am) |> broom::tidy())}.} 17 | 18 | \item{...}{passed to \code{\link[=poisson.test]{poisson.test()}}} 19 | } 20 | \value{ 21 | ARD data frame 22 | } 23 | \description{ 24 | Convert Poisson test to ARD 25 | } 26 | \examples{ 27 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 28 | cardx:::.format_poissontest_results( 29 | by = "ARM", 30 | variables = c("CNSR", "AVAL"), 31 | lst_tidy = 32 | cards::eval_capture_conditions( 33 | stats::poisson.test(sum(cards::ADTTE[["CNSR"]]), sum(cards::ADTTE[["AVAL"]])) |> 34 | broom::tidy() 35 | ) 36 | ) 37 | \dontshow{\}) # examplesIf} 38 | } 39 | \keyword{internal} 40 | -------------------------------------------------------------------------------- /man/dot-format_proptest_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_prop_test.R 3 | \name{.format_proptest_results} 4 | \alias{.format_proptest_results} 5 | \title{Convert prop.test to ARD} 6 | \usage{ 7 | .format_proptest_results(by, variable, lst_tidy, ...) 8 | } 9 | \arguments{ 10 | \item{by}{(\code{string})\cr by column name} 11 | 12 | \item{variable}{(\code{string})\cr variable column name} 13 | 14 | \item{lst_tidy}{(named \code{list})\cr 15 | list of tidied results constructed with \code{\link[cards:eval_capture_conditions]{eval_capture_conditions()}}, 16 | e.g. \code{eval_capture_conditions(t.test(mtcars$mpg ~ mtcars$am) |> broom::tidy())}.} 17 | 18 | \item{...}{passed to \code{prop.test(...)}} 19 | } 20 | \value{ 21 | ARD data frame 22 | } 23 | \description{ 24 | Convert prop.test to ARD 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/dot-format_survfit_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_survival_survfit.R 3 | \name{.format_survfit_results} 4 | \alias{.format_survfit_results} 5 | \title{Convert Tidied Survival Fit to ARD} 6 | \usage{ 7 | .format_survfit_results(tidy_survfit) 8 | } 9 | \value{ 10 | an ARD data frame of class 'card' 11 | } 12 | \description{ 13 | Convert Tidied Survival Fit to ARD 14 | } 15 | \examples{ 16 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "broom")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 17 | cardx:::.format_survfit_results( 18 | broom::tidy(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE)) 19 | ) 20 | \dontshow{\}) # examplesIf} 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/dot-format_ttest_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_t_test.R 3 | \name{.format_ttest_results} 4 | \alias{.format_ttest_results} 5 | \title{Convert t-test to ARD} 6 | \usage{ 7 | .format_ttest_results(by = NULL, variable, lst_tidy, paired, ...) 8 | } 9 | \arguments{ 10 | \item{by}{(\code{string})\cr by column name} 11 | 12 | \item{variable}{(\code{string})\cr variable column name} 13 | 14 | \item{lst_tidy}{(named \code{list})\cr 15 | list of tidied results constructed with \code{\link[cards:eval_capture_conditions]{eval_capture_conditions()}}, 16 | e.g. \code{eval_capture_conditions(t.test(mtcars$mpg ~ mtcars$am) |> broom::tidy())}.} 17 | 18 | \item{paired}{a logical indicating whether you want a paired 19 | t-test.} 20 | 21 | \item{...}{passed to \code{t.test(...)}} 22 | } 23 | \value{ 24 | ARD data frame 25 | } 26 | \description{ 27 | Convert t-test to ARD 28 | } 29 | \examples{ 30 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 31 | cardx:::.format_ttest_results( 32 | by = "ARM", 33 | variable = "AGE", 34 | paired = FALSE, 35 | lst_tidy = 36 | cards::eval_capture_conditions( 37 | stats::t.test(ADSL[["AGE"]] ~ ADSL[["ARM"]], paired = FALSE) |> 38 | broom::tidy() 39 | ) 40 | ) 41 | \dontshow{\}) # examplesIf} 42 | } 43 | \keyword{internal} 44 | -------------------------------------------------------------------------------- /man/dot-format_wilcoxtest_results.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_wilcox_test.R 3 | \name{.format_wilcoxtest_results} 4 | \alias{.format_wilcoxtest_results} 5 | \title{Convert Wilcoxon test to ARD} 6 | \usage{ 7 | .format_wilcoxtest_results(by = NULL, variable, lst_tidy, paired, ...) 8 | } 9 | \arguments{ 10 | \item{by}{(\code{string})\cr by column name} 11 | 12 | \item{variable}{(\code{string})\cr variable column name} 13 | 14 | \item{lst_tidy}{(named \code{list})\cr 15 | list of tidied results constructed with \code{\link[cards:eval_capture_conditions]{eval_capture_conditions()}}, 16 | e.g. \code{eval_capture_conditions(t.test(mtcars$mpg ~ mtcars$am) |> broom::tidy())}.} 17 | 18 | \item{paired}{a logical indicating whether you want a paired test.} 19 | 20 | \item{...}{passed to \code{stats::wilcox.test(...)}} 21 | } 22 | \value{ 23 | ARD data frame 24 | } 25 | \description{ 26 | Convert Wilcoxon test to ARD 27 | } 28 | \examples{ 29 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 30 | # Pre-processing ADSL to have grouping factor (ARM here) with 2 levels 31 | ADSL <- cards::ADSL |> 32 | dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> 33 | ard_stats_wilcox_test(by = "ARM", variables = "AGE") 34 | 35 | cardx:::.format_wilcoxtest_results( 36 | by = "ARM", 37 | variable = "AGE", 38 | paired = FALSE, 39 | lst_tidy = 40 | cards::eval_capture_conditions( 41 | stats::wilcox.test(ADSL[["AGE"]] ~ ADSL[["ARM"]], paired = FALSE) |> 42 | broom::tidy() 43 | ) 44 | ) 45 | \dontshow{\}) # examplesIf} 46 | } 47 | \keyword{internal} 48 | -------------------------------------------------------------------------------- /man/dot-paired_data_pivot_wider.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_stats_t_test.R 3 | \name{.paired_data_pivot_wider} 4 | \alias{.paired_data_pivot_wider} 5 | \title{Convert long paired data to wide} 6 | \usage{ 7 | .paired_data_pivot_wider(data, by, variable, id) 8 | } 9 | \arguments{ 10 | \item{data}{(\code{data.frame})\cr a data frame that is one line per subject per group} 11 | 12 | \item{by}{(\code{string})\cr by column name} 13 | 14 | \item{variable}{(\code{string})\cr variable column name} 15 | 16 | \item{id}{(\code{string})\cr subject id column name} 17 | } 18 | \value{ 19 | a wide data frame 20 | } 21 | \description{ 22 | Convert long paired data to wide 23 | } 24 | \examples{ 25 | cards::ADSL[c("ARM", "AGE")] |> 26 | dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> 27 | dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> 28 | dplyr::arrange(USUBJID, ARM) |> 29 | cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID") 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /man/dot-process_nested_list_as_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_categorical.survey.design.R 3 | \name{.process_nested_list_as_df} 4 | \alias{.process_nested_list_as_df} 5 | \title{Convert Nested Lists to Column} 6 | \usage{ 7 | .process_nested_list_as_df(x, arg, new_column, unlist = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{data.frame})\cr 11 | result data frame} 12 | 13 | \item{arg}{(\code{list})\cr 14 | the nested list} 15 | 16 | \item{new_column}{(\code{string})\cr 17 | new column name} 18 | 19 | \item{unlist}{(\code{logical})\cr 20 | whether to fully unlist final results} 21 | } 22 | \value{ 23 | a data frame 24 | } 25 | \description{ 26 | Some arguments, such as \code{stat_label}, are passed as nested lists. This 27 | function properly unnests these lists and adds them to the results data frame. 28 | } 29 | \examples{ 30 | ard <- ard_categorical(cards::ADSL, by = "ARM", variables = "AGEGR1") 31 | 32 | cardx:::.process_nested_list_as_df(ard, NULL, "new_col") 33 | } 34 | \keyword{internal} 35 | -------------------------------------------------------------------------------- /man/dot-process_survfit_probs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_survival_survfit.R 3 | \name{.process_survfit_probs} 4 | \alias{.process_survfit_probs} 5 | \title{Process Survival Fit For Quantile Estimates} 6 | \usage{ 7 | .process_survfit_probs(x, probs) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{survfit} or \code{data.frame})\cr 11 | an object of class \code{survfit} created with \code{\link[survival:survfit]{survival::survfit()}} or a data frame. See below for details.} 12 | 13 | \item{probs}{(\code{numeric})\cr 14 | a vector of probabilities with values in (0,1) specifying the survival quantiles to return.} 15 | } 16 | \value{ 17 | a \code{tibble} 18 | } 19 | \description{ 20 | Process Survival Fit For Quantile Estimates 21 | } 22 | \examples{ 23 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survival"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 24 | survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> 25 | cardx:::.process_survfit_probs(probs = c(0.25, 0.75)) 26 | \dontshow{\}) # examplesIf} 27 | } 28 | \keyword{internal} 29 | -------------------------------------------------------------------------------- /man/dot-process_survfit_time.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_survival_survfit.R 3 | \name{.process_survfit_time} 4 | \alias{.process_survfit_time} 5 | \title{Process Survival Fit For Time Estimates} 6 | \usage{ 7 | .process_survfit_time(x, times, type, start.time = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{survfit} or \code{data.frame})\cr 11 | an object of class \code{survfit} created with \code{\link[survival:survfit]{survival::survfit()}} or a data frame. See below for details.} 12 | 13 | \item{times}{(\code{numeric})\cr 14 | a vector of times for which to return survival probabilities.} 15 | 16 | \item{type}{(\code{string} or \code{NULL})\cr 17 | type of statistic to report. Available for Kaplan-Meier time estimates only, otherwise \code{type} 18 | is ignored. Default is \code{NULL}. 19 | Must be one of the following:\tabular{ll}{ 20 | type \tab transformation \cr 21 | \code{"survival"} \tab \code{x} \cr 22 | \code{"risk"} \tab \code{1 - x} \cr 23 | \code{"cumhaz"} \tab \code{-log(x)} \cr 24 | }} 25 | 26 | \item{start.time}{(\code{numeric})\cr 27 | default starting time. See \code{\link[survival:survfit0]{survival::survfit0()}} for more details.} 28 | } 29 | \value{ 30 | a \code{tibble} 31 | } 32 | \description{ 33 | Process Survival Fit For Time Estimates 34 | } 35 | \examples{ 36 | \dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "broom")))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 37 | survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> 38 | cardx:::.process_survfit_time(times = c(60, 180), type = "risk") 39 | \dontshow{\}) # examplesIf} 40 | } 41 | \keyword{internal} 42 | -------------------------------------------------------------------------------- /man/dot-strata_normal_quantile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/proportion_ci.R 3 | \name{.strata_normal_quantile} 4 | \alias{.strata_normal_quantile} 5 | \title{Helper Function for the Estimation of Stratified Quantiles} 6 | \usage{ 7 | .strata_normal_quantile(vars, weights, conf.level) 8 | } 9 | \arguments{ 10 | \item{weights}{(\code{numeric})\cr weights for each level of the strata. If \code{NULL}, they are 11 | estimated using the iterative algorithm that 12 | minimizes the weighted squared length of the confidence interval.} 13 | 14 | \item{conf.level}{(scalar \code{numeric})\cr 15 | a scalar in \verb{(0,1)} indicating the confidence level. 16 | Default is \code{0.95}} 17 | } 18 | \value{ 19 | Stratified quantile. 20 | } 21 | \description{ 22 | This function wraps the estimation of stratified percentiles when we assume 23 | the approximation for large numbers. This is necessary only in the case 24 | proportions for each strata are unequal. 25 | } 26 | \examples{ 27 | strata_data <- table(data.frame( 28 | "f1" = sample(c(TRUE, FALSE), 100, TRUE), 29 | "f2" = sample(c("x", "y", "z"), 100, TRUE), 30 | stringsAsFactors = TRUE 31 | )) 32 | ns <- colSums(strata_data) 33 | ests <- strata_data["TRUE", ] / ns 34 | vars <- ests * (1 - ests) / ns 35 | weights <- rep(1 / length(ns), length(ns)) 36 | 37 | cardx:::.strata_normal_quantile(vars, weights, 0.95) 38 | } 39 | \seealso{ 40 | \code{\link[=proportion_ci_strat_wilson]{proportion_ci_strat_wilson()}} 41 | } 42 | \keyword{internal} 43 | -------------------------------------------------------------------------------- /man/dot-unique_and_sorted.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ard_dichotomous.survey.design.R 3 | \name{.unique_and_sorted} 4 | \alias{.unique_and_sorted} 5 | \title{ARD-flavor of unique()} 6 | \usage{ 7 | .unique_and_sorted(x, useNA = c("no", "always")) 8 | } 9 | \arguments{ 10 | \item{x}{(\code{any})\cr 11 | a vector} 12 | } 13 | \value{ 14 | a vector 15 | } 16 | \description{ 17 | Essentially a wrapper for \code{unique(x) |> sort()} with \code{NA} levels removed. 18 | For factors, all levels are returned even if they are unobserved. 19 | Similarly, logical vectors always return \code{c(TRUE, FALSE)}, even if 20 | both levels are not observed. 21 | } 22 | \examples{ 23 | cards:::.unique_and_sorted(factor(letters[c(5, 5:1)], levels = letters)) 24 | 25 | cards:::.unique_and_sorted(c(FALSE, TRUE, TRUE, FALSE)) 26 | 27 | cards:::.unique_and_sorted(c(5, 5:1)) 28 | } 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/dot-update_weights_strat_wilson.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/proportion_ci.R 3 | \name{.update_weights_strat_wilson} 4 | \alias{.update_weights_strat_wilson} 5 | \title{Helper Function for the Estimation of Weights for \code{proportion_ci_strat_wilson()}} 6 | \usage{ 7 | .update_weights_strat_wilson( 8 | vars, 9 | strata_qnorm, 10 | initial_weights, 11 | n_per_strata, 12 | max.iterations = 50, 13 | conf.level = 0.95, 14 | tol = 0.001 15 | ) 16 | } 17 | \arguments{ 18 | \item{vars}{(\code{numeric})\cr normalized proportions for each strata.} 19 | 20 | \item{strata_qnorm}{(\code{numeric})\cr initial estimation with identical weights of the quantiles.} 21 | 22 | \item{initial_weights}{(\code{numeric})\cr initial weights used to calculate \code{strata_qnorm}. This can 23 | be optimized in the future if we need to estimate better initial weights.} 24 | 25 | \item{n_per_strata}{(\code{numeric})\cr number of elements in each strata.} 26 | 27 | \item{max.iterations}{(\code{count})\cr maximum number of iterations to be tried. Convergence is always checked.} 28 | 29 | \item{conf.level}{(scalar \code{numeric})\cr 30 | a scalar in \verb{(0,1)} indicating the confidence level. 31 | Default is \code{0.95}} 32 | 33 | \item{tol}{(\code{number})\cr tolerance threshold for convergence.} 34 | } 35 | \value{ 36 | A \code{list} of 3 elements: \code{n_it}, \code{weights}, and \code{diff_v}. 37 | } 38 | \description{ 39 | This function wraps the iteration procedure that allows you to estimate 40 | the weights for each proportional strata. This assumes to minimize the 41 | weighted squared length of the confidence interval. 42 | } 43 | \examples{ 44 | vs <- c(0.011, 0.013, 0.012, 0.014, 0.017, 0.018) 45 | sq <- 0.674 46 | ws <- rep(1 / length(vs), length(vs)) 47 | ns <- c(22, 18, 17, 17, 14, 12) 48 | 49 | cardx:::.update_weights_strat_wilson(vs, sq, ws, ns, 100, 0.95, 0.001) 50 | } 51 | \seealso{ 52 | For references and details see \code{\link[=proportion_ci_strat_wilson]{proportion_ci_strat_wilson()}}. 53 | } 54 | \keyword{internal} 55 | -------------------------------------------------------------------------------- /man/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: archived 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | archived 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: defunct 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | defunct 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: deprecated 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | deprecated 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: experimental 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | experimental 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: maturing 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | maturing 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: questioning 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | questioning 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-soft-deprecated.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: soft-deprecated 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | soft-deprecated 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: stable 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | lifecycle 21 | 22 | 25 | 26 | stable 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /man/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: superseded 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | superseded 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/man/figures/logo.png -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reexports.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{ard_continuous} 7 | \alias{ard_categorical} 8 | \alias{ard_dichotomous} 9 | \alias{ard_missing} 10 | \alias{ard_attributes} 11 | \alias{ard_total_n} 12 | \alias{\%>\%} 13 | \alias{starts_with} 14 | \alias{ends_with} 15 | \alias{contains} 16 | \alias{matches} 17 | \alias{num_range} 18 | \alias{all_of} 19 | \alias{any_of} 20 | \alias{everything} 21 | \alias{where} 22 | \alias{last_col} 23 | \alias{one_of} 24 | \title{Objects exported from other packages} 25 | \keyword{internal} 26 | \description{ 27 | These objects are imported from other packages. Follow the links 28 | below to see their documentation. 29 | 30 | \describe{ 31 | \item{cards}{\code{\link[cards]{ard_attributes}}, \code{\link[cards]{ard_categorical}}, \code{\link[cards]{ard_continuous}}, \code{\link[cards]{ard_dichotomous}}, \code{\link[cards]{ard_missing}}, \code{\link[cards]{ard_total_n}}} 32 | 33 | \item{dplyr}{\code{\link[dplyr:reexports]{\%>\%}}, \code{\link[dplyr:reexports]{all_of}}, \code{\link[dplyr:reexports]{any_of}}, \code{\link[dplyr:reexports]{contains}}, \code{\link[dplyr:reexports]{ends_with}}, \code{\link[dplyr:reexports]{everything}}, \code{\link[dplyr:reexports]{last_col}}, \code{\link[dplyr:reexports]{matches}}, \code{\link[dplyr:reexports]{num_range}}, \code{\link[dplyr:reexports]{one_of}}, \code{\link[dplyr:reexports]{starts_with}}, \code{\link[dplyr:reexports]{where}}} 34 | }} 35 | 36 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/favicon-96x96.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /pkgdown/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/web-app-manifest-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png", 9 | "purpose": "maskable" 10 | }, 11 | { 12 | "src": "/web-app-manifest-512x512.png", 13 | "sizes": "512x512", 14 | "type": "image/png", 15 | "purpose": "maskable" 16 | } 17 | ], 18 | "theme_color": "#ffffff", 19 | "background_color": "#ffffff", 20 | "display": "standalone" 21 | } -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/web-app-manifest-192x192.png -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/insightsengineering/cardx/07dbdc9a1b67306dc6d990de5cbf6f23075e9bf7/pkgdown/favicon/web-app-manifest-512x512.png -------------------------------------------------------------------------------- /revdep/.gitignore: -------------------------------------------------------------------------------- 1 | checks 2 | library 3 | checks.noindex 4 | library.noindex 5 | cloud.noindex 6 | data.sqlite 7 | *.html 8 | -------------------------------------------------------------------------------- /revdep/README.md: -------------------------------------------------------------------------------- 1 | # Platform 2 | 3 | |field |value | 4 | |:--------|:------------------------------------------| 5 | |version |R version 4.4.2 (2024-10-31) | 6 | |os |macOS Ventura 13.6.9 | 7 | |system |aarch64, darwin20 | 8 | |ui |RStudio | 9 | |language |(EN) | 10 | |collate |en_US.UTF-8 | 11 | |ctype |en_US.UTF-8 | 12 | |tz |America/Los_Angeles | 13 | |date |2025-02-17 | 14 | |rstudio |2024.12.0+467.pro1 Kousa Dogwood (desktop) | 15 | |pandoc |3.4 @ /usr/local/bin/pandoc | 16 | 17 | # Dependencies 18 | 19 | |package |old |new |Δ | 20 | |:----------|:-----|:----------|:--| 21 | |cardx |0.2.2 |0.2.2.9023 |* | 22 | |cards |0.4.0 |0.5.0.9000 |* | 23 | |cli |NA |3.6.4 |* | 24 | |cpp11 |NA |0.5.1 |* | 25 | |fansi |NA |1.0.6 |* | 26 | |glue |NA |1.8.0 |* | 27 | |pillar |NA |1.10.1 |* | 28 | |purrr |NA |1.0.4 |* | 29 | |R6 |NA |2.6.1 |* | 30 | |rlang |NA |1.1.5 |* | 31 | |stringi |NA |1.8.4 |* | 32 | |tidyr |NA |1.3.1 |* | 33 | |tidyselect |NA |1.2.1 |* | 34 | |vctrs |NA |0.6.5 |* | 35 | |withr |NA |3.0.2 |* | 36 | 37 | # Revdeps 38 | 39 | -------------------------------------------------------------------------------- /revdep/cran.md: -------------------------------------------------------------------------------- 1 | ## revdepcheck results 2 | 3 | We checked 4 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 4 | 5 | * We saw 0 new problems 6 | * We failed to check 0 packages 7 | 8 | -------------------------------------------------------------------------------- /revdep/failures.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /revdep/problems.md: -------------------------------------------------------------------------------- 1 | *Wow, no problems at all. :)* -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | test_check("cardx", stop_on_warning = TRUE) 3 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_aod_wald_test.md: -------------------------------------------------------------------------------- 1 | # ard_aod_wald_test() works 2 | 3 | Code 4 | glm_ard_aod_waldtest[, 1:6] 5 | Message 6 | {cards} data frame: 6 x 6 7 | Output 8 | variable context stat_name stat_label stat fmt_fn 9 | 1 (Intercept) aod_wald… df Degrees … 1 1 10 | 2 (Intercept) aod_wald… statistic Statistic 7126.713 1 11 | 3 (Intercept) aod_wald… p.value p-value 0 1 12 | 4 ARM aod_wald… df Degrees … 2 1 13 | 5 ARM aod_wald… statistic Statistic 1.046 1 14 | 6 ARM aod_wald… p.value p-value 0.593 1 15 | 16 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_attributes.survey.design.md: -------------------------------------------------------------------------------- 1 | # ard_attributes.survey.design() works 2 | 3 | Code 4 | attr(dclus1$variables$sname, "label") <- "School Name" 5 | as.data.frame(ard_attributes(dclus1, variables = c(sname, dname), label = list(dname = "District Name"))) 6 | Output 7 | variable context stat_name stat_label stat fmt_fn warning error 8 | 1 sname attributes label Variable Label School Name .Primitive("as.character") NULL NULL 9 | 2 sname attributes class Variable Class character NULL NULL NULL 10 | 3 dname attributes label Variable Label District Name .Primitive("as.character") NULL NULL 11 | 4 dname attributes class Variable Class character NULL NULL NULL 12 | 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_car_anova.md: -------------------------------------------------------------------------------- 1 | # ard_car_anova() works 2 | 3 | Code 4 | glm_ard_car_anova 5 | Message 6 | {cards} data frame: 6 x 8 7 | Output 8 | variable context stat_name stat_label stat fmt_fn 9 | 1 factor(cyl) car_anova statistic Statistic 0 1 10 | 2 factor(cyl) car_anova df Degrees … 2 1 11 | 3 factor(cyl) car_anova p.value p-value 1 1 12 | 4 factor(am) car_anova statistic Statistic 0 1 13 | 5 factor(am) car_anova df Degrees … 1 1 14 | 6 factor(am) car_anova p.value p-value 0.998 1 15 | Message 16 | i 2 more variables: warning, error 17 | 18 | # ard_car_anova() messaging 19 | 20 | Code 21 | ard_car_anova(mtcars) 22 | Condition 23 | Error in `ard_car_anova()`: 24 | ! There was an error running `car::Anova()`. See error message below. 25 | x no applicable method for 'vcov' applied to an object of class "data.frame" 26 | 27 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_car_vif.md: -------------------------------------------------------------------------------- 1 | # ard_car_vif() works 2 | 3 | Code 4 | as.data.frame(ard_car_vif(lm(AGE ~ ARM + SEX, data = cards::ADSL))) 5 | Output 6 | variable context stat_name stat_label stat fmt_fn warning error 7 | 1 ARM car_vif GVIF GVIF 1.015675 1 NULL NULL 8 | 2 ARM car_vif df df 2 1 NULL NULL 9 | 3 ARM car_vif aGVIF Adjusted GVIF 1.003896 1 NULL NULL 10 | 4 SEX car_vif GVIF GVIF 1.015675 1 NULL NULL 11 | 5 SEX car_vif df df 1 1 NULL NULL 12 | 6 SEX car_vif aGVIF Adjusted GVIF 1.007807 1 NULL NULL 13 | 14 | --- 15 | 16 | Code 17 | as.data.frame(ard_car_vif(lm(AGE ~ BMIBL + EDUCLVL, data = cards::ADSL))) 18 | Output 19 | variable context stat_name stat_label stat fmt_fn warning error 20 | 1 BMIBL car_vif VIF VIF 1.010522 1 NULL NULL 21 | 2 EDUCLVL car_vif VIF VIF 1.010522 1 NULL NULL 22 | 23 | # ard_vif() issues friendly messaging for incorrect object passed in/can't get terms of model 24 | 25 | Code 26 | ard_car_vif(cards::ADSL) 27 | Condition 28 | Error in `ard_car_vif()`: 29 | ! There was an error running `car::vif()`. See below. 30 | x no applicable method for 'vcov' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')" 31 | 32 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_categorical.survey.design.md: -------------------------------------------------------------------------------- 1 | # ard_categorical.survey.design() returns an error when variables have all NAs 2 | 3 | Code 4 | ard_categorical(svy_titanic, variables = c(Class, Age), by = Survived, 5 | denominator = "row") 6 | Condition 7 | Error in `ard_categorical()`: 8 | ! Column "Class" is all missing and cannot be tabulated. 9 | i Only columns of class can be tabulated when all values are missing. 10 | 11 | --- 12 | 13 | Code 14 | ard_categorical(svy_titanic, variables = c(Class, Age), by = Survived, 15 | denominator = "column") 16 | Condition 17 | Error in `ard_categorical()`: 18 | ! Column "Class" is all missing and cannot be tabulated. 19 | i Only columns of class can be tabulated when all values are missing. 20 | 21 | --- 22 | 23 | Code 24 | ard_categorical(svy_titanic, variables = c(Class, Age), by = Survived, 25 | denominator = "cell") 26 | Condition 27 | Error in `ard_categorical()`: 28 | ! Column "Class" is all missing and cannot be tabulated. 29 | i Only columns of class can be tabulated when all values are missing. 30 | 31 | # ard_categorical.survey.design(by) messages about protected names 32 | 33 | Code 34 | ard_categorical(svy_mtcars, by = variable, variables = gear) 35 | Condition 36 | Error in `ard_categorical()`: 37 | ! The `by` argument cannot include variables named "variable", "variable_level", "group1_level", "p", and "n". 38 | 39 | --- 40 | 41 | Code 42 | ard_categorical(svy_mtcars, by = p.std.error, variables = name) 43 | Condition 44 | Error in `ard_categorical()`: 45 | ! The `variables` argument cannot include variables named "by", "name", "n", "p", and "p.std.error". 46 | 47 | # ard_categorical.survey.design() messaging with all NA lgl variables 48 | 49 | Code 50 | ard_categorical(survey::svydesign(~1, data = dplyr::tibble(fct = factor(c(NA, 51 | NA), levels = c("no", "yes")), lgl = c(NA, NA)), weights = ~1), variables = lgl) 52 | Condition 53 | Error in `ard_categorical()`: 54 | ! Column "lgl" is all missing and cannot be tabulated. 55 | i Only columns of class can be tabulated when all values are missing. 56 | 57 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_categorical_ci.survey.design.md: -------------------------------------------------------------------------------- 1 | # ard_categorical_ci(data) 2 | 3 | Code 4 | dplyr::select(ard_categorical_ci(dclus1, variables = c(both, awards)), -warning, 5 | -error, -fmt_fn, -context) 6 | Message 7 | {cards} data frame: 20 x 5 8 | Output 9 | variable variable_level stat_name stat_label stat 10 | 1 both No estimate estimate 0.273 11 | 2 both No conf.low conf.low 0.213 12 | 3 both No conf.high conf.high 0.343 13 | 4 both No method method logit 14 | 5 both No conf.level conf.lev… 0.95 15 | 6 both Yes estimate estimate 0.727 16 | 7 both Yes conf.low conf.low 0.657 17 | 8 both Yes conf.high conf.high 0.787 18 | 9 both Yes method method logit 19 | 10 both Yes conf.level conf.lev… 0.95 20 | 11 awards No estimate estimate 0.29 21 | 12 awards No conf.low conf.low 0.224 22 | 13 awards No conf.high conf.high 0.365 23 | 14 awards No method method logit 24 | 15 awards No conf.level conf.lev… 0.95 25 | 16 awards Yes estimate estimate 0.71 26 | 17 awards Yes conf.low conf.low 0.635 27 | 18 awards Yes conf.high conf.high 0.776 28 | 19 awards Yes method method logit 29 | 20 awards Yes conf.level conf.lev… 0.95 30 | 31 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_dichotomous.survey.design.md: -------------------------------------------------------------------------------- 1 | # ard_dichotomous.survey.design() returns an error with erroneous input 2 | 3 | Code 4 | ard_dichotomous(svy_dicho, by = vs, variables = c(cyl, am), value = list(cyl = 4), 5 | denominator = "row") 6 | Condition 7 | Error in `ard_dichotomous()`: 8 | ! Error in argument `value` for variable "cyl". 9 | i A value of 4 was passed, but must be one of TRUE and FALSE. 10 | i To summarize this value, make the column a factor and include 4 as a level. 11 | 12 | --- 13 | 14 | Code 15 | ard_dichotomous(svy_dicho, by = cyl, variables = c(vs, am), value = list(vs = 4), 16 | denominator = "row") 17 | Condition 18 | Error in `ard_dichotomous()`: 19 | ! Error in argument `value` for variable "vs". 20 | i A value of 4 was passed, but must be one of 0 and 1. 21 | i To summarize this value, use `forcats::fct_expand()` to add 4 as a level. 22 | 23 | --- 24 | 25 | Code 26 | ard_dichotomous(svy_dicho, by = cyl, variables = c(vs, disp), value = list( 27 | disp = "turn"), denominator = "row") 28 | Condition 29 | Error in `ard_dichotomous()`: 30 | ! Error in argument `value` for variable "disp". 31 | i A value of "turn" was passed, but must be one of 71.1, 75.7, 78.7, 79, 95.1, 108, 120.1, 120.3, 121, 140.8, 145, 146.7, 160, 167.6, 225, 258, 275.8, 301, ..., 460, and 472. 32 | i To summarize this value, make the column a factor and include "turn" as a level. 33 | 34 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_effectsize_cohens_d.md: -------------------------------------------------------------------------------- 1 | # ard_effectsize_cohens_d() works 2 | 3 | Code 4 | as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select( 5 | ard_effectsize_cohens_d(dplyr::filter(cards::ADSL, ARM %in% c("Placebo", 6 | "Xanomeline High Dose")), by = ARM, variables = c(BMIBL, HEIGHTBL)), c(1:3, 7 | 5:6)), variable), n = 3)) 8 | Output 9 | group1 variable context stat_label stat 10 | 1 ARM BMIBL effectsize_cohens_d Effect Size Estimate -0.436653 11 | 2 ARM BMIBL effectsize_cohens_d CI Confidence Level 0.95 12 | 3 ARM BMIBL effectsize_cohens_d CI Lower Bound -0.740282 13 | 4 ARM HEIGHTBL effectsize_cohens_d Effect Size Estimate -0.299056 14 | 5 ARM HEIGHTBL effectsize_cohens_d CI Confidence Level 0.95 15 | 6 ARM HEIGHTBL effectsize_cohens_d CI Lower Bound -0.600975 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_effectsize_hedges_g.md: -------------------------------------------------------------------------------- 1 | # ard_effectsize_hedges_g() works 2 | 3 | Code 4 | as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select( 5 | ard_effectsize_hedges_g(dplyr::filter(cards::ADSL, ARM %in% c("Placebo", 6 | "Xanomeline High Dose")), by = ARM, variables = c(BMIBL, HEIGHTBL)), c(1:3, 7 | 5:6)), variable), n = 3)) 8 | Output 9 | group1 variable context stat_label stat 10 | 1 ARM BMIBL effectsize_hedges_g Effect Size Estimate -0.4347006 11 | 2 ARM BMIBL effectsize_hedges_g CI Confidence Level 0.95 12 | 3 ARM BMIBL effectsize_hedges_g CI Lower Bound -0.7369717 13 | 4 ARM HEIGHTBL effectsize_hedges_g Effect Size Estimate -0.2977188 14 | 5 ARM HEIGHTBL effectsize_hedges_g CI Confidence Level 0.95 15 | 6 ARM HEIGHTBL effectsize_hedges_g CI Lower Bound -0.5982873 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_emmeans_mean_difference.md: -------------------------------------------------------------------------------- 1 | # ard_emmeans_mean_difference() works 2 | 3 | Code 4 | print(ard_emmeans_mean_difference, columns = "all") 5 | Message 6 | {cards} data frame: 8 x 10 7 | Output 8 | group1 variable variable_level context stat_name stat_label stat fmt_fn warning error 9 | 1 am contrast am0 - am1 emmeans_… estimate Mean Dif… 0.61 1 10 | 2 am contrast am0 - am1 emmeans_… std.error std.error 0.229 1 11 | 3 am contrast am0 - am1 emmeans_… df df Inf 1 12 | 4 am contrast am0 - am1 emmeans_… conf.low CI Lower… 0.162 1 13 | 5 am contrast am0 - am1 emmeans_… conf.high CI Upper… 1.059 1 14 | 6 am contrast am0 - am1 emmeans_… p.value p-value 0.008 1 15 | 7 am contrast am0 - am1 emmeans_… conf.level CI Confi… 0.95 1 16 | 8 am contrast am0 - am1 emmeans_… method method Least-sq… 17 | 18 | # ard_emmeans_mean_difference() errors are returned correctly 19 | 20 | Code 21 | print(ard, columns = "all") 22 | Message 23 | {cards} data frame: 8 x 10 24 | Output 25 | group1 variable variable_level context stat_name stat_label stat fmt_fn warning error 26 | 1 am contrast NA emmeans_… estimate Mean Dif… There wa… 27 | 2 am contrast NA emmeans_… std.error std.error There wa… 28 | 3 am contrast NA emmeans_… df df There wa… 29 | 4 am contrast NA emmeans_… conf.low CI Lower… There wa… 30 | 5 am contrast NA emmeans_… conf.high CI Upper… There wa… 31 | 6 am contrast NA emmeans_… p.value p-value There wa… 32 | 7 am contrast NA emmeans_… conf.level CI Confi… There wa… 33 | 8 am contrast NA emmeans_… method method There wa… 34 | 35 | --- 36 | 37 | "There was an error evaluating the model `glm(formula = vs ~ am + mpg, data = ., family = nothing)`\nCaused by error:\n! object 'nothing' not found" 38 | 39 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_proportion_ci.md: -------------------------------------------------------------------------------- 1 | # ard_categorical_ci(method='strat_wilson') works 2 | 3 | Code 4 | ard_categorical_ci_strat_wilson 5 | Message 6 | {cards} data frame: 7 x 9 7 | Output 8 | variable variable_level context stat_name stat_label stat 9 | 1 rsp TRUE proporti… N N 80 10 | 2 rsp TRUE proporti… n n 50 11 | 3 rsp TRUE proporti… estimate estimate 0.625 12 | 4 rsp TRUE proporti… conf.low conf.low 0.487 13 | 5 rsp TRUE proporti… conf.high conf.high 0.719 14 | 6 rsp TRUE proporti… conf.level conf.lev… 0.95 15 | 7 rsp TRUE proporti… method method Stratifi… 16 | Message 17 | i 3 more variables: fmt_fn, warning, error 18 | 19 | --- 20 | 21 | Code 22 | ard_categorical_ci_strat_wilsoncc 23 | Message 24 | {cards} data frame: 7 x 9 25 | Output 26 | variable variable_level context stat_name stat_label stat 27 | 1 rsp TRUE proporti… N N 80 28 | 2 rsp TRUE proporti… n n 50 29 | 3 rsp TRUE proporti… estimate estimate 0.625 30 | 4 rsp TRUE proporti… conf.low conf.low 0.448 31 | 5 rsp TRUE proporti… conf.high conf.high 0.753 32 | 6 rsp TRUE proporti… conf.level conf.lev… 0.95 33 | 7 rsp TRUE proporti… method method Stratifi… 34 | Message 35 | i 3 more variables: fmt_fn, warning, error 36 | 37 | # ard_categorical_ci() messaging 38 | 39 | Code 40 | ard <- ard_categorical_ci(data = mtcars, variables = cyl, value = cyl ~ 10, 41 | method = "jeffreys") 42 | Condition 43 | Warning: 44 | A value of `value=10` for variable "cyl" was passed, but is not one of the observed levels: 4, 6, and 8. 45 | i This may be an error. 46 | i If value is a valid, convert variable to factor with all levels specified to avoid this message. 47 | 48 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_regression_basic.md: -------------------------------------------------------------------------------- 1 | # ard_regression_basic() works 2 | 3 | Code 4 | dplyr::select(as.data.frame(ard), -fmt_fn) 5 | Output 6 | variable variable_level context stat_name stat_label stat warning error 7 | 1 ARM Xanomeline High Dose regression estimate Coefficient -0.8283499 NULL NULL 8 | 2 ARM Xanomeline High Dose regression std.error Standard Error 1.267394 NULL NULL 9 | 3 ARM Xanomeline High Dose regression statistic statistic -0.653585 NULL NULL 10 | 4 ARM Xanomeline High Dose regression p.value p-value 0.5139775 NULL NULL 11 | 5 ARM Xanomeline High Dose regression conf.low CI Lower Bound -3.324433 NULL NULL 12 | 6 ARM Xanomeline High Dose regression conf.high CI Upper Bound 1.667733 NULL NULL 13 | 7 ARM Xanomeline Low Dose regression estimate Coefficient 0.4573643 NULL NULL 14 | 8 ARM Xanomeline Low Dose regression std.error Standard Error 1.267394 NULL NULL 15 | 9 ARM Xanomeline Low Dose regression statistic statistic 0.3608698 NULL NULL 16 | 10 ARM Xanomeline Low Dose regression p.value p-value 0.7185003 NULL NULL 17 | 11 ARM Xanomeline Low Dose regression conf.low CI Lower Bound -2.038718 NULL NULL 18 | 12 ARM Xanomeline Low Dose regression conf.high CI Upper Bound 2.953447 NULL NULL 19 | 20 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_stats_aov.md: -------------------------------------------------------------------------------- 1 | # ard_aov() works 2 | 3 | Code 4 | as.data.frame(ard_stats_aov(AGE ~ ARM + SEX, data = cards::ADSL)) 5 | Output 6 | variable context stat_name stat_label stat fmt_fn warning 7 | 1 ARM stats_aov sumsq Sum of Squares 71.38574 1 NULL 8 | 2 ARM stats_aov df Degrees of Freedom 2 1 NULL 9 | 3 ARM stats_aov meansq Mean of Sum of Squares 35.69287 1 NULL 10 | 4 ARM stats_aov statistic Statistic 0.5235002 1 NULL 11 | 5 ARM stats_aov p.value p-value 0.5930912 1 NULL 12 | 6 SEX stats_aov sumsq Sum of Squares 87.40947 1 NULL 13 | 7 SEX stats_aov df Degrees of Freedom 1 1 NULL 14 | 8 SEX stats_aov meansq Mean of Sum of Squares 87.40947 1 NULL 15 | 9 SEX stats_aov statistic Statistic 1.282017 1 NULL 16 | 10 SEX stats_aov p.value p-value 0.2586091 1 NULL 17 | error 18 | 1 NULL 19 | 2 NULL 20 | 3 NULL 21 | 4 NULL 22 | 5 NULL 23 | 6 NULL 24 | 7 NULL 25 | 8 NULL 26 | 9 NULL 27 | 10 NULL 28 | 29 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_stats_kruskal_test.md: -------------------------------------------------------------------------------- 1 | # ard_stats_kruskal_test() works 2 | 3 | Code 4 | as.data.frame(ard_stats_kruskal_test(cards::ADSL, by = "ARM", variables = "AGE")) 5 | Output 6 | group1 variable context stat_name 7 | 1 ARM AGE stats_kruskal_test statistic 8 | 2 ARM AGE stats_kruskal_test p.value 9 | 3 ARM AGE stats_kruskal_test parameter 10 | 4 ARM AGE stats_kruskal_test method 11 | stat_label stat fmt_fn 12 | 1 Kruskal-Wallis chi-squared Statistic 1.63473 1 13 | 2 p-value 0.4415937 1 14 | 3 Degrees of Freedom 2 1 15 | 4 method Kruskal-Wallis rank sum test NULL 16 | warning error 17 | 1 NULL NULL 18 | 2 NULL NULL 19 | 3 NULL NULL 20 | 4 NULL NULL 21 | 22 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_stats_mantelhaen_test.md: -------------------------------------------------------------------------------- 1 | # ard_stats_mantelhaen_test() works 2 | 3 | Code 4 | print(ard_mantelhaentest, columns = "all") 5 | Message 6 | {cards} data frame: 8 x 10 7 | Output 8 | group1 group2 variable context stat_name stat_label stat fmt_fn warning error 9 | 1 ARM SEX AGEGR1 stats_ma… statistic Generali… 6.455 1 10 | 2 ARM SEX AGEGR1 stats_ma… p.value p-value 0.168 1 11 | 3 ARM SEX AGEGR1 stats_ma… parameter Degrees … 4 1 12 | 4 ARM SEX AGEGR1 stats_ma… method method Cochran-… 13 | 5 ARM SEX AGEGR1 stats_ma… alternative alternat… two.sided 14 | 6 ARM SEX AGEGR1 stats_ma… correct Continui… TRUE 15 | 7 ARM SEX AGEGR1 stats_ma… exact Exact Co… FALSE 16 | 8 ARM SEX AGEGR1 stats_ma… conf.level CI Confi… 0.95 1 17 | 18 | --- 19 | 20 | Code 21 | print(ard_mantelhaentest, columns = "all") 22 | Message 23 | {cards} data frame: 8 x 10 24 | Output 25 | group1 group2 variable context stat_name stat_label stat fmt_fn warning error 26 | 1 ARM SEX AGEGR1 stats_ma… statistic Mantel-H… 6.455 1 27 | 2 ARM SEX AGEGR1 stats_ma… p.value p-value 0.168 1 28 | 3 ARM SEX AGEGR1 stats_ma… parameter Degrees … 4 1 29 | 4 ARM SEX AGEGR1 stats_ma… method method Cochran-… 30 | 5 ARM SEX AGEGR1 stats_ma… alternative alternat… less 31 | 6 ARM SEX AGEGR1 stats_ma… correct Continui… FALSE 32 | 7 ARM SEX AGEGR1 stats_ma… exact Exact Co… TRUE 33 | 8 ARM SEX AGEGR1 stats_ma… conf.level CI Confi… 0.9 1 34 | 35 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_stats_mood_test.md: -------------------------------------------------------------------------------- 1 | # ard_stats_mood_test() works 2 | 3 | Code 4 | as.data.frame(ard_stats_mood_test(cards::ADSL, by = SEX, variable = AGE)) 5 | Output 6 | group1 variable context stat_name stat_label 7 | 1 SEX AGE stats_mood_test statistic Z-Statistic 8 | 2 SEX AGE stats_mood_test p.value p-value 9 | 3 SEX AGE stats_mood_test method method 10 | 4 SEX AGE stats_mood_test alternative Alternative Hypothesis 11 | stat fmt_fn warning error 12 | 1 0.1292194 1 NULL NULL 13 | 2 0.8971841 1 NULL NULL 14 | 3 Mood two-sample test of scale NULL NULL NULL 15 | 4 two.sided NULL NULL NULL 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_stats_oneway_test.md: -------------------------------------------------------------------------------- 1 | # ard_stats_oneway_test() works 2 | 3 | Code 4 | head(dplyr::select(ard_stats_oneway_test(AGEGR1 ~ ARM, data = cards::ADSL), c( 5 | "stat_name", "stat", "warning")), 3) 6 | Message 7 | {cards} data frame: 3 x 3 8 | Output 9 | stat_name stat warning 10 | 1 num.df 2 argument… 11 | 2 den.df NA argument… 12 | 3 statistic NA argument… 13 | 14 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_stats_poisson_test.md: -------------------------------------------------------------------------------- 1 | # ard_stats_poisson_test() errors are handled correctly 2 | 3 | Code 4 | ard_stats_poisson_test(cards::ADTTE, by = TRTA, variables = c(CNSR, AVAL)) 5 | Condition 6 | Error in `ard_stats_poisson_test()`: 7 | ! The `by` argument must have a maximum of two levels. 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_survey_svychisq.md: -------------------------------------------------------------------------------- 1 | # ard_survey_svychisq() works 2 | 3 | Code 4 | as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select( 5 | ard_survey_svychisq(dclus2, variables = c(sch.wide, stype), by = comp.imp, 6 | statistic = "adjWald"), c(1:3, 5:6)), variable), n = 3)) 7 | Output 8 | group1 variable context stat_label stat 9 | 1 comp.imp sch.wide survey_svychisq Nominator Degrees of Freedom 1 10 | 2 comp.imp sch.wide survey_svychisq Denominator Degrees of Freedom 39 11 | 3 comp.imp sch.wide survey_svychisq Statistic 11.4203 12 | 4 comp.imp stype survey_svychisq Nominator Degrees of Freedom 2 13 | 5 comp.imp stype survey_svychisq Denominator Degrees of Freedom 38 14 | 6 comp.imp stype survey_svychisq Statistic 4.480236 15 | 16 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_survey_svyranktest.md: -------------------------------------------------------------------------------- 1 | # ard_survey_svyranktest() works 2 | 3 | Code 4 | dplyr::select(as.data.frame(svyranktest[[1]]), stat_label, stat) 5 | Output 6 | stat_label stat 7 | 1 Median of the Difference -0.1060602 8 | 2 Statistic -1.718689 9 | 3 p-value 0.09426084 10 | 4 Degrees of Freedom 36 11 | 5 method Design-based KruskalWallis test 12 | 6 Alternative Hypothesis two.sided 13 | 14 | --- 15 | 16 | Code 17 | dplyr::select(as.data.frame(svyranktest[[2]]), stat_label, stat) 18 | Output 19 | stat_label stat 20 | 1 Median of the Difference -0.3791163 21 | 2 Statistic -1.583859 22 | 3 p-value 0.1219723 23 | 4 Degrees of Freedom 36 24 | 5 method Design-based vanderWaerden test 25 | 6 Alternative Hypothesis two.sided 26 | 27 | --- 28 | 29 | Code 30 | dplyr::select(as.data.frame(svyranktest[[3]]), stat_label, stat) 31 | Output 32 | stat_label stat 33 | 1 Median of the Difference -0.1240709 34 | 2 Statistic -0.9139828 35 | 3 p-value 0.3668071 36 | 4 Degrees of Freedom 36 37 | 5 method Design-based median test 38 | 6 Alternative Hypothesis two.sided 39 | 40 | --- 41 | 42 | Code 43 | dplyr::select(as.data.frame(svyranktest[[4]]), stat_label, stat) 44 | Output 45 | stat_label stat 46 | 1 Median of the Difference -0.1060602 47 | 2 Statistic -1.718689 48 | 3 p-value 0.09426084 49 | 4 Degrees of Freedom 36 50 | 5 method Design-based KruskalWallis test 51 | 6 Alternative Hypothesis two.sided 52 | 53 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_survival_survfit_diff.md: -------------------------------------------------------------------------------- 1 | # ard_survival_survfit_diff() messaging 2 | 3 | Code 4 | ard_survival_survfit_diff(survfit(Surv(AVAL, 1 - CNSR) ~ SEX + TRTA, cards::ADTTE), 5 | times = c(25, 50)) 6 | Condition 7 | Error in `ard_survival_survfit_diff()`: 8 | ! The object passed in argument `x` must be stratified by a single variable. 9 | 10 | --- 11 | 12 | Code 13 | ard_survival_survfit_diff(survfit(Surv(AVAL, 1 - CNSR) ~ constant, dplyr::mutate( 14 | cards::ADTTE, constant = 1L)), times = c(25, 50)) 15 | Condition 16 | Error in `ard_survival_survfit_diff()`: 17 | ! The object's stratifying variable must have 2 or more levels. 18 | 19 | --- 20 | 21 | Code 22 | ard_survival_survfit_diff(survfit(coxph(Surv(AVAL, CNSR) ~ SEX + strata(TRTA), 23 | cards::ADTTE)), times = c(25, 50)) 24 | Condition 25 | Error in `ard_survival_survfit_diff()`: 26 | ! Argument `x` cannot be class . 27 | 28 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ard_total_n.survey.design.md: -------------------------------------------------------------------------------- 1 | # ard_total_n.survey.design() works 2 | 3 | Code 4 | ard_total_n(survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~ 5 | Freq)) 6 | Message 7 | {cards} data frame: 2 x 8 8 | Output 9 | variable context stat_name stat_label stat fmt_fn 10 | 1 ..ard_total_n.. total_n N N 2201 11 | 2 ..ard_total_n.. total_n N_unweighted Unweight… 32 12 | Message 13 | i 2 more variables: warning, error 14 | 15 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_aod_wald_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("aod", "broom.helpers")))) 2 | 3 | test_that("ard_aod_wald_test() works", { 4 | # works for a generic case 5 | expect_error( 6 | glm_ard_aod_waldtest <- 7 | suppressWarnings(lm(AGE ~ ARM, data = cards::ADSL)) |> 8 | ard_aod_wald_test(), 9 | NA 10 | ) 11 | expect_equal(nrow(glm_ard_aod_waldtest), 6L) 12 | expect_snapshot(glm_ard_aod_waldtest[, 1:6]) 13 | 14 | # error returned when a regression model isn't passed 15 | 16 | expect_error( 17 | ard_aod_wald_test(cards::ADSL) |> 18 | dplyr::select(c(context, error)) 19 | ) 20 | }) 21 | 22 | test_that("ard_aod_wald_test() follows ard structure", { 23 | expect_silent( 24 | suppressWarnings(lm(AGE ~ ARM, data = cards::ADSL)) |> 25 | ard_aod_wald_test() |> 26 | cards::check_ard_structure(method = FALSE) 27 | ) 28 | }) 29 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_attributes.survey.design.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(c("survey", "withr"))) 2 | 3 | test_that("ard_attributes.survey.design() works", { 4 | withr::local_options(list(width = 120)) 5 | data(api, package = "survey") 6 | dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) 7 | 8 | expect_snapshot({ 9 | attr(dclus1$variables$sname, "label") <- "School Name" 10 | 11 | ard_attributes( 12 | dclus1, 13 | variables = c(sname, dname), 14 | label = list(dname = "District Name") 15 | ) |> 16 | as.data.frame() 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_car_anova.R: -------------------------------------------------------------------------------- 1 | skip_if_not( 2 | is_pkg_installed(c("broom.helpers", "car", "parameters")) 3 | ) 4 | 5 | test_that("ard_car_anova() works", { 6 | # works for a generic case 7 | expect_error( 8 | glm_ard_car_anova <- 9 | suppressWarnings(glm(vs ~ factor(cyl) + factor(am), data = mtcars, family = binomial)) |> 10 | ard_car_anova(test.statistic = "Wald"), 11 | NA 12 | ) 13 | expect_equal(nrow(glm_ard_car_anova), 6L) 14 | expect_snapshot(glm_ard_car_anova) 15 | }) 16 | 17 | test_that("ard_car_anova() messaging", { 18 | expect_snapshot( 19 | error = TRUE, 20 | ard_car_anova(mtcars) 21 | ) 22 | }) 23 | 24 | test_that("ard_car_anova() follows ard structure", { 25 | expect_silent( 26 | suppressWarnings(glm(vs ~ factor(cyl) + factor(am), data = mtcars, family = binomial)) |> 27 | ard_car_anova(test.statistic = "Wald") |> 28 | cards::check_ard_structure(method = FALSE) 29 | ) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_car_vif.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("car")) 2 | 3 | test_that("ard_car_vif() works", { 4 | expect_snapshot( 5 | lm(AGE ~ ARM + SEX, data = cards::ADSL) |> 6 | ard_car_vif() |> 7 | as.data.frame() 8 | ) 9 | 10 | expect_snapshot( 11 | lm(AGE ~ BMIBL + EDUCLVL, data = cards::ADSL) |> 12 | ard_car_vif() |> 13 | as.data.frame() 14 | ) 15 | }) 16 | 17 | test_that("ard_car_vif() appropriate errors are given for model with only 1 term", { 18 | expect_equal( 19 | lm(AGE ~ ARM, data = cards::ADSL) |> 20 | ard_car_vif() |> 21 | dplyr::select(error) %>% 22 | is.null(), 23 | FALSE 24 | ) 25 | }) 26 | 27 | 28 | test_that("ard_vif() issues friendly messaging for incorrect object passed in/can't get terms of model", { 29 | expect_snapshot( 30 | error = TRUE, 31 | cards::ADSL |> ard_car_vif() 32 | ) 33 | }) 34 | 35 | test_that("ard_car_vif() follows ard structure", { 36 | expect_silent( 37 | lm(AGE ~ ARM + SEX, data = cards::ADSL) |> 38 | ard_car_vif() |> 39 | cards::check_ard_structure(method = FALSE) 40 | ) 41 | }) 42 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_continuous_ci.data.frame.R: -------------------------------------------------------------------------------- 1 | test_that("ard_continuous_ci.data.frame(method = 't.test')", { 2 | skip_if_not(is_pkg_installed("broom")) 3 | 4 | expect_equal( 5 | ard_continuous_ci( 6 | mtcars, 7 | variables = mpg, 8 | method = "t.test" 9 | ) |> 10 | dplyr::select(-context), 11 | ard_stats_t_test_onesample( 12 | mtcars, 13 | variables = mpg 14 | ) |> 15 | dplyr::select(-context) 16 | ) 17 | }) 18 | 19 | test_that("ard_continuous_ci.data.frame(method = 'wilcox.test')", { 20 | skip_if_not(is_pkg_installed("broom")) 21 | expect_equal( 22 | ard_continuous_ci( 23 | mtcars, 24 | variables = mpg, 25 | method = "wilcox.test" 26 | ) |> 27 | dplyr::select(-context), 28 | ard_stats_wilcox_test_onesample( 29 | mtcars, 30 | variables = mpg, 31 | conf.int = TRUE 32 | ) |> 33 | dplyr::select(-context) 34 | ) 35 | }) 36 | 37 | test_that("ard_continuous_ci.data.frame() follows ard structure", { 38 | skip_if_not(is_pkg_installed("broom")) 39 | 40 | expect_silent( 41 | ard_continuous_ci( 42 | mtcars, 43 | variables = mpg, 44 | method = "wilcox.test" 45 | ) |> 46 | cards::check_ard_structure() 47 | ) 48 | }) 49 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_regression.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(pkg = "broom.helpers")) 2 | 3 | test_that("ard_regression() works", { 4 | withr::local_options(list(width = 90)) 5 | 6 | expect_silent( 7 | ard <- 8 | lm(AGE ~ ARM, data = cards::ADSL) |> 9 | ard_regression(add_estimate_to_reference_rows = TRUE) 10 | ) 11 | 12 | expect_snapshot( 13 | ard |> 14 | as.data.frame() |> 15 | dplyr::select(-context, -stat_label, -fmt_fn) |> 16 | dplyr::mutate( 17 | stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) 18 | ) 19 | ) 20 | 21 | expect_equal( 22 | ard, 23 | ard_regression( 24 | x = cards::ADSL, 25 | formula = AGE ~ ARM, 26 | method = "lm" 27 | ) 28 | ) 29 | 30 | # checking non-syntactic names 31 | expect_equal( 32 | lm(AGE ~ `Treatment Arm`, data = cards::ADSL |> dplyr::rename(`Treatment Arm` = ARM)) |> 33 | ard_regression(add_estimate_to_reference_rows = TRUE) |> 34 | dplyr::pull(variable) |> 35 | unique(), 36 | "Treatment Arm" 37 | ) 38 | }) 39 | 40 | test_that("ard_regression() works specifying custom tidier", { 41 | skip_if_not(is_pkg_installed(pkg = c("lme4", "broom.mixed"))) 42 | withr::local_options(list(width = 90)) 43 | 44 | expect_snapshot( 45 | lme4::lmer(mpg ~ hp + (1 | cyl), data = mtcars) |> 46 | ard_regression(tidy_fun = broom.mixed::tidy) |> 47 | as.data.frame() |> 48 | dplyr::select(-context, -stat_label, -fmt_fn) |> 49 | dplyr::filter(map_lgl(stat, is.numeric)) |> 50 | dplyr::mutate( 51 | stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x)) 52 | ) 53 | ) 54 | }) 55 | 56 | test_that("ard_regression() does not produce `variable_level` column where not applicable", { 57 | expect_true(!"variable_level" %in% names(lm(mpg ~ hp, mtcars) |> ard_regression())) 58 | }) 59 | 60 | test_that("ard_regression() warnings and errors return correctly", { 61 | skip_if_not(is_pkg_installed(pkg = "parameters")) 62 | # constructed a model where broom.helpers fails, 63 | # fall back method uses parameters which returns different messaging. 64 | mod <- lm(AGE ~ ARM, data = cards::ADSL) 65 | mod$coefficients <- NULL 66 | df <- mod |> 67 | ard_regression() |> 68 | as.data.frame() 69 | 70 | expect_false(is_empty(df$error)) 71 | expect_true(is_empty(df$stat[[1]])) 72 | }) 73 | 74 | test_that("ard_regression() follows ard structure", { 75 | expect_silent( 76 | lm(AGE ~ ARM, data = cards::ADSL) |> 77 | ard_regression(add_estimate_to_reference_rows = TRUE) |> 78 | cards::check_ard_structure(method = FALSE) 79 | ) 80 | }) 81 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_regression_basic.R: -------------------------------------------------------------------------------- 1 | skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers"))) 2 | 3 | test_that("ard_regression_basic() works", { 4 | withr::local_options(list(width = 100)) 5 | 6 | expect_error( 7 | ard <- lm(AGE ~ ARM, data = cards::ADSL) |> 8 | ard_regression_basic(), 9 | NA 10 | ) 11 | 12 | expect_snapshot(as.data.frame(ard) |> dplyr::select(-fmt_fn)) 13 | 14 | expect_equal( 15 | ard, 16 | ard_regression_basic( 17 | x = cards::ADSL, 18 | formula = AGE ~ ARM, 19 | method = "lm" 20 | ) 21 | ) 22 | }) 23 | 24 | test_that("ard_regression_basic() does not produce `variable_level` column where not applicable", { 25 | expect_true(!"variable_level" %in% names(lm(mpg ~ hp, mtcars) |> ard_regression_basic())) 26 | }) 27 | 28 | test_that("ard_regression_basic() follows ard structure", { 29 | expect_silent( 30 | lm(AGE ~ ARM, data = cards::ADSL) |> 31 | ard_regression_basic() |> 32 | cards::check_ard_structure(method = FALSE) 33 | ) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_smd_smd.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("smd")) 2 | 3 | test_that("ard_smd_smd() works", { 4 | expect_error( 5 | ard_smd <- 6 | mtcars |> 7 | ard_smd_smd(by = vs, variables = am, std.error = TRUE), 8 | NA 9 | ) 10 | 11 | expect_equal( 12 | ard_smd |> 13 | cards::get_ard_statistics(stat_name %in% c("estimate", "std.error")), 14 | smd::smd(x = mtcars$am, g = mtcars$vs, std.error = TRUE) |> 15 | dplyr::select(-term) |> 16 | unclass(), 17 | ignore_attr = TRUE 18 | ) 19 | 20 | # test that the function works with multiple variables at once 21 | expect_equal( 22 | dplyr::bind_rows( 23 | ard_smd, 24 | mtcars |> 25 | ard_smd_smd(by = vs, variables = gear, std.error = TRUE) 26 | ), 27 | mtcars |> 28 | ard_smd_smd(by = vs, variables = c(am, gear), std.error = TRUE) 29 | ) 30 | }) 31 | 32 | test_that("ard_smd() works with survey data", { 33 | skip_if_not(is_pkg_installed("survey")) 34 | 35 | data(api, package = "survey") 36 | dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) 37 | 38 | expect_error( 39 | ard_smd <- 40 | dclus1 |> 41 | ard_smd_smd(by = both, variable = api00, std.error = TRUE), 42 | NA 43 | ) 44 | 45 | expect_equal( 46 | ard_smd |> 47 | cards::get_ard_statistics(stat_name %in% c("estimate", "std.error")), 48 | smd::smd(x = apiclus1$api00, g = apiclus1$both, w = weights(dclus1), std.error = TRUE) |> 49 | dplyr::select(-term) |> 50 | unclass(), 51 | ignore_attr = TRUE 52 | ) 53 | }) 54 | 55 | test_that("ard_smd_smd() error messaging", { 56 | # mis-specify the gref argument 57 | expect_error( 58 | bad_gref <- 59 | ard_smd_smd(cards::ADSL, by = SEX, variables = AGE, std.error = TRUE, gref = 0) |> 60 | as.data.frame(), 61 | NA 62 | ) 63 | # check all the stats still appear despite the errors 64 | expect_equal(nrow(bad_gref), 3L) 65 | expect_setequal(bad_gref$stat_name, c("estimate", "std.error", "gref")) 66 | # check the error message it the one we expect 67 | expect_equal( 68 | bad_gref$error |> unique() |> cli::ansi_strip(), 69 | "gref must be an integer within 2" 70 | ) 71 | }) 72 | 73 | test_that("ard_smd_smd() follows ard structure", { 74 | expect_silent( 75 | mtcars |> 76 | ard_smd_smd(by = vs, variables = am, std.error = TRUE) |> 77 | cards::check_ard_structure() 78 | ) 79 | }) 80 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_aov.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(c("broom.helpers", "parameters"))) 2 | 3 | test_that("ard_aov() works", { 4 | expect_error( 5 | ard_aov <- 6 | ard_stats_aov(AGE ~ ARM, data = cards::ADSL), 7 | NA 8 | ) 9 | 10 | expect_equal( 11 | ard_aov |> 12 | cards::get_ard_statistics(stat_name %in% c("sumsq", "statistic")), 13 | aov( 14 | AGE ~ ARM, 15 | data = cards::ADSL 16 | ) |> 17 | broom::tidy() |> 18 | dplyr::slice_head() |> 19 | dplyr::select(sumsq, statistic) |> 20 | unclass(), 21 | ignore_attr = TRUE 22 | ) 23 | 24 | # see if it can handle multiple variables 25 | expect_snapshot( 26 | ard_stats_aov(AGE ~ ARM + SEX, data = cards::ADSL) |> 27 | as.data.frame() 28 | ) 29 | }) 30 | 31 | test_that("ard_stats_aov() follows ard structure", { 32 | expect_silent( 33 | ard_stats_aov(AGE ~ ARM, data = cards::ADSL) |> 34 | cards::check_ard_structure(method = FALSE) 35 | ) 36 | }) 37 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_chisq_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_chisq_test() works", { 4 | expect_error( 5 | ard_chisqtest <- 6 | cards::ADSL |> 7 | ard_stats_chisq_test(by = ARM, variables = AGEGR1), 8 | NA 9 | ) 10 | 11 | expect_equal( 12 | ard_chisqtest |> 13 | cards::get_ard_statistics(stat_name %in% c("statistic", "p.value")), 14 | with(cards::ADSL, chisq.test(AGEGR1, ARM)) |> 15 | broom::tidy() |> 16 | dplyr::select(statistic, p.value) |> 17 | unclass(), 18 | ignore_attr = TRUE 19 | ) 20 | 21 | # function works with multiple variables 22 | expect_equal( 23 | dplyr::bind_rows( 24 | ard_chisqtest, 25 | cards::ADSL |> 26 | ard_stats_chisq_test(by = ARM, variables = BMIBLGR1) 27 | ), 28 | cards::ADSL |> 29 | ard_stats_chisq_test(by = ARM, variables = c(AGEGR1, BMIBLGR1)) 30 | ) 31 | }) 32 | 33 | 34 | test_that("ard_stats_chisq_test() follows ard structure", { 35 | expect_silent( 36 | cards::ADSL |> 37 | ard_stats_chisq_test(by = ARM, variables = AGEGR1) |> 38 | cards::check_ard_structure() 39 | ) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_fisher_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_fisher_test() works", { 4 | expect_error( 5 | ard_fishertest <- 6 | cards::ADSL[1:20, ] |> 7 | ard_stats_fisher_test(by = ARM, variables = AGEGR1), 8 | NA 9 | ) 10 | 11 | expect_equal( 12 | ard_fishertest |> 13 | cards::get_ard_statistics(stat_name %in% c("p.value", "method")), 14 | with(cards::ADSL[1:20, ], fisher.test(AGEGR1, ARM)) |> 15 | broom::tidy() |> 16 | dplyr::select(p.value, method) |> 17 | unclass(), 18 | ignore_attr = TRUE 19 | ) 20 | 21 | # function works with multiple variables 22 | expect_equal( 23 | dplyr::bind_rows( 24 | ard_fishertest, 25 | cards::ADSL[1:20, ] |> 26 | ard_stats_fisher_test(by = ARM, variables = BMIBLGR1) 27 | ), 28 | cards::ADSL[1:20, ] |> 29 | ard_stats_fisher_test(by = ARM, variables = c(AGEGR1, BMIBLGR1)) 30 | ) 31 | }) 32 | 33 | test_that("ard_stats_fisher_test() follows ard structure", { 34 | expect_silent( 35 | cards::ADSL[1:20, ] |> 36 | ard_stats_fisher_test(by = ARM, variables = AGEGR1) |> 37 | cards::check_ard_structure() 38 | ) 39 | }) 40 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_kruskal_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_kruskal_test() works", { 4 | expect_error( 5 | ard_kruskaltest <- 6 | cards::ADSL |> 7 | ard_stats_kruskal_test(by = ARM, variables = AGE), 8 | NA 9 | ) 10 | 11 | expect_equal( 12 | ard_kruskaltest |> 13 | cards::get_ard_statistics(stat_name %in% c("statistic", "p.value")), 14 | with(cards::ADSL, kruskal.test(AGE, ARM)) |> 15 | broom::tidy() |> 16 | dplyr::select(statistic, p.value) |> 17 | unclass(), 18 | ignore_attr = TRUE 19 | ) 20 | 21 | # errors are properly handled 22 | expect_snapshot( 23 | cards::ADSL |> 24 | ard_stats_kruskal_test(by = "ARM", variables = "AGE") |> 25 | as.data.frame() 26 | ) 27 | 28 | # test that the function works with multiple variables 29 | expect_equal( 30 | dplyr::bind_rows( 31 | ard_kruskaltest, 32 | cards::ADSL |> 33 | ard_stats_kruskal_test(by = ARM, variable = BMIBL) 34 | ), 35 | cards::ADSL |> 36 | ard_stats_kruskal_test(by = ARM, variable = c(AGE, BMIBL)) 37 | ) 38 | }) 39 | 40 | test_that("ard_stats_kruskal_test() follows ard structure", { 41 | expect_silent( 42 | cards::ADSL |> 43 | ard_stats_kruskal_test(by = ARM, variable = BMIBL) |> 44 | cards::check_ard_structure() 45 | ) 46 | }) 47 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_mantelhaen_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_mantelhaen_test() works", { 4 | withr::local_options(width = 200) 5 | 6 | expect_silent( 7 | ard_mantelhaentest <- cards::ADSL |> 8 | ard_stats_mantelhaen_test(by = ARM, variables = AGEGR1, strata = SEX) 9 | ) 10 | 11 | expect_snapshot(ard_mantelhaentest |> print(columns = "all")) 12 | 13 | expect_equal( 14 | ard_mantelhaentest |> 15 | cards::get_ard_statistics(stat_name %in% c("statistic", "p.value")), 16 | with(cards::ADSL, mantelhaen.test(AGEGR1, ARM, SEX)) |> 17 | broom::tidy() |> 18 | dplyr::select(statistic, p.value) |> 19 | unclass(), 20 | ignore_attr = TRUE 21 | ) 22 | 23 | # custom arguments to stats::mantelhaen.test() 24 | expect_silent( 25 | ard_mantelhaentest <- cards::ADSL |> 26 | ard_stats_mantelhaen_test( 27 | by = ARM, variable = AGEGR1, strata = SEX, 28 | alternative = "less", correct = FALSE, exact = TRUE, conf.level = 0.90 29 | ) 30 | ) 31 | 32 | expect_snapshot(ard_mantelhaentest |> print(columns = "all")) 33 | }) 34 | 35 | test_that("ard_stats_mantelhaen_test() displays errors correctly", { 36 | data <- cards::ADSL |> 37 | dplyr::mutate(ARM = "ARM A") 38 | 39 | expect_silent( 40 | ard_mantelhaentest <- data |> 41 | ard_stats_mantelhaen_test(by = ARM, variables = AGEGR1, strata = SEX) 42 | ) 43 | expect_equal(nrow(ard_mantelhaentest), 9) 44 | expect_equal(ard_mantelhaentest$error, as.list(rep("'x' and 'y' must have at least 2 levels", 9))) 45 | }) 46 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_mcnemar_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(c("broom", "withr"))) 2 | 3 | test_that("ard_stats_mcnemar_test() works", { 4 | expect_error( 5 | ard_mcnemartest <- 6 | cards::ADSL |> 7 | ard_stats_mcnemar_test(by = SEX, variables = EFFFL), 8 | NA 9 | ) 10 | 11 | expect_equal( 12 | ard_mcnemartest |> 13 | cards::get_ard_statistics(stat_name %in% c("statistic", "p.value", "parameter", "method")), 14 | stats::mcnemar.test(cards::ADSL[["SEX"]], cards::ADSL[["EFFFL"]], correct = TRUE) |> 15 | broom::tidy() |> 16 | unclass(), 17 | ignore_attr = TRUE 18 | ) 19 | 20 | # errors are properly handled 21 | expect_equal( 22 | cards::ADSL |> 23 | ard_stats_mcnemar_test(by = ARM, variables = AGE, correct = FALSE) |> 24 | dplyr::pull(error) |> 25 | getElement(1L), 26 | "'x' and 'y' must have the same number of levels (minimum 2)" 27 | ) 28 | 29 | # non-syntactic column names work too 30 | ADSL_tmp <- cards::ADSL |> 31 | dplyr::rename("if" = AGE, "_c d" = EFFFL) 32 | 33 | expect_equal( 34 | cards::ADSL |> 35 | dplyr::rename(`Planned Tx` = TRT01P, `Age Group` = AGEGR1) |> 36 | ard_stats_mcnemar_test(by = `Planned Tx`, variables = `Age Group`) |> 37 | cards::get_ard_statistics(), 38 | cards::ADSL |> 39 | ard_stats_mcnemar_test(by = TRT01P, variables = AGEGR1) |> 40 | cards::get_ard_statistics() 41 | ) 42 | 43 | # test that the function works with multiple variables 44 | expect_equal( 45 | dplyr::bind_rows( 46 | ard_mcnemartest, 47 | cards::ADSL |> 48 | ard_stats_mcnemar_test(by = SEX, variables = COMP16FL) 49 | ), 50 | cards::ADSL |> 51 | ard_stats_mcnemar_test(by = SEX, variables = c(EFFFL, COMP16FL)) 52 | ) 53 | 54 | # testing long format version 55 | withr::local_seed(1234) 56 | expect_error( 57 | ard_stats_mcnemar_test_long <- 58 | cards::ADSL[c("USUBJID", "TRT01P")] |> 59 | dplyr::mutate(TYPE = "PLANNED") |> 60 | dplyr::rename(TRT01 = TRT01P) %>% 61 | dplyr::bind_rows(dplyr::mutate(., TYPE = "ACTUAL", TRT01 = sample(TRT01))) |> 62 | ard_stats_mcnemar_test_long( 63 | by = TYPE, 64 | variable = TRT01, 65 | id = USUBJID 66 | ), 67 | NA 68 | ) 69 | expect_null(ard_stats_mcnemar_test_long$error |> unique() |> unlist()) 70 | }) 71 | 72 | test_that("ard_stats_mcnemar_test() follows ard structure", { 73 | expect_silent( 74 | cards::ADSL |> 75 | ard_stats_mcnemar_test(by = SEX, variables = EFFFL) |> 76 | cards::check_ard_structure() 77 | ) 78 | }) 79 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_mood_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_mood_test() works", { 4 | expect_error( 5 | ard_moodtest <- 6 | cards::ADSL |> 7 | ard_stats_mood_test(by = SEX, variable = AGE), 8 | NA 9 | ) 10 | 11 | expect_equal( 12 | ard_moodtest |> 13 | cards::get_ard_statistics(stat_name %in% c("statistic", "p.value")), 14 | with(cards::ADSL, mood.test(AGE ~ SEX)) |> 15 | broom::tidy() |> 16 | dplyr::select(statistic, p.value) |> 17 | unclass(), 18 | ignore_attr = TRUE 19 | ) 20 | 21 | # errors are properly handled 22 | expect_snapshot( 23 | cards::ADSL |> 24 | ard_stats_mood_test(by = SEX, variable = AGE) |> 25 | as.data.frame() 26 | ) 27 | 28 | expect_equal( 29 | dplyr::bind_rows( 30 | ard_moodtest, 31 | cards::ADSL |> 32 | ard_stats_mood_test(by = SEX, variable = BMIBL) 33 | ), 34 | cards::ADSL |> 35 | ard_stats_mood_test(by = SEX, variable = c(AGE, BMIBL)) 36 | ) 37 | }) 38 | 39 | test_that("ard_stats_mood_test() follows ard structure", { 40 | expect_silent( 41 | cards::ADSL |> 42 | ard_stats_mood_test(by = SEX, variable = AGE) |> 43 | cards::check_ard_structure() 44 | ) 45 | }) 46 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_oneway_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_oneway_test() works", { 4 | expect_error( 5 | ard_onewaytest <- ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL), 6 | NA 7 | ) 8 | 9 | expect_equal( 10 | ard_onewaytest |> 11 | cards::get_ard_statistics(stat_name %in% c("num.df", "statistic", "method")), 12 | oneway.test( 13 | AGE ~ ARM, 14 | data = cards::ADSL 15 | ) |> 16 | broom::tidy() |> 17 | dplyr::select(num.df, statistic, method) |> 18 | unclass(), 19 | ignore_attr = TRUE 20 | ) 21 | 22 | # warnings are properly handled - "variable" should be continuous, not character 23 | # THE WARNING HERE IS VERY LONG, SO NOT CONVERTING TO data.frame TO KEEP THE CHECK EASY ON THE EYES 24 | expect_snapshot( 25 | ard_stats_oneway_test(AGEGR1 ~ ARM, data = cards::ADSL) |> 26 | dplyr::select(c("stat_name", "stat", "warning")) |> 27 | head(3) 28 | ) 29 | }) 30 | 31 | test_that("ard_stats_oneway_test() follows ard structure", { 32 | expect_silent( 33 | ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) |> 34 | cards::check_ard_structure() 35 | ) 36 | }) 37 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_poisson_test.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_poisson_test() works for one sample tests", { 4 | # Default values work 5 | expect_silent( 6 | ard_stats_poisson_test(cards::ADTTE, variables = c(CNSR, AVAL)) 7 | ) 8 | 9 | # Custom values work 10 | expect_silent( 11 | ard_single <- ard_stats_poisson_test( 12 | cards::ADTTE, 13 | variables = c("CNSR", "AVAL"), 14 | conf.level = 0.90, 15 | r = 0.8, 16 | alternative = "greater" 17 | ) 18 | ) 19 | 20 | # Statistics calculated correctly 21 | expect_equal( 22 | ard_single |> 23 | cards::get_ard_statistics( 24 | stat_name %in% 25 | c("estimate", "statistic", "p.value", "parameter", "conf.low", "conf.high", "method", "alternative") 26 | ), 27 | poisson.test( 28 | x = sum(cards::ADTTE$CNSR), 29 | T = sum(cards::ADTTE$AVAL), 30 | r = 0.8, 31 | conf.level = 0.9, 32 | alternative = "greater" 33 | ) |> 34 | broom::tidy() |> 35 | unclass(), 36 | ignore_attr = TRUE 37 | ) 38 | }) 39 | 40 | test_that("ard_stats_poisson_test() works for two sample tests", { 41 | expect_silent( 42 | ard_compare <- 43 | cards::ADTTE |> 44 | dplyr::filter(TRTA %in% c("Placebo", "Xanomeline High Dose")) |> 45 | ard_stats_poisson_test(by = TRTA, variables = c(CNSR, AVAL)) 46 | ) 47 | 48 | # Statistics calculated correctly 49 | expect_equal( 50 | ard_compare |> 51 | cards::get_ard_statistics( 52 | stat_name %in% 53 | c("estimate", "statistic", "p.value", "parameter", "conf.low", "conf.high", "method", "alternative") 54 | ), 55 | poisson.test( 56 | x = cards::ADTTE |> 57 | dplyr::filter(TRTA %in% c("Placebo", "Xanomeline High Dose")) |> 58 | dplyr::group_by(TRTA) |> 59 | dplyr::summarise(sum = sum(CNSR)) |> 60 | dplyr::pull(sum), 61 | T = cards::ADTTE |> 62 | dplyr::filter(TRTA %in% c("Placebo", "Xanomeline High Dose")) |> 63 | dplyr::group_by(TRTA) |> 64 | dplyr::summarise(sum = sum(AVAL)) |> 65 | dplyr::pull(sum) 66 | ) |> 67 | broom::tidy() |> 68 | unclass(), 69 | ignore_attr = TRUE 70 | ) 71 | }) 72 | 73 | test_that("ard_stats_poisson_test() errors are handled correctly", { 74 | expect_snapshot( 75 | cards::ADTTE |> 76 | ard_stats_poisson_test(by = TRTA, variables = c(CNSR, AVAL)), 77 | error = TRUE 78 | ) 79 | }) 80 | 81 | test_that("ard_stats_poisson_test() follows ard structure", { 82 | expect_silent( 83 | ard_stats_poisson_test(cards::ADTTE, variables = c(CNSR, AVAL)) |> 84 | cards::check_ard_structure(method = T) 85 | ) 86 | }) 87 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_t_test_onesample.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_t_test_onesample() works", { 4 | # first calculate an object to test against 5 | expect_silent( 6 | ard1 <- ard_stats_t_test_onesample( 7 | cards::ADSL, 8 | variables = AGE, 9 | by = ARM, 10 | conf.level = 0.9, 11 | mu = 1 12 | ) 13 | ) 14 | 15 | # first check arguments passed and returned correctly 16 | expect_equal( 17 | cards::get_ard_statistics( 18 | ard1, 19 | group1_level %in% "Placebo" 20 | )[c("mu", "conf.level")], 21 | list(mu = 1, conf.level = 0.9) 22 | ) 23 | # check results are correct 24 | expect_equal( 25 | cards::get_ard_statistics( 26 | ard1, 27 | group1_level %in% "Placebo" 28 | )[c("estimate", "conf.low", "conf.high", "p.value")], 29 | t.test( 30 | cards::ADSL$AGE[cards::ADSL$ARM == "Placebo"], 31 | conf.level = 0.9, 32 | mu = 1 33 | ) |> 34 | broom::tidy() |> 35 | dplyr::select(c("estimate", "conf.low", "conf.high", "p.value")) |> 36 | as.list() 37 | ) 38 | 39 | # test the structure is good 40 | expect_silent(cards::check_ard_structure(ard1)) 41 | 42 | # empty tibble returned with no variables 43 | expect_equal( 44 | ard_stats_t_test_onesample( 45 | cards::ADSL, 46 | variables = character(0) 47 | ), 48 | dplyr::tibble() |> cards::as_card() 49 | ) 50 | }) 51 | 52 | test_that("ard_stats_t_test_onesample() follows ard structure", { 53 | expect_silent( 54 | ard_stats_t_test_onesample( 55 | cards::ADSL, 56 | variables = AGE, 57 | by = ARM, 58 | conf.level = 0.9, 59 | mu = 1 60 | ) |> 61 | cards::check_ard_structure() 62 | ) 63 | }) 64 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_stats_wilcox_test_onesample.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("broom")) 2 | 3 | test_that("ard_stats_wilcox_test_onesample() works", { 4 | # first calculate an object to test against 5 | expect_silent( 6 | ard1 <- ard_stats_wilcox_test_onesample( 7 | cards::ADSL, 8 | variables = AGE, 9 | by = ARM, 10 | conf.level = 0.9, 11 | conf.int = TRUE, 12 | mu = 1 13 | ) 14 | ) 15 | 16 | # first check arguments passed and returned correctly 17 | expect_equal( 18 | cards::get_ard_statistics( 19 | ard1, 20 | group1_level %in% "Placebo" 21 | )[c("mu", "conf.level")], 22 | list(mu = 1, conf.level = 0.9) 23 | ) 24 | # check results are correct 25 | expect_equal( 26 | cards::get_ard_statistics( 27 | ard1, 28 | group1_level %in% "Placebo" 29 | )[c("estimate", "conf.low", "conf.high", "p.value")], 30 | wilcox.test( 31 | cards::ADSL$AGE[cards::ADSL$ARM == "Placebo"], 32 | conf.level = 0.9, 33 | mu = 1, 34 | conf.int = TRUE 35 | ) |> 36 | broom::tidy() |> 37 | dplyr::select(c("estimate", "conf.low", "conf.high", "p.value")) |> 38 | as.list() 39 | ) 40 | 41 | # test the structure is good 42 | expect_silent(cards::check_ard_structure(ard1)) 43 | 44 | # empty tibble returned with no variables 45 | expect_equal( 46 | ard_stats_wilcox_test_onesample( 47 | cards::ADSL, 48 | variables = character(0) 49 | ), 50 | dplyr::tibble() |> cards::as_card() 51 | ) 52 | }) 53 | 54 | test_that("ard_stats_wilcox_test_onesample() follows ard structure", { 55 | expect_silent( 56 | ard_stats_wilcox_test_onesample( 57 | cards::ADSL, 58 | variables = AGE, 59 | by = ARM, 60 | conf.level = 0.9, 61 | conf.int = TRUE, 62 | mu = 1 63 | ) |> 64 | cards::check_ard_structure() 65 | ) 66 | }) 67 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_survey_svychisq.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(c("survey", "broom"))) 2 | 3 | test_that("ard_survey_svychisq() works", { 4 | data(api, package = "survey") 5 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 6 | 7 | expect_error( 8 | ard_svychisq <- 9 | ard_survey_svychisq( 10 | dclus2, 11 | variables = sch.wide, 12 | by = comp.imp, 13 | statistic = "F" 14 | ), 15 | NA 16 | ) 17 | 18 | expect_equal( 19 | cards::get_ard_statistics( 20 | ard_svychisq, 21 | stat_name %in% c("statistic", "p.value") 22 | ), 23 | survey::svychisq(~ sch.wide + comp.imp, dclus2)[c("statistic", "p.value")], 24 | ignore_attr = TRUE 25 | ) 26 | 27 | # test that the function works with multiple variables 28 | expect_snapshot( 29 | ard_survey_svychisq( 30 | dclus2, 31 | variables = c(sch.wide, stype), 32 | by = comp.imp, 33 | statistic = "adjWald" 34 | ) |> 35 | dplyr::select(c(1:3, 5:6)) |> 36 | dplyr::group_by(variable) |> 37 | dplyr::slice_head(n = 3) |> 38 | as.data.frame() 39 | ) 40 | 41 | 42 | expect_equal( 43 | dplyr::bind_rows( 44 | ard_svychisq, 45 | dclus2 |> 46 | ard_survey_svychisq(by = comp.imp, variables = stype) 47 | ), 48 | dclus2 |> 49 | ard_survey_svychisq(by = comp.imp, variables = c(sch.wide, stype)) 50 | ) 51 | 52 | # works with non-syntactic names 53 | expect_equal( 54 | { 55 | dclus2_syntactic <- dclus2 56 | dclus2_syntactic$variables <- 57 | dplyr::rename(dclus2_syntactic$variables, `comp imp` = comp.imp) 58 | ard_survey_svychisq( 59 | dclus2, 60 | variables = sch.wide, 61 | by = comp.imp, 62 | statistic = "F" 63 | )[c("context", "stat_name", "stat_label", "stat")] 64 | }, 65 | ard_svychisq[c("context", "stat_name", "stat_label", "stat")] 66 | ) 67 | }) 68 | 69 | test_that("ard_survey_svychisq() follows ard structure", { 70 | data(api, package = "survey") 71 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 72 | expect_silent( 73 | ard_survey_svychisq( 74 | dclus2, 75 | variables = sch.wide, 76 | by = comp.imp, 77 | statistic = "F" 78 | ) |> 79 | cards::check_ard_structure() 80 | ) 81 | }) 82 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_survey_svyranktest.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(c("survey", "broom"))) 2 | 3 | test_that("ard_survey_svyranktest() works", { 4 | data(api, package = "survey") 5 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 6 | svyranktest <- lapply( 7 | c("wilcoxon", "vanderWaerden", "median", "KruskalWallis"), 8 | function(x) { 9 | ard_survey_svyranktest( 10 | dclus2, 11 | variable = enroll, 12 | by = comp.imp, 13 | test = x 14 | ) 15 | } 16 | ) 17 | 18 | expect_snapshot(svyranktest[[1]] |> as.data.frame() |> dplyr::select(stat_label, stat)) 19 | expect_snapshot(svyranktest[[2]] |> as.data.frame() |> dplyr::select(stat_label, stat)) 20 | expect_snapshot(svyranktest[[3]] |> as.data.frame() |> dplyr::select(stat_label, stat)) 21 | expect_snapshot(svyranktest[[4]] |> as.data.frame() |> dplyr::select(stat_label, stat)) 22 | }) 23 | 24 | test_that("exact values match for ard_svyranktest works", { 25 | data(api, package = "survey") 26 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 27 | svywilcox <- ard_survey_svyranktest( 28 | dclus2, 29 | variable = enroll, 30 | by = comp.imp, 31 | test = "wilcoxon" 32 | ) 33 | expect_equal( 34 | cards::get_ard_statistics( 35 | svywilcox, 36 | stat_name %in% c("estimate", "p.value") 37 | ), 38 | survey::svyranktest(enroll ~ comp.imp, dclus2, test = "wilcoxon")[c("estimate", "p.value")], 39 | ignore_attr = TRUE 40 | ) 41 | }) 42 | 43 | test_that("ard_survey_svyranktest() follows ard structure", { 44 | data(api, package = "survey") 45 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 46 | expect_silent( 47 | ard_survey_svyranktest( 48 | dclus2, 49 | variable = enroll, 50 | by = comp.imp, 51 | test = "wilcoxon" 52 | ) |> 53 | cards::check_ard_structure() 54 | ) 55 | }) 56 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_survey_svyttest.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(c("survey", "broom"))) 2 | 3 | test_that("ard_survey_svyttest() works", { 4 | data(api, package = "survey") 5 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 6 | 7 | expect_error( 8 | ard_svyttest <- 9 | ard_survey_svyttest( 10 | dclus2, 11 | variable = enroll, 12 | by = comp.imp, 13 | conf.level = 0.9 14 | ), 15 | NA 16 | ) 17 | 18 | expect_equal( 19 | cards::get_ard_statistics( 20 | ard_svyttest, 21 | stat_name %in% c("estimate", "p.value") 22 | ), 23 | survey::svyttest(enroll ~ comp.imp, dclus2)[c("estimate", "p.value")], 24 | ignore_attr = TRUE 25 | ) 26 | 27 | expect_equal( 28 | cards::get_ard_statistics( 29 | ard_svyttest, 30 | stat_name %in% c("conf.low", "conf.high") 31 | ), 32 | survey::svyttest(enroll ~ comp.imp, dclus2) |> 33 | confint(level = 0.9) |> 34 | as.list(), 35 | ignore_attr = TRUE 36 | ) 37 | 38 | # check that is works with multiple variables 39 | expect_equal( 40 | dplyr::bind_rows( 41 | ard_svyttest, 42 | ard_survey_svyttest( 43 | dclus2, 44 | variable = mobility, 45 | by = comp.imp, 46 | conf.level = 0.9 47 | ) 48 | ), 49 | ard_survey_svyttest( 50 | dclus2, 51 | variable = c(enroll, mobility), 52 | by = comp.imp, 53 | conf.level = 0.9 54 | ) 55 | ) 56 | }) 57 | 58 | test_that("ard_survey_svyttest() messaging", { 59 | data(api, package = "survey") 60 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 61 | 62 | expect_error( 63 | ard_svyttest <- 64 | ard_survey_svyttest( 65 | dclus2, 66 | variable = enroll, 67 | by = stype 68 | ), 69 | NA 70 | ) 71 | expect_equal( 72 | ard_svyttest$error |> unique() |> unlist(), 73 | "group must be binary" 74 | ) 75 | }) 76 | 77 | test_that("ard_survey_svyttest() follows ard structure", { 78 | data(api, package = "survey") 79 | dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) 80 | expect_silent( 81 | ard_survey_svyttest( 82 | dclus2, 83 | variable = enroll, 84 | by = comp.imp, 85 | conf.level = 0.9 86 | ) |> 87 | cards::check_ard_structure() 88 | ) 89 | }) 90 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_survival_survdiff.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(c("survival", "broom"))) 2 | 3 | test_that("ard_survival_survdiff() works", { 4 | # Log-rank test ---- 5 | expect_error( 6 | ard_survival_survdiff <- 7 | ard_survival_survdiff(survival::Surv(AVAL, CNSR) ~ TRTA, data = cards::ADTTE), 8 | NA 9 | ) 10 | 11 | expect_equal( 12 | ard_survival_survdiff |> 13 | dplyr::slice(-nrow(ard_survival_survdiff)) |> 14 | cards::get_ard_statistics(), 15 | survival::survdiff(survival::Surv(AVAL, CNSR) ~ TRTA, data = cards::ADTTE) |> 16 | broom::glance() |> 17 | as.list() 18 | ) 19 | expect_equal( 20 | ard_survival_survdiff$stat[ard_survival_survdiff$stat_name %in% "method"], 21 | list("Log-rank test") 22 | ) 23 | 24 | # Tarone-Ware test ---- 25 | expect_error( 26 | ard_survival_survdiff <- 27 | ard_survival_survdiff(survival::Surv(AVAL, CNSR) ~ TRTA, data = cards::ADTTE, rho = 1.5), 28 | NA 29 | ) 30 | 31 | expect_equal( 32 | ard_survival_survdiff |> 33 | dplyr::slice(-nrow(ard_survival_survdiff)) |> 34 | cards::get_ard_statistics(), 35 | survival::survdiff(survival::Surv(AVAL, CNSR) ~ TRTA, data = cards::ADTTE, rho = 1.5) |> 36 | broom::glance() |> 37 | as.list() 38 | ) 39 | expect_equal( 40 | ard_survival_survdiff$stat[ard_survival_survdiff$stat_name %in% "method"], 41 | list("Tarone-Ware test") 42 | ) 43 | }) 44 | 45 | test_that("ard_survival_survdiff() error messaging", { 46 | expect_error( 47 | ard_survival_survdiff(survival::Surv(AVAL, CNSR) ~ 1, data = cards::ADTTE), 48 | "There was an error" 49 | ) 50 | 51 | expect_error( 52 | ard_survival_survdiff <- 53 | ard_survival_survdiff(survival::Surv(AVAL, CNSR) ~ not_a_variable, data = cards::ADTTE), 54 | NA 55 | ) 56 | expect_true( 57 | ard_survival_survdiff |> nrow() == 4L 58 | ) 59 | expect_true( 60 | ard_survival_survdiff$error |> unique() |> grepl(pattern = "*'not_a_variable'*", x = _) 61 | ) 62 | }) 63 | 64 | test_that("ard_survival_survdiff() follows ard structure", { 65 | expect_silent( 66 | ard_survival_survdiff(survival::Surv(AVAL, CNSR) ~ TRTA, data = cards::ADTTE) |> 67 | cards::check_ard_structure() 68 | ) 69 | }) 70 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_survival_survfit_diff.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed(c("survival", "broom"))) 2 | 3 | test_that("ard_survival_survfit_diff() works", { 4 | withr::local_package("survival") 5 | sf <- survfit(Surv(AVAL, 1 - CNSR) ~ SEX, cards::ADTTE) 6 | expect_silent( 7 | ard1 <- ard_survival_survfit_diff(sf, times = c(25, 50)) 8 | ) 9 | 10 | # check the survival differences are accurate 11 | expect_equal( 12 | ard1 |> 13 | dplyr::filter(variable_level == 25, stat_name == "estimate") |> 14 | dplyr::pull(stat) |> 15 | unlist(), 16 | summary(sf, times = 25) |> 17 | getElement("surv") |> 18 | reduce(`-`) 19 | ) 20 | expect_equal( 21 | ard1 |> 22 | dplyr::filter(variable_level == 50, stat_name == "estimate") |> 23 | dplyr::pull(stat) |> 24 | unlist(), 25 | summary(sf, times = 50) |> 26 | getElement("surv") |> 27 | reduce(`-`) 28 | ) 29 | 30 | # check the structure of the ARD object 31 | expect_silent( 32 | cards::check_ard_structure(ard1) 33 | ) 34 | }) 35 | 36 | test_that("ard_survival_survfit_diff() messaging", { 37 | withr::local_package("survival") 38 | 39 | # we can only do one stratifying variable at a time 40 | expect_snapshot( 41 | error = TRUE, 42 | survfit(Surv(AVAL, 1 - CNSR) ~ SEX + TRTA, cards::ADTTE) |> 43 | ard_survival_survfit_diff(times = c(25, 50)) 44 | ) 45 | 46 | # the stratifying variable must have 2 or more levels 47 | expect_snapshot( 48 | error = TRUE, 49 | survfit( 50 | Surv(AVAL, 1 - CNSR) ~ constant, 51 | cards::ADTTE |> dplyr::mutate(constant = 1L) 52 | ) |> 53 | ard_survival_survfit_diff(times = c(25, 50)) 54 | ) 55 | 56 | # cannot pass a multi-state model or stratified Cox 57 | expect_snapshot( 58 | error = TRUE, 59 | coxph(Surv(AVAL, CNSR) ~ SEX + strata(TRTA), cards::ADTTE) |> 60 | survfit() |> 61 | ard_survival_survfit_diff(times = c(25, 50)) 62 | ) 63 | }) 64 | 65 | test_that("ard_survival_survfit_diff() follows ard structure", { 66 | withr::local_package("survival") 67 | sf <- survfit(Surv(AVAL, 1 - CNSR) ~ SEX, cards::ADTTE) 68 | expect_silent( 69 | ard_survival_survfit_diff(sf, times = c(25, 50)) |> 70 | cards::check_ard_structure() 71 | ) 72 | }) 73 | -------------------------------------------------------------------------------- /tests/testthat/test-ard_total_n.survey.design.R: -------------------------------------------------------------------------------- 1 | skip_if_not(is_pkg_installed("survey")) 2 | 3 | test_that("ard_total_n.survey.design() works", { 4 | expect_snapshot( 5 | survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |> 6 | ard_total_n() 7 | ) 8 | }) 9 | 10 | test_that("ard_total_n.survey.design() follows ard structure", { 11 | expect_silent( 12 | survey::svydesign(~1, data = as.data.frame(Titanic), weights = ~Freq) |> 13 | ard_total_n() |> 14 | cards::check_ard_structure(method = FALSE) 15 | ) 16 | }) 17 | --------------------------------------------------------------------------------