From 5536c319bbf9d8a2a2639b763c23c5954389e69c Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 30 Jan 2025 15:40:59 -0500 Subject: [PATCH 1/4] Add pct argument to risk diff processing --- R/response_subgroups.R | 3 ++- R/survival_duration_subgroups.R | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/response_subgroups.R b/R/response_subgroups.R index d80924d4e4..7185faf393 100644 --- a/R/response_subgroups.R +++ b/R/response_subgroups.R @@ -276,7 +276,8 @@ tabulate_rsp_subgroups <- function(lyt, x = as.list(.data[[arm_cols[1]]]), y = as.list(.data[[arm_cols[2]]]), N_x = .data[[arm_cols[3]]], - N_y = .data[[arm_cols[4]]] + N_y = .data[[arm_cols[4]]], + pct = riskdiff$pct ) ) %>% dplyr::select(-dplyr::all_of(arm_cols)) diff --git a/R/survival_duration_subgroups.R b/R/survival_duration_subgroups.R index eab7e46b9b..ba6a99e9a7 100644 --- a/R/survival_duration_subgroups.R +++ b/R/survival_duration_subgroups.R @@ -284,7 +284,8 @@ tabulate_survival_subgroups <- function(lyt, x = as.list(.data[[arm_cols[1]]]), y = as.list(.data[[arm_cols[2]]]), N_x = .data[[arm_cols[3]]], - N_y = .data[[arm_cols[4]]] + N_y = .data[[arm_cols[4]]], + pct = riskdiff$pct ) ) %>% dplyr::select(-dplyr::all_of(arm_cols)) From 293e94717462c8d2806762caa07f8bc876c4aa26 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 30 Jan 2025 15:46:56 -0500 Subject: [PATCH 2/4] Add tests --- tests/testthat/_snaps/response_subgroups.md | 17 +++++++++++++++++ .../_snaps/survival_duration_subgroups.md | 18 ++++++++++++++++++ tests/testthat/test-response_subgroups.R | 16 ++++++++++++++++ .../test-survival_duration_subgroups.R | 14 ++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/tests/testthat/_snaps/response_subgroups.md b/tests/testthat/_snaps/response_subgroups.md index 5b019e9718..4c056c7403 100644 --- a/tests/testthat/_snaps/response_subgroups.md +++ b/tests/testthat/_snaps/response_subgroups.md @@ -288,3 +288,20 @@ S1 73 34 70.6% 39 87.2% 2.83 (0.86, 9.35) 0.0801 -16.6 (-35.2 - 2.0) S2 69 39 66.7% 30 83.3% 2.50 (0.78, 8.04) 0.1181 -16.7 (-36.6 - 3.3) +--- + + Code + res + Output + B: Placebo A: Drug X + Prop. Diff + Baseline Risk Factors Total n n Response (%) n Response (%) Odds Ratio 95% CI p-value (Chi-Squared Test) (95% CI) + ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— + All Patients 142 73 68.5% 69 85.5% 2.71 (1.18, 6.24) 0.0164 -0.2 (-0.3 - -0.0) + Sex + F 78 40 62.5% 38 94.7% 10.80 (2.27, 51.45) 0.0006 -0.3 (-0.5 - -0.2) + M 64 33 75.8% 31 74.2% 0.92 (0.30, 2.85) 0.8852 0.0 (-0.2 - 0.2) + Stratification Factor 2 + S1 73 34 70.6% 39 87.2% 2.83 (0.86, 9.35) 0.0801 -0.2 (-0.4 - 0.0) + S2 69 39 66.7% 30 83.3% 2.50 (0.78, 8.04) 0.1181 -0.2 (-0.4 - 0.0) + diff --git a/tests/testthat/_snaps/survival_duration_subgroups.md b/tests/testthat/_snaps/survival_duration_subgroups.md index 8bdd934c88..7c07ab4a93 100644 --- a/tests/testthat/_snaps/survival_duration_subgroups.md +++ b/tests/testthat/_snaps/survival_duration_subgroups.md @@ -275,3 +275,21 @@ MEDIUM 31 14 731.8 17 964.2 0.77 (0.36, 1.61) -4.5 (-31.6 - 22.5) HIGH 34 22 654.8 12 1016.3 0.67 (0.33, 1.36) 14.0 (-11.7 - 39.7) +--- + + Code + res + Output + B: Placebo A: Drug X + Prop. Diff + Baseline Risk Factors Total Events Events Median (DAYS) Events Median (DAYS) Hazard Ratio 95% Wald CI (95% CI) + ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— + All Patients 101 57 727.8 44 974.6 0.71 (0.48, 1.06) 0.1 (-0.0 - 0.3) + Sex + F 55 31 599.2 24 1016.3 0.56 (0.32, 0.96) 0.1 (-0.1 - 0.3) + M 46 26 888.5 20 974.6 0.91 (0.50, 1.65) 0.1 (-0.1 - 0.4) + Continuous Level Biomarker 2 + LOW 36 21 735.5 15 974.6 0.76 (0.39, 1.51) 0.3 (0.1 - 0.5) + MEDIUM 31 14 731.8 17 964.2 0.77 (0.36, 1.61) -0.0 (-0.3 - 0.2) + HIGH 34 22 654.8 12 1016.3 0.67 (0.33, 1.36) 0.1 (-0.1 - 0.4) + diff --git a/tests/testthat/test-response_subgroups.R b/tests/testthat/test-response_subgroups.R index 7422d7c64e..695f24f704 100644 --- a/tests/testthat/test-response_subgroups.R +++ b/tests/testthat/test-response_subgroups.R @@ -306,6 +306,22 @@ testthat::test_that("tabulate_rsp_subgroups riskdiff argument works as expected" res <- testthat::expect_silent(result) testthat::expect_snapshot(res) + + # pct works + result <- basic_table() %>% + tabulate_rsp_subgroups( + df = df, + vars = c("n", "prop", "n_tot", "or", "ci", "pval"), + riskdiff = control_riskdiff( + arm_x = levels(df$prop$arm)[1], + arm_y = levels(df$prop$arm)[2], + col_label = "Prop. Diff\n(95% CI)", + pct = FALSE + ) + ) + + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) }) testthat::test_that("tabulate_rsp_subgroups pval statistic warning works as expected", { diff --git a/tests/testthat/test-survival_duration_subgroups.R b/tests/testthat/test-survival_duration_subgroups.R index f82064469d..d2195b6cc3 100644 --- a/tests/testthat/test-survival_duration_subgroups.R +++ b/tests/testthat/test-survival_duration_subgroups.R @@ -286,4 +286,18 @@ testthat::test_that("tabulate_survival_subgroups riskdiff argument works as expe res <- testthat::expect_silent(result) testthat::expect_snapshot(res) + + # pct works + result <- basic_table() %>% + tabulate_survival_subgroups( + df, + time_unit = adtte$AVALU[1], + riskdiff = control_riskdiff( + col_label = "Prop. Diff\n(95% CI)", + pct = FALSE + ) + ) + + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) }) From 9c63cf61ce91fff18138f9799ddc1eccb2fcbbff Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Thu, 30 Jan 2025 15:47:02 -0500 Subject: [PATCH 3/4] Update NEWS --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 785b416b8d..1c09e0563a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ ### Bug Fixes * Fixed bug in `a_count_patients_with_flags()` preventing select custom label and indentation specification formats from being applied. +* Fixed bug in `tabulate_rsp_subgroups` and `tabulate_survival_subgroups` preventing the `pct` option from having an effect when adding a risk difference column. # tern 0.9.7 From 17d84c50f26fbcd9c4f8ea5a8dd6445a3c04c079 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Fri, 31 Jan 2025 10:55:25 -0500 Subject: [PATCH 4/4] Simplify tests --- tests/testthat/_snaps/response_subgroups.md | 17 ----------------- .../_snaps/survival_duration_subgroups.md | 18 ------------------ tests/testthat/test-response_subgroups.R | 9 +++++---- .../test-survival_duration_subgroups.R | 13 ++++++------- 4 files changed, 11 insertions(+), 46 deletions(-) diff --git a/tests/testthat/_snaps/response_subgroups.md b/tests/testthat/_snaps/response_subgroups.md index 4c056c7403..5b019e9718 100644 --- a/tests/testthat/_snaps/response_subgroups.md +++ b/tests/testthat/_snaps/response_subgroups.md @@ -288,20 +288,3 @@ S1 73 34 70.6% 39 87.2% 2.83 (0.86, 9.35) 0.0801 -16.6 (-35.2 - 2.0) S2 69 39 66.7% 30 83.3% 2.50 (0.78, 8.04) 0.1181 -16.7 (-36.6 - 3.3) ---- - - Code - res - Output - B: Placebo A: Drug X - Prop. Diff - Baseline Risk Factors Total n n Response (%) n Response (%) Odds Ratio 95% CI p-value (Chi-Squared Test) (95% CI) - ———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— - All Patients 142 73 68.5% 69 85.5% 2.71 (1.18, 6.24) 0.0164 -0.2 (-0.3 - -0.0) - Sex - F 78 40 62.5% 38 94.7% 10.80 (2.27, 51.45) 0.0006 -0.3 (-0.5 - -0.2) - M 64 33 75.8% 31 74.2% 0.92 (0.30, 2.85) 0.8852 0.0 (-0.2 - 0.2) - Stratification Factor 2 - S1 73 34 70.6% 39 87.2% 2.83 (0.86, 9.35) 0.0801 -0.2 (-0.4 - 0.0) - S2 69 39 66.7% 30 83.3% 2.50 (0.78, 8.04) 0.1181 -0.2 (-0.4 - 0.0) - diff --git a/tests/testthat/_snaps/survival_duration_subgroups.md b/tests/testthat/_snaps/survival_duration_subgroups.md index 7c07ab4a93..8bdd934c88 100644 --- a/tests/testthat/_snaps/survival_duration_subgroups.md +++ b/tests/testthat/_snaps/survival_duration_subgroups.md @@ -275,21 +275,3 @@ MEDIUM 31 14 731.8 17 964.2 0.77 (0.36, 1.61) -4.5 (-31.6 - 22.5) HIGH 34 22 654.8 12 1016.3 0.67 (0.33, 1.36) 14.0 (-11.7 - 39.7) ---- - - Code - res - Output - B: Placebo A: Drug X - Prop. Diff - Baseline Risk Factors Total Events Events Median (DAYS) Events Median (DAYS) Hazard Ratio 95% Wald CI (95% CI) - ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— - All Patients 101 57 727.8 44 974.6 0.71 (0.48, 1.06) 0.1 (-0.0 - 0.3) - Sex - F 55 31 599.2 24 1016.3 0.56 (0.32, 0.96) 0.1 (-0.1 - 0.3) - M 46 26 888.5 20 974.6 0.91 (0.50, 1.65) 0.1 (-0.1 - 0.4) - Continuous Level Biomarker 2 - LOW 36 21 735.5 15 974.6 0.76 (0.39, 1.51) 0.3 (0.1 - 0.5) - MEDIUM 31 14 731.8 17 964.2 0.77 (0.36, 1.61) -0.0 (-0.3 - 0.2) - HIGH 34 22 654.8 12 1016.3 0.67 (0.33, 1.36) 0.1 (-0.1 - 0.4) - diff --git a/tests/testthat/test-response_subgroups.R b/tests/testthat/test-response_subgroups.R index 695f24f704..268d966e54 100644 --- a/tests/testthat/test-response_subgroups.R +++ b/tests/testthat/test-response_subgroups.R @@ -308,20 +308,21 @@ testthat::test_that("tabulate_rsp_subgroups riskdiff argument works as expected" testthat::expect_snapshot(res) # pct works - result <- basic_table() %>% + result2 <- basic_table() %>% tabulate_rsp_subgroups( df = df, vars = c("n", "prop", "n_tot", "or", "ci", "pval"), riskdiff = control_riskdiff( arm_x = levels(df$prop$arm)[1], arm_y = levels(df$prop$arm)[2], - col_label = "Prop. Diff\n(95% CI)", pct = FALSE ) ) - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) + testthat::expect_equal( + cell_values(result2)[[1]][[9]], + cell_values(result)[[1]][[9]] / 100 + ) }) testthat::test_that("tabulate_rsp_subgroups pval statistic warning works as expected", { diff --git a/tests/testthat/test-survival_duration_subgroups.R b/tests/testthat/test-survival_duration_subgroups.R index d2195b6cc3..7c63ea6f1a 100644 --- a/tests/testthat/test-survival_duration_subgroups.R +++ b/tests/testthat/test-survival_duration_subgroups.R @@ -288,16 +288,15 @@ testthat::test_that("tabulate_survival_subgroups riskdiff argument works as expe testthat::expect_snapshot(res) # pct works - result <- basic_table() %>% + result2 <- basic_table() %>% tabulate_survival_subgroups( df, time_unit = adtte$AVALU[1], - riskdiff = control_riskdiff( - col_label = "Prop. Diff\n(95% CI)", - pct = FALSE - ) + riskdiff = control_riskdiff(pct = FALSE) ) - res <- testthat::expect_silent(result) - testthat::expect_snapshot(res) + testthat::expect_equal( + cell_values(result2)[[1]][[8]], + cell_values(result)[[1]][[8]] / 100 + ) })