-
-
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 116-check-for-other-package-messaging
- Loading branch information
Showing
40 changed files
with
448 additions
and
182 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: cardx | ||
Title: Extra Analysis Results Data Utilities | ||
Version: 0.1.0.9017 | ||
Version: 0.1.0.9021 | ||
Authors@R: c( | ||
person("Daniel", "Sjoberg", , "[email protected]", role = c("aut", "cre")), | ||
person("Abinaya", "Yogasekaram", , "[email protected]", role = "aut"), | ||
|
@@ -27,10 +27,11 @@ Imports: | |
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), | ||
|
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
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
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
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
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
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
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,146 @@ | ||
#' ARD for Difference in Survival | ||
#' | ||
#' @description | ||
#' Analysis results data for comparison of survival using [survival::survdiff()]. | ||
#' | ||
#' @param formula (`formula`)\cr | ||
#' a formula | ||
#' @param data (`data.frame`)\cr | ||
#' a data frame | ||
#' @param rho (`scalar numeric`)\cr | ||
#' numeric scalar passed to `survival::survdiff(rho)`. Default is `rho=0`. | ||
#' @param ... additional arguments passed to `survival::survdiff()` | ||
#' | ||
#' @return an ARD data frame of class 'card' | ||
#' @export | ||
#' | ||
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "broom", "ggsurvfit"), reference_pkg = "cardx")) | ||
#' library(survival) | ||
#' library(ggsurvfit) | ||
#' | ||
#' ard_survival_survdiff(Surv_CNSR(AVAL, CNSR) ~ TRTA, data = cards::ADTTE) | ||
ard_survival_survdiff <- function(formula, data, rho = 0, ...) { | ||
set_cli_abort_call() | ||
|
||
# check installed packages --------------------------------------------------- | ||
check_pkg_installed(c("survival", "broom"), reference_pkg = "cardx") | ||
|
||
# check/process inputs ------------------------------------------------------- | ||
check_not_missing(formula) | ||
check_class(formula, cls = "formula") | ||
if (!missing(data)) check_class(data, cls = "data.frame") | ||
check_scalar(rho) | ||
check_class(rho, cls = "numeric") | ||
|
||
# assign method | ||
method <- dplyr::case_when( | ||
rho == 0 ~ "Log-rank test", | ||
rho == 1.5 ~ "Tarone-Ware test", | ||
rho == 1 ~ "Peto & Peto modification of Gehan-Wilcoxon test", | ||
.default = glue::glue("G-rho test (\U03C1 = {rho})") | ||
) |> | ||
as.character() | ||
|
||
# calculate survdiff() results ----------------------------------------------- | ||
lst_glance <- | ||
cards::eval_capture_conditions( | ||
survival::survdiff(formula = formula, data = data, rho = rho, ...) |> | ||
broom::glance() |> | ||
dplyr::mutate(method = .env$method) | ||
) | ||
|
||
# tidy results up in an ARD format ------------------------------------------- | ||
# extract variable names from formula | ||
variables <- stats::terms(formula) |> | ||
attr("term.labels") |> | ||
.strip_backticks() | ||
|
||
# if there was an error, return results early | ||
if (is.null(lst_glance[["result"]])) { | ||
# if no variables in formula, then return an error | ||
# otherwise, if we do have variable names, then we can construct an empty ARD which will be done below | ||
if (is_empty(variables)) { | ||
cli::cli_abort( | ||
message = | ||
c("There was an error in {.fun survival::survdiff}. See below:", | ||
"x" = lst_glance[["error"]] | ||
), | ||
call = get_cli_abort_call() | ||
) | ||
} | ||
} | ||
|
||
.variables_to_survdiff_ard( | ||
variables = variables, | ||
method = method, | ||
# styler: off | ||
stat_names = | ||
if (!is.null(lst_glance[["result"]])) names(lst_glance[["result"]]) | ||
else c("statistic", "df", "p.value", "method"), | ||
stats = | ||
if (!is.null(lst_glance[["result"]])) unname(as.list(lst_glance[["result"]])) | ||
else rep_along(c("statistic", "df", "p.value"), list(NULL)) |> c(list(method = method)) | ||
# styler: on | ||
) |> | ||
.add_survdiff_stat_labels() |> | ||
dplyr::mutate( | ||
context = "survival_survdiff", | ||
warning = lst_glance["warning"], | ||
error = lst_glance["error"], | ||
fmt_fn = map( | ||
.data$stat, | ||
function(x) { | ||
if (is.numeric(x)) return(1L) # styler: off | ||
NULL | ||
} | ||
) | ||
) |> | ||
cards::tidy_ard_column_order() %>% | ||
{structure(., class = c("card", class(.)))} # styler: off | ||
} | ||
|
||
.variables_to_survdiff_ard <- function(variables, | ||
method, | ||
stat_names, | ||
stats) { | ||
len <- length(variables) | ||
|
||
df_vars <- dplyr::tibble(!!!rev(variables)) |> | ||
set_names( | ||
ifelse( | ||
len > 1L, | ||
c(paste0("group_", rev(seq_len(len - 1L))), "variable"), | ||
"variable" | ||
) | ||
) | ||
|
||
dplyr::bind_cols( | ||
df_vars, | ||
dplyr::tibble( | ||
stat_name = .env$stat_names, | ||
stat = .env$stats | ||
) | ||
) | ||
} | ||
|
||
.add_survdiff_stat_labels <- function(x) { | ||
x |> | ||
dplyr::left_join( | ||
dplyr::tribble( | ||
~stat_name, ~stat_label, | ||
"statistic", "X^2 Statistic", | ||
"df", "Degrees of Freedom", | ||
"p.value", "p-value" | ||
), | ||
by = "stat_name" | ||
) |> | ||
dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) | ||
} | ||
|
||
.strip_backticks <- function(x) { | ||
ifelse( | ||
str_detect(x, "^`.*`$"), | ||
substr(x, 2, nchar(x) - 1), | ||
x | ||
) | ||
} |
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
Oops, something went wrong.