Skip to content

Commit

Permalink
Merge branch 'main' into 187_ard_poisson_test@main
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua authored Aug 22, 2024
2 parents 257c585 + 9b08b6f commit d38cc2e
Show file tree
Hide file tree
Showing 46 changed files with 338 additions and 220 deletions.
2 changes: 1 addition & 1 deletion 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.2.0.9006
Version: 0.2.0.9008
Authors@R: c(
person("Daniel", "Sjoberg", , "[email protected]", role = c("aut", "cre")),
person("Abinaya", "Yogasekaram", , "[email protected]", role = "aut"),
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# cardx 0.2.0.9006
# cardx 0.2.0.9008

* Bug fix in `ard_categorical.survey.design()` where all unweighted statistics were returned, even in the case where they were explicitly not requested.

* Added S3 method `ard_total_n.survey.design()` which returns an ARD with both the survey-weighted and unweighted total sample size.

* Added `warning` and `error` columns to `ard_regression()` output. (#148)

* Implemented `cards::as_card()` where needed in the package to convert data frames to class 'card'. (#200)

# cardx 0.2.0

### Breaking Changes
Expand Down
4 changes: 2 additions & 2 deletions R/ard_aod_wald_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ ard_aod_wald_test <- function(x, tidy_fun = broom.helpers::tidy_with_broom_or_pa
warning = wald_test["warning"],
error = wald_test["error"]
) |>
cards::tidy_ard_column_order() %>%
{structure(., class = c("card", class(.)))} # styler: off
cards::as_card() |>
cards::tidy_ard_column_order()
}

#' Extract data from wald.test object
Expand Down
4 changes: 2 additions & 2 deletions R/ard_car_anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ ard_car_anova <- function(x, ...) {
warning = car_anova["warning"],
error = car_anova["error"]
) |>
cards::tidy_ard_column_order() %>%
{structure(., class = c("card", class(.)))} # styler: off
cards::as_card() |>
cards::tidy_ard_column_order()
}
4 changes: 2 additions & 2 deletions R/ard_car_vif.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ ard_car_vif <- function(x, ...) {

# Clean up return object
vif_return |>
cards::tidy_ard_column_order() %>%
{structure(., class = c("card", class(.)))} # styler: off
cards::as_card() |>
cards::tidy_ard_column_order()
}
15 changes: 6 additions & 9 deletions R/ard_categorical.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ ard_categorical.survey.design <- function(data,
variables <- setdiff(variables, by)
check_scalar(by, allow_empty = TRUE)

# if no variables selected, return empty data frame
if (is_empty(variables)) return(dplyr::tibble()) # styler: off
# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble() |> cards::as_card())
}

check_na_factor_levels(data$variables, c(by, variables))

Expand All @@ -97,11 +99,6 @@ ard_categorical.survey.design <- function(data,
)
denominator <- arg_match(denominator)

# return empty tibble if no variables selected -------------------------------
if (is_empty(variables)) {
return(dplyr::tibble())
}

# check the missingness
walk(
variables,
Expand Down Expand Up @@ -215,8 +212,8 @@ ard_categorical.survey.design <- function(data,
warning = list(NULL),
error = list(NULL),
) |>
cards::tidy_ard_column_order() %>%
{structure(., class = c("card", class(.)))} |> # styler: off
cards::as_card() |>
cards::tidy_ard_column_order() |>
cards::tidy_ard_row_order()
}

Expand Down
6 changes: 6 additions & 0 deletions R/ard_categorical_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ ard_categorical_ci.data.frame <- function(data,
data[variables],
value = value
)
check_not_missing(variables)

# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble() |> cards::as_card())
}

