Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolving Merge Conflicts for #112 #115

Merged
merged 15 commits into from
Apr 15, 2024
Merged
4 changes: 1 addition & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ Pre-review Checklist (if item does not apply, mark is as complete)
- [ ] If a bug was fixed, a unit test was added.
- [ ] If a new `ard_*()` function was added, it passes the ARD structural checks from `cards::check_ard_structure()`.
- [ ] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()`
- [ ] Request a reviewer

Reviewer Checklist (if item does not apply, mark is as complete)

- [ ] If a bug was fixed, a unit test was added.
- [ ] Run `pkgdown::build_site()`. Check the R console for errors, and review the rendered website.
- [ ] Code coverage is suitable for any new functions/features: `devtools::test_coverage()`

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the heading "`# cards (development version)`". If there is an issue associated with the pull request, reference it in parentheses at the end update (see `NEWS.md` for examples).
- [ ] Update `NEWS.md` with the changes from this pull request under the heading "`# cardx (development version)`". If there is an issue associated with the pull request, reference it in parentheses at the end update (see `NEWS.md` for examples).
- [ ] **All** GitHub Action workflows pass with a :white_check_mark:
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ on:
- synchronize
- reopened
- ready_for_review
branches:
- main
push:
branches:
- main
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

Expand Down
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cardx
Title: Extra Analysis Results Data Utilities
Version: 0.1.0.9011
Version: 0.1.0.9014
Authors@R: c(
person("Daniel", "Sjoberg", , "[email protected]", role = c("aut", "cre")),
person("Abinaya", "Yogasekaram", , "[email protected]", role = "aut"),
Expand All @@ -25,17 +25,20 @@ Imports:
rlang (>= 1.1.1),
tidyr (>= 1.3.0)
Suggests:
aod (>= 1.3.3),
broom (>= 1.0.5),
broom.helpers (>= 1.13.0),
car (>= 3.0-11),
effectsize (>= 0.6.0),
geepack (>= 1.3.2),
lme4 (>= 1.1-31),
parameters (>= 0.20.2),
smd (>= 0.6.6),
spelling,
survey (>= 4.1),
survival (>= 3.2-11),
testthat (>= 3.2.0),
withr
withr (>= 2.5.0)
Remotes:
insightsengineering/cards
Config/Needs/website: insightsengineering/nesttemplate
Expand Down
51 changes: 28 additions & 23 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
# Generated by roxygen2: do not edit by hand

S3method(ard_regression,default)
S3method(ard_stats_anova,anova)
S3method(ard_stats_anova,data.frame)
export("%>%")
export(all_of)
export(any_of)
export(ard_aov)
export(ard_aod_wald_test)
export(ard_car_anova)
export(ard_chisqtest)
export(ard_cohens_d)
export(ard_fishertest)
export(ard_hedges_g)
export(ard_kruskaltest)
export(ard_mcnemartest)
export(ard_moodtest)
export(ard_onewaytest)
export(ard_paired_cohens_d)
export(ard_paired_hedges_g)
export(ard_paired_ttest)
export(ard_paired_wilcoxtest)
export(ard_car_vif)
export(ard_effectsize_cohens_d)
export(ard_effectsize_hedges_g)
export(ard_effectsize_paired_cohens_d)
export(ard_effectsize_paired_hedges_g)
export(ard_proportion_ci)
export(ard_proptest)
export(ard_regression)
export(ard_regression_basic)
export(ard_smd)
export(ard_survfit)
export(ard_svychisq)
export(ard_svycontinuous)
export(ard_svyranktest)
export(ard_svyttest)
export(ard_ttest)
export(ard_vif)
export(ard_wilcoxtest)
export(ard_smd_smd)
export(ard_stats_anova)
export(ard_stats_aov)
export(ard_stats_chisq_test)
export(ard_stats_fisher_test)
export(ard_stats_kruskal_test)
export(ard_stats_mcnemar_test)
export(ard_stats_mood_test)
export(ard_stats_oneway_test)
export(ard_stats_paired_t_test)
export(ard_stats_paired_wilcox_test)
export(ard_stats_prop_test)
export(ard_stats_t_test)
export(ard_stats_wilcox_test)
export(ard_survey_svychisq)
export(ard_survey_svycontinuous)
export(ard_survey_svyranktest)
export(ard_survey_svyttest)
export(ard_survival_survfit)
export(contains)
export(ends_with)
export(everything)
Expand All @@ -48,6 +52,7 @@ export(starts_with)
export(where)
import(rlang)
importFrom(dplyr,"%>%")
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,any_of)
importFrom(dplyr,contains)
Expand Down
48 changes: 34 additions & 14 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
# cardx 0.1.0.9011
# cardx 0.1.0.9014

### Breaking Changes

