diff --git a/tests/testthat/_snaps/table_lbt11.md b/tests/testthat/_snaps/table_lbt11.md index 2322231..cd17b64 100644 --- a/tests/testthat/_snaps/table_lbt11.md +++ b/tests/testthat/_snaps/table_lbt11.md @@ -3,25 +3,25 @@ Code res Output - ARM A ARM B ARM C - (N=134) (N=134) (N=132) - ——————————————————————————————————————————————————————————————————————————————————————— - Patients with LLT event (%) 20 (14.9%) 9 (6.7%) 9 (6.8%) - Patients without LLT event (%) 114 (85.1%) 125 (93.3%) 123 (93.2%) - Time to 1st LLT Event (DAYS) - Median NA NA 728.0 - 95% CI NA (724.0, NA) NA - 25% and 75%-ile 618.0, NA 724.0, NA 728.0, 728.0 - Range 1.0 to 731.0 {1} 1.0 to 728.0 {1} 1.0 to 728.0 {2} - Unstratified Analysis - p-value (log-rank) 0.0295 0.1687 - Hazard Ratio 0.43 0.58 - 95% CI (0.19, 0.94) (0.26, 1.27) - ——————————————————————————————————————————————————————————————————————————————————————— + Pbo Xan_Hi Xan_Lo + (N=86) (N=84) (N=84) + ———————————————————————————————————————————————————————————————————————————————————————— + Patients with LLT event (%) 26 (30.2%) 27 (32.1%) 26 (31.0%) + Patients without LLT event (%) 59 (68.6%) 54 (64.3%) 56 (66.7%) + Time to 1st LLT Event (DAYS) + Median 197.0 183.0 189.0 + 95% CI (185.0, NA) (181.0, NA) (182.0, NA) + 25% and 75%-ile 182.0, NA 127.0, NA 114.0, NA + Range 11.0 to 210.0 {1} 7.0 to 199.0 {2} 4.0 to 212.0 {2} + Unstratified Analysis + p-value (log-rank) 0.0453 0.1025 + Hazard Ratio 1.72 1.57 + 95% CI (1.00, 2.97) (0.91, 2.71) + ———————————————————————————————————————————————————————————————————————————————————————— - {1} - Censored observations: range minimum & maximum - {2} - Censored observation: range minimum - ——————————————————————————————————————————————————————————————————————————————————————— + {1} - Censored observation: range maximum + {2} - Censored observations: range minimum & maximum + ———————————————————————————————————————————————————————————————————————————————————————— # LBT11 variant 2 works as expected @@ -29,21 +29,21 @@ Code res Output - ARM A ARM B ARM C - (N=134) (N=134) (N=132) - ——————————————————————————————————————————————————————————————————————————————————————— - Patients with LLT event (%) 20 (14.9%) 9 (6.7%) 9 (6.8%) - Patients without LLT event (%) 114 (85.1%) 125 (93.3%) 123 (93.2%) - Time to 1st LLT Event (DAYS) - Median NA NA 728.0 - 95% CI NA (724.0, NA) NA - 25% and 75%-ile 618.0, NA 724.0, NA 728.0, 728.0 - Range 1.0 to 731.0 {1} 1.0 to 728.0 {1} 1.0 to 728.0 {2} - ——————————————————————————————————————————————————————————————————————————————————————— + Pbo Xan_Hi Xan_Lo + (N=86) (N=84) (N=84) + ———————————————————————————————————————————————————————————————————————————————————————— + Patients with LLT event (%) 26 (30.2%) 27 (32.1%) 26 (31.0%) + Patients without LLT event (%) 59 (68.6%) 54 (64.3%) 56 (66.7%) + Time to 1st LLT Event (DAYS) + Median 197.0 183.0 189.0 + 95% CI (185.0, NA) (181.0, NA) (182.0, NA) + 25% and 75%-ile 182.0, NA 127.0, NA 114.0, NA + Range 11.0 to 210.0 {1} 7.0 to 199.0 {2} 4.0 to 212.0 {2} + ———————————————————————————————————————————————————————————————————————————————————————— - {1} - Censored observations: range minimum & maximum - {2} - Censored observation: range minimum - ——————————————————————————————————————————————————————————————————————————————————————— + {1} - Censored observation: range maximum + {2} - Censored observations: range minimum & maximum + ———————————————————————————————————————————————————————————————————————————————————————— # LBT11 variant 3 works as expected @@ -51,28 +51,28 @@ Code res Output - ARM A ARM B ARM C - (N=134) (N=134) (N=132) - ——————————————————————————————————————————————————————————————————————————————————————— - Patients with LLT event (%) 20 (14.9%) 9 (6.7%) 9 (6.8%) - Patients without LLT event (%) 114 (85.1%) 125 (93.3%) 123 (93.2%) - Time to 1st LLT Event (DAYS) - Median NA NA 728.0 - 95% CI NA (724.0, NA) NA - 25% and 75%-ile 618.0, NA 724.0, NA 728.0, 728.0 - Range 1.0 to 731.0 {1} 1.0 to 728.0 {1} 1.0 to 728.0 {2} - Unstratified Analysis - p-value (log-rank) 0.0295 0.1687 - Hazard Ratio 0.43 0.58 - 95% CI (0.19, 0.94) (0.26, 1.27) - Stratified By: RACE, SEX - p-value (log-rank) 0.0858 0.1605 - Hazard Ratio 0.51 0.57 - 95% CI (0.23, 1.12) (0.26, 1.26) - ——————————————————————————————————————————————————————————————————————————————————————— + Pbo Xan_Hi Xan_Lo + (N=86) (N=84) (N=84) + ———————————————————————————————————————————————————————————————————————————————————————— + Patients with LLT event (%) 26 (30.2%) 27 (32.1%) 26 (31.0%) + Patients without LLT event (%) 59 (68.6%) 54 (64.3%) 56 (66.7%) + Time to 1st LLT Event (DAYS) + Median 197.0 183.0 189.0 + 95% CI (185.0, NA) (181.0, NA) (182.0, NA) + 25% and 75%-ile 182.0, NA 127.0, NA 114.0, NA + Range 11.0 to 210.0 {1} 7.0 to 199.0 {2} 4.0 to 212.0 {2} + Unstratified Analysis + p-value (log-rank) 0.0453 0.1025 + Hazard Ratio 1.72 1.57 + 95% CI (1.00, 2.97) (0.91, 2.71) + Stratified By: RACE, SEX + p-value (log-rank) 0.0505 0.1596 + Hazard Ratio 1.74 1.47 + 95% CI (0.99, 3.06) (0.84, 2.55) + ———————————————————————————————————————————————————————————————————————————————————————— - {1} - Censored observations: range minimum & maximum - {2} - Censored observation: range minimum - ——————————————————————————————————————————————————————————————————————————————————————— + {1} - Censored observation: range maximum + {2} - Censored observations: range minimum & maximum + ———————————————————————————————————————————————————————————————————————————————————————— diff --git a/tests/testthat/test-table_lbt11.R b/tests/testthat/test-table_lbt11.R index ff30c19..000006c 100644 --- a/tests/testthat/test-table_lbt11.R +++ b/tests/testthat/test-table_lbt11.R @@ -1,29 +1,53 @@ -adsl <- adsl_raw -adsaftte <- adaette_raw - -# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels. -adsl <- df_explicit_na(adsl) -adsaftte <- df_explicit_na(adsaftte) +# Test variants for AET05. +adsl <- adsl_pharmaverse %>% + filter(SAFFL == "Y") +anl <- adlb_pharmaverse %>% + filter(PARAMCD %in% c("AST", "ALT", "BILI") & is.na(DTYPE)) %>% + mutate( + CRIT1 = case_when( + PARAMCD == "AST" ~ "AST >=3xULN", + PARAMCD == "ALT" ~ "ALT >=3xULN", + PARAMCD == "BILI" ~ "BILI >=2xULN" + ), + CRIT1FL = case_when( + (AVAL / ANRHI >= 3) & PARAMCD %in% c("AST", "ALT") ~ "Y", + (AVAL / ANRHI >= 2 & PARAMCD == "BILI") ~ "Y" + ) + ) %>% + select(STUDYID, USUBJID, ARMCD, ADT, CRIT1, CRIT1FL) %>% + pivot_wider(names_from = CRIT1, values_from = CRIT1FL) %>% + mutate( + HYLAW = ifelse((`AST >=3xULN` == "Y" | `ALT >=3xULN` == "Y") & `BILI >=2xULN` == "Y" , "Y", NA_character_) + ) %>% + select(USUBJID, HYLAW, ADT) %>% + group_by(USUBJID, HYLAW) %>% + mutate( + LASTKNOWN = max(ADT), + HYDT = min(ADT) + ) %>% + ungroup() %>% + mutate(ADT2 = as.Date(ifelse(is.na(HYLAW), LASTKNOWN, HYDT))) %>% + select(USUBJID, HYLAW, ADT2) %>% + unique() %>% + left_join( + select(adsl, USUBJID, ARMCD, TRTSDT, SEX, RACE), + ., + by = "USUBJID" + ) %>% + mutate( + PARAM = "Time to Hy's Law Elevation in relation to ULN", + AVAL = as.numeric(difftime(ADT2, TRTSDT, unit = "days")), + AVAL = ifelse(is.na(AVAL) & !is.na(ARMCD), 1, AVAL), + AVALU = ifelse(!is.na(AVAL), "DAYS", NA_character_), + AVALU = as.factor(AVALU), + CNSR = ifelse(is.na(HYLAW), 1, 0) # original pharmaverseadam data + ) -adsl_safl <- dplyr::filter(adsl, .data$SAFFL == "Y") +anl$CNSR[1:80] <- 0 -anl <- adsaftte %>% - dplyr::filter( - SAFFL == "Y", - PARAMCD == "HYSTTEUL" - ) %>% - dplyr::mutate( - AVAL = .data$AVAL * dplyr::case_when( # convert to days, if possible - .data$AVALU == "WEEKS" ~ 7, - .data$AVALU == "MONTHS" ~ 30.4375, - .data$AVALU == "YEARS" ~ 365, - TRUE ~ 1 - ), - AVALU = factor(dplyr::case_when( - .data$AVALU %in% c("WEEKS", "MONTHS", "YEARS") ~ factor("DAYS"), - TRUE ~ .data$AVALU - ), levels = "DAYS"), - is_event = CNSR == 0, # this will be a LLT event +anl <- anl %>% + mutate( + is_event = CNSR == 0, event_grp = factor( dplyr::case_when( CNSR == 0 ~ "Patients with LLT event (%)", @@ -34,11 +58,12 @@ anl <- adsaftte %>% "Patients without LLT event (%)" ) ) - ) + ) %>% + filter(AVAL > 0) 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_fun = ref_group_position("first")) %>% + split_cols_by(var = "ARMCD", ref_group = "Pbo", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", @@ -54,7 +79,7 @@ testthat::test_that("LBT11 variant 1 works as expected", { table_names = "coxph_unstratified" ) - result <- build_table(lyt, df = anl, alt_counts_df = adsl_safl) + result <- build_table(lyt, df = anl, alt_counts_df = adsl) res <- testthat::expect_silent(result) testthat::expect_snapshot(res) @@ -62,7 +87,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_fun = ref_group_position("first")) %>% + split_cols_by(var = "ARMCD", ref_group = "Pbo", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", @@ -71,7 +96,7 @@ testthat::test_that("LBT11 variant 2 works as expected", { table_names = "time_to_event" ) - result <- build_table(lyt, df = anl, alt_counts_df = adsl_safl) + result <- build_table(lyt, df = anl, alt_counts_df = adsl) res <- testthat::expect_silent(result) testthat::expect_snapshot(res) @@ -81,7 +106,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_fun = ref_group_position("first")) %>% + split_cols_by(var = "ARMCD", ref_group = "Pbo", split_fun = ref_group_position("first")) %>% count_occurrences(vars = "event_grp") %>% surv_time( vars = "AVAL", @@ -104,8 +129,9 @@ testthat::test_that("LBT11 variant 3 works as expected", { table_names = "coxph_stratified" ) - result <- build_table(lyt, df = anl, alt_counts_df = adsl_safl) + result <- build_table(lyt, df = anl, alt_counts_df = adsl) res <- testthat::expect_silent(result) testthat::expect_snapshot(res) }) +