From a411f2f97f6eb7cc50d600bf316b5637ff808fdb Mon Sep 17 00:00:00 2001 From: Joe Zhu Date: Tue, 31 Oct 2023 22:06:13 +0800 Subject: [PATCH] update scda.test snaps allowing key column to change (#67) Signed-off-by: Davide Garolini Co-authored-by: Davide Garolini Co-authored-by: Melkiades Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- DESCRIPTION | 10 ++-- tests/testthat/_snaps/table_ttet01.md | 37 ++++++++++++++ tests/testthat/test-table_aovt01.R | 4 +- tests/testthat/test-table_aovt02.R | 2 +- tests/testthat/test-table_aovt03.R | 2 +- tests/testthat/test-table_cmht01.R | 4 +- tests/testthat/test-table_dort01.R | 8 +-- tests/testthat/test-table_lbt11.R | 6 +-- tests/testthat/test-table_lbt11_bl.R | 6 +-- tests/testthat/test-table_ratet01.R | 5 +- tests/testthat/test-table_rmpt06.R | 4 +- tests/testthat/test-table_rspt01.R | 12 ++--- tests/testthat/test-table_ttet01.R | 73 ++++++++++++++++++++++++--- 13 files changed, 137 insertions(+), 36 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3fa3639f..0dc32efd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,11 +21,11 @@ License: Apache License 2.0 | file LICENSE URL: https://github.com/insightsengineering/scda.test/ BugReports: https://github.com/insightsengineering/scda.test/issues Depends: - formatters (>= 0.5.3.9002), - R (>= 3.6), - rlistings (>= 0.2.5.9002), - rtables (>= 0.6.4.9003), - tern (>= 0.9.1.9005) + formatters (>= 0.5.4.9002), + R (>= 4.2), + rlistings (>= 0.2.6.9005), + rtables (>= 0.6.5.9004), + tern (>= 0.9.2.9001) Imports: scda (>= 0.1.6.9012), scda.2022 (>= 0.1.5.9002) diff --git a/tests/testthat/_snaps/table_ttet01.md b/tests/testthat/_snaps/table_ttet01.md index 63d44b13..7a1bfdb0 100644 --- a/tests/testthat/_snaps/table_ttet01.md +++ b/tests/testthat/_snaps/table_ttet01.md @@ -35,6 +35,43 @@ 95% CI (-11.86, 11.86) (-20.95, 2.97) p-value (Z-test) 1.0000 0.1406 +# TTET01 default variant with Placebo arm + + Code + res + Output + A: Drug X C: Combination B: Placebo + (N=134) (N=132) (N=134) + ——————————————————————————————————————————————————————————————————————————————————— + Patients with event (%) 58 (43.3%) 69 (52.3%) 58 (43.3%) + Earliest contributing event + Death 58 69 58 + Patients without event (%) 76 (56.7%) 63 (47.7%) 76 (56.7%) + Time to Event (Months) + Median NA 9.4 NA + 95% CI (9.3, NA) (7.6, NA) (9.4, NA) + 25% and 75%-ile 5.6, NA 5.0, NA 5.6, NA + Range (censored) 9.9 to 16.4 9.9 to 16.3 9.9 to 16.3 + Range (event) 0.5 to 9.6 0.5 to 9.8 0.9 to 9.6 + Unstratified Analysis + p-value (log-rank) 0.9998 0.1480 + Hazard Ratio 1.00 1.29 + 95% CI (0.69, 1.44) (0.91, 1.83) + 6 Months + Patients remaining at risk 97 90 97 + Event Free Rate (%) 72.39 68.18 72.39 + 95% CI (64.82, 79.96) (60.24, 76.13) (64.82, 79.96) + Difference in Event Free Rate 0.00 -4.21 + 95% CI (-10.71, 10.71) (-15.18, 6.77) + p-value (Z-test) 1.0000 0.4525 + 12 Months + Patients remaining at risk 49 37 48 + Event Free Rate (%) 56.72 47.73 56.72 + 95% CI (48.33, 65.11) (39.21, 56.25) (48.33, 65.11) + Difference in Event Free Rate 0.00 -8.99 + 95% CI (-11.86, 11.86) (-20.95, 2.97) + p-value (Z-test) 1.0000 0.1406 + # TTET01 variant 2: selecting sections to display Code diff --git a/tests/testthat/test-table_aovt01.R b/tests/testthat/test-table_aovt01.R index eba926ac..cf968211 100644 --- a/tests/testthat/test-table_aovt01.R +++ b/tests/testthat/test-table_aovt01.R @@ -12,7 +12,7 @@ testthat::test_that("AOVT01 variant with single endpoint is produced correctly", dplyr::mutate(CHG = ifelse(BMEASIFL == "Y", CHG, NA)) # only analyze evaluable population result <- basic_table() %>% - split_cols_by("ARMCD", ref_group = "ARM A") %>% + split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% add_colcounts() %>% summarize_ancova( vars = "CHG", @@ -38,7 +38,7 @@ testthat::test_that("AOVT01 variant with multiple endpoints is produced correctl n_per_arm <- table(adsl$ARM) result <- basic_table() %>% - split_cols_by("ARMCD", ref_group = "ARM A") %>% + split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% add_colcounts() %>% split_rows_by("PARAMCD") %>% summarize_ancova( diff --git a/tests/testthat/test-table_aovt02.R b/tests/testthat/test-table_aovt02.R index e1c4523d..e88be29d 100644 --- a/tests/testthat/test-table_aovt02.R +++ b/tests/testthat/test-table_aovt02.R @@ -14,7 +14,7 @@ adqs_single <- adqs %>% testthat::test_that("AOVT02 is produced correctly", { lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARMCD", ref_group = "ARM A") %>% + split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% append_varlabels(adqs_single, "PARAM") %>% summarize_ancova( vars = "CHG", diff --git a/tests/testthat/test-table_aovt03.R b/tests/testthat/test-table_aovt03.R index 5a363a6b..ce76d7c9 100644 --- a/tests/testthat/test-table_aovt03.R +++ b/tests/testthat/test-table_aovt03.R @@ -9,7 +9,7 @@ adqs_in <- adqs %>% testthat::test_that("AOVT03 is produced correctly", { result <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARMCD", ref_group = "ARM A") %>% + split_cols_by("ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% split_rows_by("PARAM", split_fun = drop_split_levels) %>% summarize_ancova( vars = "CHG", diff --git a/tests/testthat/test-table_cmht01.R b/tests/testthat/test-table_cmht01.R index a0ae3a65..2e2ccaeb 100644 --- a/tests/testthat/test-table_cmht01.R +++ b/tests/testthat/test-table_cmht01.R @@ -14,7 +14,7 @@ testthat::test_that("CMHT01 variant 1 is produced correctly", { mutate(strata = interaction(STRATA1, STRATA2, drop = TRUE)) lyt_01 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X") %>% + split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% estimate_proportion(vars = "is_rsp", table_names = "est_prop") %>% estimate_proportion_diff( var_labels = "Unstratified Analysis", @@ -68,7 +68,7 @@ testthat::test_that("CMHT01 variant 2 is produced correctly", { split_fun <- drop_split_levels lyt_02 <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X") %>% + split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% split_rows_by( var = "PARAM", split_fun = split_fun, diff --git a/tests/testthat/test-table_dort01.R b/tests/testthat/test-table_dort01.R index 49df6e70..6b5a98a4 100644 --- a/tests/testthat/test-table_dort01.R +++ b/tests/testthat/test-table_dort01.R @@ -27,7 +27,7 @@ testthat::test_that("DORT01 variant 1 is produced correctly", { adtte <- adtte_local result <- basic_table() %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X") %>% + split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% count_values( vars = "USUBJID", @@ -82,7 +82,7 @@ testthat::test_that("DORT01 variant 2 (selecting sectons) is produced correctly" adtte <- adtte_local result <- basic_table() %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X") %>% + split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% count_values( vars = "USUBJID", @@ -138,7 +138,7 @@ testthat::test_that("DORT01 variant 3 (modifying conftype and alpha level) is pr adtte <- adtte_local result <- basic_table() %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X") %>% + split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% count_values( vars = "USUBJID", @@ -194,7 +194,7 @@ testthat::test_that("DORT01 variant 4 (modifying time point for the “xx durati adtte <- adtte_local result <- basic_table() %>% - split_cols_by(var = "ARM", ref_group = "A: Drug X") %>% + split_cols_by(var = "ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% count_values( vars = "USUBJID", diff --git a/tests/testthat/test-table_lbt11.R b/tests/testthat/test-table_lbt11.R index 250efad8..ff30c192 100644 --- a/tests/testthat/test-table_lbt11.R +++ b/tests/testthat/test-table_lbt11.R @@ -38,7 +38,7 @@ anl <- adsaftte %>% testthat::test_that("LBT11 variant 1 works as expected", { lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", @@ -62,7 +62,7 @@ testthat::test_that("LBT11 variant 1 works as expected", { testthat::test_that("LBT11 variant 2 works as expected", { lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", @@ -81,7 +81,7 @@ testthat::test_that("LBT11 variant 3 works as expected", { strata <- c("RACE", "SEX") lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", diff --git a/tests/testthat/test-table_lbt11_bl.R b/tests/testthat/test-table_lbt11_bl.R index acea8d9d..dbd19b28 100644 --- a/tests/testthat/test-table_lbt11_bl.R +++ b/tests/testthat/test-table_lbt11_bl.R @@ -38,7 +38,7 @@ anl <- adsaftte %>% testthat::test_that("LBT11_BL variant 1 works as expected", { lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", @@ -62,7 +62,7 @@ testthat::test_that("LBT11_BL variant 1 works as expected", { testthat::test_that("LBT11_BL variant 2 works as expected", { lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", @@ -81,7 +81,7 @@ testthat::test_that("LBT11_BL variant 3 works as expected", { strata <- c("RACE", "SEX") lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", diff --git a/tests/testthat/test-table_ratet01.R b/tests/testthat/test-table_ratet01.R index 3129420a..a39dd314 100644 --- a/tests/testthat/test-table_ratet01.R +++ b/tests/testthat/test-table_ratet01.R @@ -6,7 +6,10 @@ anl <- df_explicit_na(anl) testthat::test_that("RATET01 is produced correctly", { lyt <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ARM", ref_group = "B: Placebo") %>% + split_cols_by("ARM", + ref_group = "B: Placebo", + split_fun = ref_group_position("first") + ) %>% analyze_vars( "AVAL_f", var_labels = "Number of exacerbations per patient", diff --git a/tests/testthat/test-table_rmpt06.R b/tests/testthat/test-table_rmpt06.R index 5becebcb..6ef800a9 100644 --- a/tests/testthat/test-table_rmpt06.R +++ b/tests/testthat/test-table_rmpt06.R @@ -150,7 +150,7 @@ testthat::test_that("RMPT06 variant 2 is produced correctly", { testthat::test_that("RMPT06 variant 3 is produced correctly", { lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM", ref_group = "A: Drug X") %>% + split_cols_by("ACTARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% estimate_proportion( vars = "AEFL", method = "clopper-pearson", @@ -213,7 +213,7 @@ testthat::test_that("RMPT06 variant 3 is produced correctly", { testthat::test_that("RMPT06 variant 4 is produced correctly", { lyt_adsl <- basic_table(show_colcounts = TRUE) %>% - split_cols_by("ACTARM", ref_group = "A: Drug X") %>% + split_cols_by("ACTARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% estimate_proportion( vars = "AEFL", conf_level = 0.90, diff --git a/tests/testthat/test-table_rspt01.R b/tests/testthat/test-table_rspt01.R index 5bc5c88b..c1eb3ef3 100644 --- a/tests/testthat/test-table_rspt01.R +++ b/tests/testthat/test-table_rspt01.R @@ -17,7 +17,7 @@ adrs <- adrs %>% testthat::test_that("RSPT01: 1. Best Overall Response", { l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% add_colcounts() %>% estimate_proportion( vars = "is_rsp", @@ -48,7 +48,7 @@ testthat::test_that("RSPT01: 1. Best Overall Response", { testthat::test_that("RSPT01: 2. Best Overall Response (selecting sections to display)", { l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% add_colcounts() %>% estimate_proportion( vars = "is_rsp", @@ -77,7 +77,7 @@ testthat::test_that("RSPT01: 3. Best Overall Response (modifying settings)", { conf_level <- 0.90 method_prop <- "clopper-pearson" l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% add_colcounts() %>% estimate_proportion( vars = "is_rsp", @@ -118,7 +118,7 @@ testthat::test_that("RSPT01: 3. Best Overall Response (modifying settings)", { testthat::test_that("RSPT01: 4. Best Overall Response (with stratified analysis)", { l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% add_colcounts() %>% estimate_proportion( vars = "is_rsp", @@ -168,7 +168,7 @@ testthat::test_that("RSPT01: 4. Best Overall Response (with stratified analysis) testthat::test_that("RSPT01: 5. Best Overall Response (modifying the definition of overall response)", { l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% add_colcounts() %>% estimate_proportion( vars = "is_rsp", @@ -219,7 +219,7 @@ testthat::test_that("RSPT01: 6. Best Overall Response (define new sections to di ) l <- basic_table() %>% - split_cols_by(var = "ARMCD", ref_group = "ARM A") %>% + split_cols_by(var = "ARMCD", ref_group = "ARM A", split_fun = ref_group_position("first")) %>% add_colcounts() %>% estimate_proportion( vars = "is_rsp", diff --git a/tests/testthat/test-table_ttet01.R b/tests/testthat/test-table_ttet01.R index 162c627b..f05bf269 100644 --- a/tests/testthat/test-table_ttet01.R +++ b/tests/testthat/test-table_ttet01.R @@ -27,7 +27,68 @@ testthat::test_that("TTET01 default variant is produced correctly", { preproc_adtte() l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X") %>% + split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% + add_colcounts() %>% + analyze_vars( + vars = "is_event", + .stats = "count_fraction", + .labels = c(count_fraction = "Patients with event (%)") + ) %>% + split_rows_by( + "EVNT1", + split_label = "Earliest contributing event", + split_fun = keep_split_levels("Patients with event (%)"), + label_pos = "visible", + child_labels = "hidden", + indent_mod = 1L, + ) %>% + split_rows_by("EVNTDESC", split_fun = drop_split_levels) %>% + summarize_row_groups(format = "xx") %>% + analyze_vars( + vars = "is_not_event", + .stats = "count_fraction", + .labels = c(count_fraction = "Patients without event (%)"), + nested = FALSE, + show_labels = "hidden" + ) %>% + surv_time( + vars = "AVAL", + var_labels = "Time to Event (Months)", + is_event = "is_event", + table_names = "time_to_event" + ) %>% + coxph_pairwise( + vars = "AVAL", + is_event = "is_event", + var_labels = c("Unstratified Analysis"), + control = control_coxph(pval_method = "log-rank"), + table_names = "coxph_unstratified" + ) %>% + surv_timepoint( + vars = "AVAL", + var_labels = "Months", + time_point = c(6, 12), + is_event = "is_event", + method = "both", + control = control_surv_timepoint() + ) + + result <- build_table(l, df = adtte, alt_counts_df = adsl) + + res <- testthat::expect_silent(result) + testthat::expect_snapshot(res) +}) + + +testthat::test_that("TTET01 default variant with Placebo arm", { + adtte <- adtte %>% + preproc_adtte() + + l <- basic_table() %>% + split_cols_by("ARM", + ref_group = "B: Placebo", + split_fun = ref_group_position("last") + ) %>% add_colcounts() %>% analyze_vars( vars = "is_event", @@ -84,7 +145,7 @@ testthat::test_that("TTET01 variant 2: selecting sections to display", { preproc_adtte() l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X") %>% + split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% analyze_vars( vars = "is_event", @@ -129,7 +190,7 @@ testthat::test_that("TTET01 variant 3: modifying analysis details like conftype, preproc_adtte() l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X") %>% + split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% analyze_vars( vars = "is_event", @@ -195,7 +256,7 @@ testthat::test_that("TTET01 variant 4: with stratified analysis", { preproc_adtte() l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X") %>% + split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% analyze_vars( vars = "is_event", @@ -256,7 +317,7 @@ testthat::test_that("TTET01 variant 5: modifying time point", { preproc_adtte() l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X") %>% + split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% analyze_vars( vars = "is_event", @@ -311,7 +372,7 @@ testthat::test_that("TTET01 variant 6: requesting more than one p-value", { preproc_adtte() l <- basic_table() %>% - split_cols_by("ARM", ref_group = "A: Drug X") %>% + split_cols_by("ARM", ref_group = "A: Drug X", split_fun = ref_group_position("first")) %>% add_colcounts() %>% analyze_vars( vars = "is_event",