Skip to content

[821] Feature Request: Add weights option to ancova #1412

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

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 15 additions & 3 deletions R/summarize_ancova.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand All @@ -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"))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -117,8 +120,15 @@ 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,
Expand Down Expand Up @@ -300,6 +310,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,
Expand All @@ -323,6 +334,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,
...
)

Expand Down
10 changes: 9 additions & 1 deletion man/h_ancova.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/summarize_ancova.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.