-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into propagation-march-2024
- Loading branch information
Showing
130 changed files
with
3,481 additions
and
801 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ on: | |
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: R-CMD-check | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ on: | |
- synchronize | ||
- reopened | ||
- ready_for_review | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ on: | |
push: | ||
branches: [main, master] | ||
pull_request: | ||
branches: [main, master] | ||
|
||
name: test-coverage | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
Package: cardx | ||
Title: Extra Analysis Results Data Utilities | ||
Version: 0.1.0.9008 | ||
Version: 0.1.0.9021 | ||
Authors@R: c( | ||
person("Daniel", "Sjoberg", , "[email protected]", role = c("aut", "cre")), | ||
person("Abinaya", "Yogasekaram", , "[email protected]", role = "aut"), | ||
person("Emily", "de la Rua", , "[email protected]", role = "aut"), | ||
person("F. Hoffmann-La Roche AG", role = c("cph", "fnd")) | ||
) | ||
Description: Create extra Analysis Results Data (ARD) summary objects. | ||
|
@@ -17,23 +18,28 @@ BugReports: https://github.com/insightsengineering/cardx/issues | |
Depends: | ||
R (>= 4.1) | ||
Imports: | ||
cards (>= 0.1.0.9002), | ||
cards (>= 0.1.0.9014), | ||
cli (>= 3.6.1), | ||
dplyr (>= 1.1.2), | ||
glue (>= 1.6.2), | ||
rlang (>= 1.1.1), | ||
tidyr (>= 1.3.0) | ||
Suggests: | ||
aod (>= 1.3.3), | ||
broom (>= 1.0.5), | ||
broom.helpers (>= 1.13.0), | ||
broom.helpers (>= 1.15.0), | ||
car (>= 3.0-11), | ||
effectsize (>= 0.6.0), | ||
geepack (>= 1.3.2), | ||
ggsurvfit (>= 1.0.0), | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#' 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.