From e2031f3643e35b03ace3a7fb62314462a22dcd1f Mon Sep 17 00:00:00 2001 From: Andrii Yurovskyi Date: Sat, 29 Mar 2025 10:09:24 +0100 Subject: [PATCH 1/2] Added weights_emmeans argument to summarize_ancova() --- NEWS.md | 1 + R/summarize_ancova.R | 12 +++++++++--- man/h_ancova.Rd | 10 +++++++++- man/summarize_ancova.Rd | 4 ++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index cba52c1596..903328659a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ * Refactored `afun_riskdiff()`, `count_occurrences()`, `count_occurrences_by_grade()`, `count_patients_with_event()`, `count_patients_with_flags()`, `count_values()`, `estimate_incidence_rate()`, `h_tab_one_biomarker()`, `summarize_change()`, `summarize_colvars()`, `summarize_patients_exposure_in_cols()`, `survival_time()`, `tabulate_rsp_subgroups()`, `tabulate_survival_subgroups()`, `tabulate_rsp_biomarkers()`, and `tabulate_survival_biomarkers()` to align with new analysis function style. * Converted `as_factor_keep_attributes()` to an exported function. * Added `denom` parameter to `estimate_proportion()`. +* Added `weights_emmeans` argument to `summarize_ancova()`. ### Bug Fixes * Fixed bug in `a_count_patients_with_flags()` preventing select custom label and indentation specification formats from being applied. diff --git a/R/summarize_ancova.R b/R/summarize_ancova.R index 5fdc894ec8..62bd6fd20a 100644 --- a/R/summarize_ancova.R +++ b/R/summarize_ancova.R @@ -38,6 +38,7 @@ NULL #' interaction terms indicated by `"X1 * X2"`. #' @param interaction_item (`string` or `NULL`)\cr name of the variable that should have interactions #' with arm. if the interaction is not needed, the default option is `NULL`. +#' @param weights_emmeans (`string` or `NULL`)\cr argument from [emmeans::emmeans()] #' #' @return The summary of a linear model. #' @@ -52,7 +53,8 @@ NULL h_ancova <- function(.var, .df_row, variables, - interaction_item = NULL) { + interaction_item = NULL, + weights_emmeans = NULL) { checkmate::assert_string(.var) checkmate::assert_list(variables) checkmate::assert_subset(names(variables), c("arm", "covariates")) @@ -88,7 +90,8 @@ h_ancova <- function(.var, # Specify here the group variable over which EMM are desired. specs = specs, # Pass the data again so that the factor levels of the arm variable can be inferred. - data = .df_row + data = .df_row, + weights = weights_emmeans ) emmeans_fit @@ -117,8 +120,9 @@ s_ancova <- function(df, conf_level, interaction_y = FALSE, interaction_item = NULL, + weights_emmeans = NULL, ...) { - emmeans_fit <- h_ancova(.var = .var, variables = variables, .df_row = .df_row, interaction_item = interaction_item) + emmeans_fit <- h_ancova(.var = .var, variables = variables, .df_row = .df_row, interaction_item = interaction_item, weights_emmeans = weights_emmeans) sum_fit <- summary( emmeans_fit, @@ -300,6 +304,7 @@ summarize_ancova <- function(lyt, conf_level, interaction_y = FALSE, interaction_item = NULL, + weights_emmeans = NULL, var_labels, na_str = default_na_str(), nested = TRUE, @@ -323,6 +328,7 @@ summarize_ancova <- function(lyt, extra_args, variables = list(variables), conf_level = list(conf_level), interaction_y = list(interaction_y), interaction_item = list(interaction_item), + weights_emmeans = weights_emmeans, ... ) diff --git a/man/h_ancova.Rd b/man/h_ancova.Rd index a338900cb6..4695953ece 100644 --- a/man/h_ancova.Rd +++ b/man/h_ancova.Rd @@ -4,7 +4,13 @@ \alias{h_ancova} \title{Helper function to return results of a linear model} \usage{ -h_ancova(.var, .df_row, variables, interaction_item = NULL) +h_ancova( + .var, + .df_row, + variables, + interaction_item = NULL, + weights_emmeans = NULL +) } \arguments{ \item{.var}{(\code{string})\cr single variable name that is passed by \code{rtables} when requested @@ -22,6 +28,8 @@ interaction terms indicated by \code{"X1 * X2"}. \item{interaction_item}{(\code{string} or \code{NULL})\cr name of the variable that should have interactions with arm. if the interaction is not needed, the default option is \code{NULL}.} + +\item{weights_emmeans}{(\code{string} or \code{NULL})\cr argument from \code{\link[emmeans:emmeans]{emmeans::emmeans()}}} } \value{ The summary of a linear model. diff --git a/man/summarize_ancova.Rd b/man/summarize_ancova.Rd index b9aa570c26..40b8f58f2f 100644 --- a/man/summarize_ancova.Rd +++ b/man/summarize_ancova.Rd @@ -13,6 +13,7 @@ summarize_ancova( conf_level, interaction_y = FALSE, interaction_item = NULL, + weights_emmeans = NULL, var_labels, na_str = default_na_str(), nested = TRUE, @@ -36,6 +37,7 @@ s_ancova( conf_level, interaction_y = FALSE, interaction_item = NULL, + weights_emmeans = NULL, ... ) @@ -70,6 +72,8 @@ used to select the specific ANCOVA results. if the interaction is not needed, th \item{interaction_item}{(\code{string} or \code{NULL})\cr name of the variable that should have interactions with arm. if the interaction is not needed, the default option is \code{NULL}.} +\item{weights_emmeans}{(\code{string} or \code{NULL})\cr argument from \code{\link[emmeans:emmeans]{emmeans::emmeans()}}} + \item{var_labels}{(\code{character})\cr variable labels.} \item{na_str}{(\code{string})\cr string used to replace all \code{NA} or empty values in the output.} From 55ce0575eedf21e17d26c8750164d922a7a5310a Mon Sep 17 00:00:00 2001 From: Andrii Yurovskyi Date: Sun, 30 Mar 2025 11:23:43 +0200 Subject: [PATCH 2/2] Fixed lintr issue --- R/summarize_ancova.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/summarize_ancova.R b/R/summarize_ancova.R index 62bd6fd20a..f740c43e46 100644 --- a/R/summarize_ancova.R +++ b/R/summarize_ancova.R @@ -122,7 +122,13 @@ s_ancova <- function(df, interaction_item = NULL, weights_emmeans = NULL, ...) { - emmeans_fit <- h_ancova(.var = .var, variables = variables, .df_row = .df_row, interaction_item = interaction_item, weights_emmeans = weights_emmeans) + emmeans_fit <- h_ancova( + .var = .var, + variables = variables, + .df_row = .df_row, + interaction_item = interaction_item, + weights_emmeans = weights_emmeans + ) sum_fit <- summary( emmeans_fit,