Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #2481 bug the result of derive param tte depends on the sort order of the input #2569

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8e23388
Added order arguments to censor_source and event_source. Also added s…
ProfessorP-beep Nov 18, 2024
cd52801
Added order argument to tte_source as part of development and error f…
ProfessorP-beep Nov 18, 2024
2727736
Fixed previous erros but still need to address failed tests for Test …
ProfessorP-beep Nov 18, 2024
9e86217
added check_type arg_match to derive_param_tte so user has to input a…
ProfessorP-beep Nov 18, 2024
d97377c
Changed position of signal_duplicate_records function in derive_param…
ProfessorP-beep Nov 18, 2024
fa49a51
lintr changes by removing whitespace.
ProfessorP-beep Nov 18, 2024
01e8f5a
styler fix.
ProfessorP-beep Nov 18, 2024
53457c2
updated NEWS.md with changes to derive_param_tte,. Removed Test 17 fr…
ProfessorP-beep Nov 19, 2024
020c9d7
Merge branch 'main' into 2481-bug-the-result-of-derive_param_tte-depe…
ProfessorP-beep Nov 19, 2024
dccdbe1
changed the signal_duplicate_records within derive_parame_tte to hand…
ProfessorP-beep Nov 19, 2024
8006891
Merge branch '2481-bug-the-result-of-derive_param_tte-depends-on-the-…
ProfessorP-beep Nov 19, 2024
4c95243
added a tryCatch() to filter_date_sources to catch duplicates to addr…
ProfessorP-beep Nov 21, 2024
087c0f3
Moved duplication check to filter_date_sources in tryCatch() and rewr…
ProfessorP-beep Nov 24, 2024
4405868
1. Moved updates in News section to admiral dev section
ProfessorP-beep Dec 3, 2024
21b5a00
Ran styler, lintr fixes, and devtools check.
ProfessorP-beep Dec 3, 2024
ce07ad1
styler changes
ProfessorP-beep Dec 3, 2024
1d4e6b7
accepted snapshots from testthat and addressed bds_tte.Rmd error for …
ProfessorP-beep Dec 3, 2024
22f3f2d
added documentation for order and check_type arguments added to funct…
ProfessorP-beep Dec 3, 2024
47637a5
requested updates to documentation and test script for derive_param_tte
ProfessorP-beep Dec 16, 2024
e882758
corrected documentation and removed rlang from bds_tte.Rmd
ProfessorP-beep Dec 17, 2024
e5c28fc
updated derive_param_tte documentation and added test to derive_param…
ProfessorP-beep Dec 20, 2024
404c949
fixed spelling error
ProfessorP-beep Dec 20, 2024
ae70492
updates to derive_param_tte documentation and test examples.
ProfessorP-beep Dec 23, 2024
34d2fb3
Update NEWS.md
ProfessorP-beep Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions R/derive_param_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@
#' mutate(STUDYID = "AB42")
#'
#' ae <- tribble(
#' ~USUBJID, ~AESTDTC, ~AESEQ, ~AEDECOD,
#' "01", "2021-01-03T10:56", 1, "Flu",
#' "01", "2021-03-04", 2, "Cough",
#' "01", "2021", 3, "Flu"
#' ~USUBJID, ~AESTDTC, ~AESEQ, ~AEDECOD,
#' "01", "2021-01-03T10:56", 1, "Flu",
#' "01", "2021-03-04", 2, "Cough",
#' "01", "2021-", 3, "Flu"
Comment on lines -265 to +276
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this been changed?

Now the example generates a warning.

#' ) %>%
#' mutate(STUDYID = "AB42")
#'
Expand Down Expand Up @@ -321,6 +321,50 @@
#' )
#' ) %>%
#' select(USUBJID, STARTDT, PARAMCD, PARAM, ADT, CNSR, SRCSEQ)
#'
#' # Resolve tie when serious AE share a date by sorting with order argument
#' adsl <- tribble(
#' ~USUBJID, ~TRTSDT, ~EOSDT,
#' "01", ymd("2020-12-06"), ymd("2021-03-06"),
#' "02", ymd("2021-01-16"), ymd("2021-02-03")
#' ) %>% mutate(STUDYID = "AB42")
#'
#' ae <- tribble(
#' ~USUBJID, ~AESTDTC, ~AESEQ, ~AESER, ~AEDECOD,
#' "01", "2021-01-03", 1, "Y", "Flu",
#' "01", "2021-01-03", 2, "Y", "cough",
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
#' "01", "2021-01-20", 3, "N", "Headache",
#' ) %>% mutate(
#' AESTDT = ymd(AESTDTC),
#' STUDYID = "AB42"
#' )
#'
#' derive_param_tte(
#' dataset_adsl = adsl,
#' start_date = TRTSDT,
#' source_datasets = list(adsl = adsl, ae = ae),
#' event_conditions = list(event_source(
#' dataset_name = "ae",
#' date = AESTDT,
#' set_values_to = exprs(
#' EVENTDESC = "Serious AE",
#' SRCSEQ = AESEQ
#' ),
#' filter = AESER == "Y",
#' order = exprs(AESTDT, AESEQ)
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
#' )),
#' censor_conditions = list(censor_source(
#' dataset_name = "adsl",
#' date = EOSDT,
#' censor = 1,
#' set_values_to = exprs(EVENTDESC = "End of Study")
#' )),
#' set_values_to = exprs(
#' PARAMCD = "TTSAE",
#' PARAM = "Time to First Serious AE"
#' )
#' )
#'
derive_param_tte <- function(dataset = NULL,
dataset_adsl,
source_datasets,
Expand Down Expand Up @@ -845,8 +889,10 @@ extend_source_datasets <- function(source_datasets,
#'
#' @param order Sort order
#'
#' If the argument is set to a non-null value, for each by group the first or
#' last observation
#' An optional named list returned by `exprs()` defining additional variables
#' that the input dataset is sorted on after `date`.
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
#'
#' Permitted Values: list of variables created by `exprs()` e.g. `exprs(ASEQ)`.
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @keywords source_specifications
#' @family source_specifications
Expand Down
6 changes: 4 additions & 2 deletions man/censor_source.Rd

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

52 changes: 48 additions & 4 deletions man/derive_param_tte.Rd

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

6 changes: 4 additions & 2 deletions man/event_source.Rd

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

6 changes: 4 additions & 2 deletions man/tte_source.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/derive_param_tte.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
i Following names were provided by `source_datasets`: "adsl"
i But, `censor_conditions[[1]]$dataset_name = adls`

# list_tte_source_objects Test 14: error is issued if package does not exist
# list_tte_source_objects Test 16: error is issued if package does not exist
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be 17

Copy link
Collaborator

@rossfarrugia rossfarrugia Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ProfessorP-beep from my small review comments only this one still needs updating (its just to make sure the _snaps file matches the test script), and looks like you need to merge latest main branch into this one. I would recommend @bundfussr takes another look and is the approver of this PR before we merge in the updates as i only did some minor checks around the documentation and tests.


Code
list_tte_source_objects(package = "tte")
Expand Down
72 changes: 66 additions & 6 deletions tests/testthat/test-derive_param_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,68 @@ test_that("derive_param_tte Test 14: detects duplicates in input datasets via pi
)
})