* Updated function names to follow the pattern `ard_<pkgname>_<fnname>()`. Former functions names have _not_ been deprecated. (#106)

```r
ard_ttest() -> ard_stats_t_test()
ard_paired_ttest() -> ard_stats_paired_t_test()
ard_wilcoxtest() -> ard_stats_wilcox_test()
ard_paired_wilcoxtest() -> ard_stats_paired_wilcox_test()
ard_chisqtest() -> ard_stats_chisq_test()
ard_fishertest() -> ard_stats_fisher_test()
ard_kruskaltest() -> ard_stats_kruskal_test()
ard_mcnemartest() -> ard_stats_mcnemar_test()
ard_moodtest() -> ard_stats_mood_test()
```

### New Features

* Added the following functions for calculating Analysis Results Data (ARD).
- `ard_aov()` for calculating ANOVA results using `stats::aov()`. (#3)
- `ard_stats_aov()` for calculating ANOVA results using `stats::aov()`. (#3)
- `ard_stats_anova()` for calculating ANOVA results using `stats::anova()`. (#12)
- `ard_aod_wald_test()` for calculating Wald Tests for regression models using `aod::wald.test()`. (#84)
- `ard_car_anova()` for calculating ANOVA results using `car::Anova()`. (#3)
- `ard_onewaytest()` for calculating ANOVA results using `stats::oneway.test()`. (#3)
- `ard_cohens_d()`, `ard_paired_cohens_d()`, `ard_hedges_g()`, and `ard_paired_hedges_g()` for standardized differences using `effectsize::cohens_d()` and `effectsize::hedges_g()`. (#50)
- `ard_proptest()` for tests of proportions using `stats::prop.test()`. (#64)
- `ard_stats_oneway_test()` for calculating ANOVA results using `stats::oneway.test()`. (#3)
- `ard_effectsize_cohens_d()`, `ard_effectsize_paired_cohens_d()`, `ard_effectsize_hedges_g()`, and `ard_effectsize_paired_hedges_g()` for standardized differences using `effectsize::cohens_d()` and `effectsize::hedges_g()`. (#50)
- `ard_stats_prop_test()` for tests of proportions using `stats::prop.test()`. (#64)
- `ard_regression_basic()` for basic regression models. The function focuses on matching terms to underlying variables names. (#46)
- `ard_smd()` for calculating standardized mean differences using `smd::smd()`. (#4)
- `ard_survfit()` for survival analyses using `survival::survfit()`. (#43)
- `ard_svycontinuous()` for calculating univariate summary statistics from weighted/survey data using many functions from the {survey} package. (#68)
- `ard_svychisq()` for weighted/survey chi-squared test using `survey::svychisq()`. (#72)
- `ard_svyttest()` for weighted/survey t-tests using `survey::svyttest()`. (#70)
- `ard_svyranktest()` for weighted/survey rank tests using `survey::svyranktest()`. (#71)
- `ard_vif()` for calculating the variance inflation factor using `car::vif()`. (#10)
- `ard_smd_smd()` for calculating standardized mean differences using `smd::smd()`. (#4)
- `ard_survival_survfit()` for survival analyses using `survival::survfit()`. (#43)
- `ard_survey_svycontinuous()` for calculating univariate summary statistics from weighted/survey data using many functions from the {survey} package. (#68)
- `ard_survey_svychisq()` for weighted/survey chi-squared test using `survey::svychisq()`. (#72)
- `ard_survey_svyttest()` for weighted/survey t-tests using `survey::svyttest()`. (#70)
- `ard_survey_svyranktest()` for weighted/survey rank tests using `survey::svyranktest()`. (#71)
- `ard_car_vif()` for calculating the variance inflation factor using `car::vif()`. (#10)

* Updated functions `ard_ttest()`, `ard_paired_ttest()`, `ard_wilcoxtest()`, `ard_paired_wilcoxtest()`, `ard_chisqtest()`, `ard_fishertest()`, `ard_kruskaltest()`, `ard_mcnemartest()`, and `ard_moodtest()` to accept multiple variables at once. Independent tests are calculated for each variable. The `variable` argument is renamed to `variables`. (#77)
* Updated functions `ard_stats_t_test()`, `ard_stats_paired_t_test()`, `ard_stats_wilcox_test()`, `ard_stats_paired_wilcox_test()`, `ard_stats_chisq_test()`, `ard_stats_fisher_test()`, `ard_stats_kruskal_test()`, `ard_stats_mcnemar_test()`, and `ard_stats_mood_test()` to accept multiple variables at once. Independent tests are calculated for each variable. The `variable` argument is renamed to `variables`. (#77)

* Updated `ard_ttest()` and `ard_wilcoxtest()` to no longer require the `by` argument, which yields central estimates with their confidence intervals. (#82)
* Updated `ard_stats_t_test()` and `ard_stats_wilcox_test()` to no longer require the `by` argument, which yields central estimates with their confidence intervals. (#82)

# cardx 0.1.0

Expand Down
118 changes: 118 additions & 0 deletions R/ard_aod_wald_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#' ARD Wald Test
#'
#' @description
#' Function takes a regression model object and calculates Wald
#' statistical test using [`aod::wald.test()`].
#'
#' @param x regression model object
#' @param ... arguments passed to `aod::wald.test(...)`
#'
#' @return data frame
#' @export
#'
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "aod", reference_pkg = "cardx"))
#' lm(AGE ~ ARM, data = cards::ADSL) |>
#' ard_aod_wald_test()
ard_aod_wald_test <- function(x, ...) {
set_cli_abort_call()
# check installed packages ---------------------------------------------------
check_pkg_installed("aod", reference_pkg = "cardx")

# check inputs ---------------------------------------------------------------
check_not_missing(x)

# run regression() -----------------------------------------------------------
reg_model <- cards::eval_capture_conditions(
ard_regression_basic(x, intercept = TRUE, stats_to_remove = c(
"var_type",
"var_label",
"var_class", "label",
"contrasts_type", "contrasts", "var_nlevels", "std.error",
"conf.low", "conf.high", "statistic", "p.value", "estimate"
))
)

if (!is.null(reg_model[["error"]])) {
cli::cli_abort(
c("Unable to identify underlying variable names in regression model.",
i = "Is this model type supported by {.fun broom.helpers::tidy_plus_plus}, which is the function used to identify variable names?"
),
call = get_cli_abort_call()
)
}
aod <-
reg_model[["result"]] %>%
dplyr::select(c(
variable = "variable",
model_terms = "stat"
)) %>%
dplyr::mutate(term_id = dplyr::row_number()) %>%
tidyr::nest(data = -"variable") %>%
dplyr::rowwise() %>%
dplyr::mutate(
model_terms = unlist(.data$data[["model_terms"]]) %>% list(),
model_terms_id = rlang::set_names(.data$data[["term_id"]]) %>% list()
)
# run wald.test() -----------------------------------------------------------
wald_test <-
cards::eval_capture_conditions(lapply(seq_len(length(aod$model_terms_id)), function(terms_id) {
aod::wald.test(
Sigma = stats::vcov(x),
b = stats::coef(x), Terms = aod$model_terms_id[[terms_id]]
)
}))


df_list <- do.call(rbind, lapply(wald_test$result, .extract_wald_results))

cbind(aod$variable, df_list) %>%
tidyr::pivot_longer(
cols = !"aod$variable",
names_to = "stat_name",
values_to = "stat"
) %>%
dplyr::rename(
"variable" = "aod$variable"
) |>
dplyr::mutate(
stat = as.list(.data$stat),
stat_label =
dplyr::case_when(
.data$stat_name %in% "statistic" ~ "Statistic",
.data$stat_name %in% "df" ~ "Degrees of Freedom",
.data$stat_name %in% "p.value" ~ "p-value",
TRUE ~ .data$stat_name
),
fmt_fn =
map(
.data$stat,
function(.x) {
# styler: off
if (is.integer(.x)) return(0L)
if (is.numeric(.x)) return(1L)
# styler: on
NULL
}
),
context = "aod_wald_test",
warning = wald_test["warning"],
error = wald_test["error"]
) |>
cards::tidy_ard_column_order() %>%
{structure(., class = c("card", class(.)))} # styler: off
}

#' Extract data from wald.test object
#'
#'
#' @param wald_test (`data.frame`)\cr wald test object object from `aod::wald.test()`
#'
#' @return a data frame containing the wald test results.
#' @keywords internal

.extract_wald_results <- function(wald_test) {
df <- wald_test$result$chi2[("df")]
statistic <- wald_test$result$chi2[("chi2")]
p.value <- wald_test$result$chi2[("P")]
data.frame(df, statistic, p.value)
}
11 changes: 7 additions & 4 deletions R/ard_car_anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ ard_car_anova <- function(x, ...) {
car_anova <- cards::eval_capture_conditions(car::Anova(x, ...))

if (!is.null(car_anova[["error"]])) {
cli::cli_abort(c(
"There was an error running {.fun car::Anova}. See error message below.",
x = car_anova[["error"]]
))
cli::cli_abort(
c(
"There was an error running {.fun car::Anova}. See error message below.",
x = car_anova[["error"]]
),
call = get_cli_abort_call()
)
}

car_anova[["result"]] |>
Expand Down
15 changes: 9 additions & 6 deletions R/ard_vif.R → R/ard_car_vif.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
#' @param ... arguments passed to `car::vif(...)`
#'
#' @return data frame
#' @name ard_vif
#' @rdname ard_vif
#' @name ard_car_vif
#' @rdname ard_car_vif
#' @export
#'
#' @examples
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "car", reference_pkg = "cardx"))
#' lm(AGE ~ ARM + SEX, data = cards::ADSL) |>
#' ard_vif()
ard_vif <- function(x, ...) {
#' ard_car_vif()
ard_car_vif <- function(x, ...) {
set_cli_abort_call()
check_pkg_installed("car", reference_pkg = "cardx")
# check inputs ---------------------------------------------------------------
check_not_missing(x)

Expand All @@ -30,7 +32,8 @@ ard_vif <- function(x, ...) {
# we cannot get variable names, error out
if (!is.null(lst_terms[["error"]])) {
cli::cli_abort(
c("There was an error running {.fun car::vif}. See below.", x = vif[["error"]])
c("There was an error running {.fun car::vif}. See below.", x = vif[["error"]]),
call = get_cli_abort_call()
)
}
vif$result <- dplyr::tibble(
Expand Down
Loading
Loading