Skip to content

Commit

Permalink
Add warning for missing p-value in tabulate_rsp_subgroups() output (#…
Browse files Browse the repository at this point in the history
…1296)

Fixes #1289
  • Loading branch information
edelarua authored Sep 5, 2024
1 parent f598c3d commit 03d8639
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Reworking of `summarize_glm_count()` documentation and all its associated functions to better describe the results and the functions' purpose.
* Added the `.formats` argument to `tabulate_rsp_subgroups` and `tabulate_survival_subgroups` to allow users to specify formats.
* Added the `riskdiff` argument to `tabulate_rsp_subgroups` and `tabulate_survival_subgroups` to allow users to add a risk difference table column, and function `control_riskdiff` to specify settings for the risk difference column.
* Added warning to `tabulate_rsp_subgroups` when `pval` statistic is selected but `df` has not been correctly generated to add p-values to the output table.

### Bug Fixes
* Fixed a bug in `a_surv_time` that threw an error when split only has `"is_event"`.
Expand All @@ -15,7 +16,6 @@
* Fixed bug in `decorate_grob` that did not handle well empty strings or `NULL` values for title and footers.
* Fixed bug in `g_km` that caused an error when multiple records in the data had estimates at max time.


### Miscellaneous
* Began deprecation of the confusing functions `summary_formats` and `summary_labels`.

Expand Down
2 changes: 1 addition & 1 deletion R/argument_convention.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#' for more information.
#' @param lyt (`PreDataTableLayouts`)\cr layout that analyses will be added to.
#' @param method (`string` or `NULL`)\cr specifies the test used to calculate the p-value for the difference between
#' two proportions. For options, see [s_test_proportion_diff()]. Default is `NULL` so no test is performed.
#' two proportions. For options, see [test_proportion_diff()]. Default is `NULL` so no test is performed.
#' @param na.rm (`flag`)\cr whether `NA` values should be removed from `x` prior to analysis.
#' @param na_str (`string`)\cr string used to replace all `NA` or empty values in the output.
#' @param nested (`flag`)\cr whether this layout instruction should be applied within the existing layout structure _if
Expand Down
8 changes: 8 additions & 0 deletions R/response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ tabulate_rsp_subgroups <- function(lyt,
)) {
checkmate::assert_list(riskdiff, null.ok = TRUE)
checkmate::assert_true(all(c("n_tot", "or", "ci") %in% vars))
if ("pval" %in% vars && !"pval" %in% names(df$or)) {
warning(
'The "pval" statistic has been selected but is not present in "df" so it will not be included in the output ',
'table. To include the "pval" statistic, please specify a p-value test when generating "df" via ',
'the "method" argument to `extract_rsp_subgroups()`. If method = "cmh", strata must also be specified via the ',
'"variables" argument to `extract_rsp_subgroups()`.'
)
}

# Create "ci" column from "lcl" and "ucl"
df$or$ci <- combine_vectors(df$or$lcl, df$or$ucl)
Expand Down
2 changes: 1 addition & 1 deletion man/argument_convention.Rd

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

2 changes: 1 addition & 1 deletion man/d_rsp_subgroups_colvars.Rd

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

2 changes: 1 addition & 1 deletion man/extract_rsp_subgroups.Rd

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

2 changes: 1 addition & 1 deletion man/h_response_subgroups.Rd

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

21 changes: 21 additions & 0 deletions tests/testthat/test-response_subgroups.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,24 @@ testthat::test_that("tabulate_rsp_subgroups riskdiff argument works as expected"
res <- testthat::expect_silent(result)
testthat::expect_snapshot(res)
})

testthat::test_that("tabulate_rsp_subgroups pval statistic warning works as expected", {
adrs <- adrs_200

df <- extract_rsp_subgroups(
variables = list(rsp = "rsp", arm = "ARM", subgroups = c("SEX", "STRATA2")),
data = adrs,
method = NULL,
conf_level = 0.95
)

# warning when no pval in df
expect_warning(
basic_table() %>%
tabulate_rsp_subgroups(
df = df,
vars = c("n", "prop", "n_tot", "or", "ci", "pval")
),
"please specify a p-value test"
)
})

0 comments on commit 03d8639

Please sign in to comment.