## Test 15: derive_param_tte produces consistent results regardless of input sort order ----
test_that("derive_param_tte Test 15: produces consistent results regardless of input sort order", {
## Test 15: derive_param_tte resolves ties using order argument when input is sorted descending
test_that("derive_param_tte Test 15: derive_param_tte resolves ties using order argument when
input is sorted descending", {
adsl <- tibble::tribble(
~USUBJID, ~TRTSDT, ~EOSDT,
"01", ymd("2020-12-06"), ymd("2021-03-06"),
"02", ymd("2021-01-16"), ymd("2021-02-03")
) %>%
mutate(STUDYID = "AB42")

# Sort the input AE dataset in descending order by AESEQ
# to confirm that the order argument re-sorts it correctly.
ae <- tibble::tribble(
~USUBJID, ~AESTDTC, ~AESEQ, ~AESER, ~AEDECOD,
"01", "2021-01-03", 2, "Y", "Cough",
"01", "2021-01-03", 1, "Y", "Flu",
"01", "2021-01-20", 3, "N", "Headache"
) %>%
mutate(
STUDYID = "AB42",
AESTDT = ymd(AESTDTC)
) %>%
arrange(desc(AESEQ)) # Intentionally sort descending to test the order argument

result <- derive_param_tte(
dataset_adsl = adsl,
start_date = TRTSDT,
event_conditions = list(event_source(
dataset_name = "ae",
date = AESTDT,
set_values_to = exprs(
EVENTDESC = "Serious AE",
SRCSEQ = AESEQ
),
filter = AESER == "Y",
order = exprs(AESTDT, AESEQ) # Should re-sort so that AESEQ=1 (Flu) is chosen on tie
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
)),
censor_conditions = list(censor_source(
dataset_name = "adsl",
date = EOSDT,
censor = 1,
set_values_to = exprs(EVENTDESC = "End of Study")
)),
set_values_to = exprs(
PARAMCD = "TTSAE",
PARAM = "Time to First Serious AE"
),
source_datasets = list(adsl = adsl, ae = ae)
)

# Check that for USUBJID = "01", the first serious AE selected is the one with AESEQ = 1 (Flu),
# despite the input AE data initially being arranged to show AESEQ=2 (Cough) first.
selected_seq <- result %>%
filter(USUBJID == "01", PARAMCD == "TTSAE") %>%
pull(SRCSEQ)

expect_equal(selected_seq, 1, info = "The order argument should ensure AE with AESEQ=1
is chosen on tie.")
})

## Test 16: derive_param_tte produces consistent results regardless of input sort order ----
test_that("derive_param_tte Test 16: produces consistent results regardless of input sort order", {
# Define ADSL dataset
adsl <- tibble::tribble(
~USUBJID, ~TRTSDT, ~TRTEDT, ~EOSDT,
Expand Down Expand Up @@ -1059,16 +1119,16 @@ test_that("derive_param_tte Test 15: produces consistent results regardless of i
})

# list_tte_source_objects ----
## Test 16: error is issued if package does not exist ----
test_that("list_tte_source_objects Test 16: error is issued if package does not exist", {
## Test 17: error is issued if package does not exist ----
test_that("list_tte_source_objects Test 17: error is issued if package does not exist", {
expect_snapshot(
list_tte_source_objects(package = "tte"),
error = TRUE
)
})

## Test 17: expected objects produced ----
test_that("list_tte_source_objects Test 17: expected objects produced", {
## Test 18: expected objects produced ----
test_that("list_tte_source_objects Test 18: expected objects produced", {
expected_output <- tibble::tribble(
~object, ~dataset_name, ~filter,
"ae_ser_event", "adae", quote(TRTEMFL == "Y" & AESER == "Y"),
Expand Down
Loading