Skip to content

Commit

Permalink
too few instances of Hy's Law in adlb_pharmaverse, imputed in
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz2101 committed Jan 25, 2024
1 parent 23a899d commit 26f3707
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 85 deletions.
108 changes: 54 additions & 54 deletions tests/testthat/_snaps/table_lbt11.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,76 @@
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

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

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
———————————————————————————————————————————————————————————————————————————————————————

88 changes: 57 additions & 31 deletions tests/testthat/test-table_lbt11.R
Original file line number Diff line number Diff line change
@@ -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 (%)",
Expand All @@ -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",
Expand All @@ -54,15 +79,15 @@ 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)
})

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",
Expand All @@ -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)
Expand All @@ -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",
Expand All @@ -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)
})

0 comments on commit 26f3707

Please sign in to comment.