# calculate confidence intervals ---------------------------------------------
map(
Expand Down
12 changes: 7 additions & 5 deletions R/ard_categorical_ci.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ ard_categorical_ci.survey.design <- function(data,
check_scalar_range(conf.level, range = c(0, 1))
method <- arg_match(method)

# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble() |> cards::as_card())
}

# calculate and return ARD of one sample CI ----------------------------------
.calculate_ard_onesample_survey_ci(
FUN = .svyciprop_wrapper,
Expand All @@ -65,9 +70,6 @@ ard_categorical_ci.survey.design <- function(data,
}

.calculate_ard_onesample_survey_ci <- function(FUN, data, variables, by, conf.level, value, ...) {
# return empty data frame if no variables to process -------------------------
if (is_empty(variables)) return(dplyr::tibble()) # styler: off

# calculate results ----------------------------------------------------------
map(
variables,
Expand Down Expand Up @@ -142,8 +144,8 @@ ard_categorical_ci.survey.design <- function(data,
stat_label = .data$stat_name,
fmt_fn = map(.data$stat, ~ case_switch(is.numeric(.x) ~ 2L, .default = as.character))
) |>
cards::tidy_ard_column_order() %>%
structure(., class = c("card", class(.)))
cards::as_card() |>
cards::tidy_ard_column_order()

# if a value was passed for the variable, subset on those results
if (!is_empty(value)) {
Expand Down
8 changes: 4 additions & 4 deletions R/ard_continuous.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ ard_continuous.survey.design <- function(data, variables, by = NULL,
)
)

# return empty tibble if no variables selected -------------------------------
# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble())
return(dplyr::tibble() |> cards::as_card())
}

# compute the weighted statistics --------------------------------------------
Expand Down Expand Up @@ -147,8 +147,8 @@ ard_continuous.survey.design <- function(data, variables, by = NULL,
# add class and return ARD object --------------------------------------------
df_stats |>
dplyr::mutate(context = "continuous") |>
cards::tidy_ard_column_order() %>%
{structure(., class = c("card", class(.)))} # styler: off
cards::as_card() |>
cards::tidy_ard_column_order()
}

.default_svy_stat_labels <- function(stat_label = NULL) {
Expand Down
7 changes: 7 additions & 0 deletions R/ard_continuous_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ ard_continuous_ci.data.frame <- function(data, variables, by = dplyr::group_vars

# check inputs ---------------------------------------------------------------
method <- arg_match(method)
check_not_missing(variables)
cards::process_selectors(data, by = {{ by }}, variables = {{ variables }})

# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble() |> cards::as_card())
}

# calculate CIs --------------------------------------------------------------
switch(method,
Expand Down
12 changes: 7 additions & 5 deletions R/ard_continuous_ci.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ ard_continuous_ci.survey.design <- function(data,
}
)

# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble() |> cards::as_card())
}

# calculate and return ARD of one sample CI ----------------------------------
.calculate_ard_continuous_survey_ci(
FUN = ifelse(method == "svymean", .svymean_confint_wrapper, .svyquantile_confint_wrapper),
Expand All @@ -73,9 +78,6 @@ ard_continuous_ci.survey.design <- function(data,
}

.calculate_ard_continuous_survey_ci <- function(FUN, data, variables, by, conf.level, ...) {
# return empty data frame if no variables to process -------------------------
if (is_empty(variables)) return(dplyr::tibble()) # styler: off

# calculate results ----------------------------------------------------------
map(
variables,
Expand Down Expand Up @@ -143,8 +145,8 @@ ard_continuous_ci.survey.design <- function(data,
stat_label = .data$stat_name,
fmt_fn = map(.data$stat, ~ case_switch(is.numeric(.x) ~ 2L, .default = as.character))
) |>
cards::tidy_ard_column_order() %>%
structure(., class = c("card", class(.)))
cards::as_card() |>
cards::tidy_ard_column_order()
}

.svymean_confint_wrapper <- function(data, variable, conf.level, df, ...) {
Expand Down
4 changes: 2 additions & 2 deletions R/ard_dichotomous.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ ard_dichotomous.survey.design <- function(data,
)
.check_dichotomous_value(data$variables, value)

# return empty tibble if no variables selected -------------------------------
# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble())
return(dplyr::tibble() |> cards::as_card())
}

# calculate summary statistics -----------------------------------------------
Expand Down
10 changes: 6 additions & 4 deletions R/ard_effectsize_cohens_d.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ ard_effectsize_cohens_d <- function(data, by, variables, conf.level = 0.95, ...)
cards::process_selectors(data, by = {{ by }}, variables = {{ variables }})
check_scalar(by)
check_range(conf.level, range = c(0, 1))
# if no variables selected, return empty tibble ------------------------------

# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble())
return(dplyr::tibble() |> cards::as_card())
}

# build ARD ------------------------------------------------------------------
Expand Down Expand Up @@ -116,9 +117,9 @@ ard_effectsize_paired_cohens_d <- function(data, by, variables, id, conf.level =
check_scalar(id)
check_range(conf.level, range = c(0, 1))

# if no variables selected, return empty tibble ------------------------------
# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble())
return(dplyr::tibble() |> cards::as_card())
}

# build ARD ------------------------------------------------------------------
Expand Down Expand Up @@ -206,5 +207,6 @@ ard_effectsize_paired_cohens_d <- function(data, by, variables, id, conf.level =
by = "stat_name"
) |>
dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |>
cards::as_card() |>
cards::tidy_ard_column_order()
}
11 changes: 6 additions & 5 deletions R/ard_effectsize_hedges_g.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ ard_effectsize_hedges_g <- function(data, by, variables, conf.level = 0.95, ...)
check_scalar(by)
check_range(conf.level, range = c(0, 1))

# if no variables selected, return empty tibble ------------------------------
# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble())
return(dplyr::tibble() |> cards::as_card())
}

# build ARD ------------------------------------------------------------------
Expand Down Expand Up @@ -115,12 +115,12 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, conf.level =
check_scalar(id)
check_range(conf.level, range = c(0, 1))

# if no variables selected, return empty tibble ------------------------------
# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble())
return(dplyr::tibble() |> cards::as_card())
}
# build ARD ------------------------------------------------------------------

# build ARD ------------------------------------------------------------------
lapply(
variables,
function(variable) {
Expand Down Expand Up @@ -190,5 +190,6 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, conf.level =
by = "stat_name"
) |>
dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |>
cards::as_card() |>
cards::tidy_ard_column_order()
}
4 changes: 2 additions & 2 deletions R/ard_emmeans_mean_difference.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ ard_emmeans_mean_difference <- function(data, formula, method,
error = list(NULL),
fmt_fn = map(.data$stat, \(.x) if (is.numeric(.x)) 1L else NULL) # styler: off
) |>
cards::tidy_ard_column_order() %>%
{structure(., class = c("card", class(.)))} # styler: off
cards::as_card() |>
cards::tidy_ard_column_order()
}
9 changes: 7 additions & 2 deletions R/ard_missing.survey.design.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ ard_missing.survey.design <- function(data,
by = {{ by }}
)

# return empty ARD if no variables selected ----------------------------------
if (is_empty(variables)) {
return(dplyr::tibble() |> cards::as_card())
}

# convert all variables to T/F whether it's missing --------------------------
data$variables <- data$variables |>
dplyr::mutate(across(all_of(variables), Negate(is.na)))
Expand Down Expand Up @@ -126,6 +131,6 @@ ard_missing.survey.design <- function(data,
# return final object --------------------------------------------------------
result |>
dplyr::mutate(context = "missing") |>
cards::tidy_ard_column_order() %>%
{structure(., class = c("card", class(.)))} # styler: off
cards::as_card() |>
cards::tidy_ard_column_order()
}
Loading

0 comments on commit d38cc2e

Please sign in to comment.