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 11 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
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ example, `">2.5 x ULN"` changed to `">2.5"` for grade 3. (#2534)
</details>

# admiral 1.1.1

- `check_type = "warning"` default argument added to `derive_param_tte` with an
`arg_match` function within the function so the user can use a valid input of
`error, message, warning, or none`. `signal_duplicate_records()` has also been
added to the function on lines 394 and 411 to check for uniqueness of records. (#2481)
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved

- `order()` function has been added to `event_source()` and `censor_source()` and
defaulted to `NULL` to allow sorting of input data. (#2481)
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved

ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
- `derive_extreme_event()` was fixed such that `check_type = "none"` is accepted
again. (#2462)

Expand Down
40 changes: 30 additions & 10 deletions R/derive_param_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,12 @@ derive_param_tte <- function(dataset = NULL,
censor_conditions,
create_datetime = FALSE,
set_values_to,
subject_keys = get_admiral_option("subject_keys")) {
# checking and quoting #
subject_keys = get_admiral_option("subject_keys"),
check_type = "warning") {
# Match check_type to valid admiral options
check_type <- rlang::arg_match(check_type, c("warning", "message", "error", "none"))
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved

# checking and quoting #
assert_data_frame(dataset, optional = TRUE)
assert_vars(by_vars, optional = TRUE)
start_date <- assert_symbol(enexpr(start_date))
Expand Down Expand Up @@ -374,7 +378,17 @@ derive_param_tte <- function(dataset = NULL,
)
}

#check for duplicates in dataset_adsl and source_datasets
combined_dataset <- bind_rows(dataset_adsl, !!!source_datasets)

signal_duplicate_records(
dataset = combined_dataset,
by_vars = expr_c(subject_keys, by_vars),
cnd_type = check_type
)

ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
tmp_event <- get_new_tmp_var(dataset)

# determine events #
event_data <- filter_date_sources(
sources = event_conditions,
Expand All @@ -386,7 +400,7 @@ derive_param_tte <- function(dataset = NULL,
) %>%
mutate(!!tmp_event := 1L)

# determine censoring observations #
# determine censoring observations #
censor_data <- filter_date_sources(
sources = censor_conditions,
source_datasets = source_datasets,
Expand All @@ -397,7 +411,7 @@ derive_param_tte <- function(dataset = NULL,
) %>%
mutate(!!tmp_event := 0L)

# determine variable to add from ADSL #
# determine variable to add from ADSL #
if (create_datetime) {
date_var <- sym("ADTM")
start_var <- sym("STARTDTM")
Expand Down Expand Up @@ -793,7 +807,8 @@ tte_source <- function(dataset_name,
filter = NULL,
date,
censor = 0,
set_values_to = NULL) {
set_values_to = NULL,
order = order) {
out <- list(
dataset_name = assert_character_scalar(dataset_name),
filter = assert_filter_cond(enexpr(filter), optional = TRUE),
Expand All @@ -803,7 +818,8 @@ tte_source <- function(dataset_name,
set_values_to,
named = TRUE,
optional = TRUE
)
),
order = order
)
class(out) <- c("tte_source", "source", "list")
out
Expand Down Expand Up @@ -844,13 +860,15 @@ tte_source <- function(dataset_name,
event_source <- function(dataset_name,
filter = NULL,
date,
set_values_to = NULL) {
set_values_to = NULL,
order = NULL) {
out <- tte_source(
dataset_name = assert_character_scalar(dataset_name),
filter = !!enexpr(filter),
date = !!assert_expr(enexpr(date)),
censor = 0,
set_values_to = set_values_to
set_values_to = set_values_to,
order = order
)
class(out) <- c("event_source", class(out))
out
Expand Down Expand Up @@ -891,13 +909,15 @@ censor_source <- function(dataset_name,
filter = NULL,
date,
censor = 1,
set_values_to = NULL) {
set_values_to = NULL,
order = NULL) {
out <- tte_source(
dataset_name = assert_character_scalar(dataset_name),
filter = !!enexpr(filter),
date = !!assert_expr(enexpr(date)),
censor = assert_integer_scalar(censor, subset = "positive"),
set_values_to = set_values_to
set_values_to = set_values_to,
order = order
)
class(out) <- c("censor_source", class(out))
out
Expand Down
3 changes: 2 additions & 1 deletion man/censor_source.Rd

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

3 changes: 2 additions & 1 deletion man/derive_param_tte.Rd

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

8 changes: 7 additions & 1 deletion man/event_source.Rd

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

9 changes: 8 additions & 1 deletion man/tte_source.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat/_snaps/derive_param_tte.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
event_conditions = list(ttae), censor_conditions = list(eos), source_datasets = list(
adsl = adsl, ae = ae), set_values_to = exprs(PARAMCD = "TTAE", PARCAT2 = AEDECOD))
Condition
Warning:
Dataset contains duplicate records with respect to `STUDYID`, `USUBJID`, and `AEDECOD`
i Run `admiral::get_duplicates_dataset()` to access the duplicate records
Error in `derive_param_tte()`:
! For some values of "PARAMCD" there is more than one value of "AEDECOD"
i Call `admiral::get_one_to_many_dataset()` to get all one-to-many values.
Expand All @@ -43,6 +46,9 @@
as.numeric(as.factor(AEDECOD))), PARAM = past("Time to First", AEDECOD,
"Adverse Event"), PARCAT1 = "TTAE", PARCAT2 = AEDECOD))
Condition
Warning:
Dataset contains duplicate records with respect to `STUDYID`, `USUBJID`, and `AEDECOD`
i Run `admiral::get_duplicates_dataset()` to access the duplicate records
Error in `process_set_values_to()`:
! Assigning variables failed!
* `set_values_to = exprs(PARAMCD = paste0("TTAE", as.numeric(as.factor(AEDECOD))), PARAM = past("Time to First", AEDECOD, "Adverse Event"), PARCAT1 = TTAE, PARCAT2 = AEDECOD)`
Expand Down
134 changes: 134 additions & 0 deletions tests/testthat/test-derive_param_tte.R
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,137 @@ test_that("list_tte_source_objects Test 15: expected objects produced", {

expect_dfs_equal(expected_output, observed_output, keys = c("object"))
})

## Test 15: derive_param_tte detects duplicates when check_type = 'warning' ----
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
test_that("list_tte_source_objects Test 15: detects duplicates when check_type = 'warning'", {
# Define ADSL dataset
adsl <- tibble::tribble(
~USUBJID, ~TRTSDT, ~TRTEDT, ~EOSDT,
"01", ymd("2020-12-06"), ymd("2021-03-02"), ymd("2021-03-06"),
"02", ymd("2021-01-16"), ymd("2021-01-20"), ymd("2021-02-03")
) %>%
mutate(STUDYID = "AB42")

# Define AE dataset with duplicates
ae <- tibble::tribble(
~USUBJID, ~AESTDTC, ~AESEQ, ~AEDECOD,
"01", "2021-01-03", 1, "Flu",
"01", "2021-03-04", 2, "Cough",
"01", "2021-01-03", 3, "Flu"
) %>%
mutate(
STUDYID = "AB42",
AESTDT = ymd(AESTDTC)
)

# Define event source
ttae <- event_source(
dataset_name = "ae",
date = AESTDT,
set_values_to = exprs(
EVENTDESC = "AE",
SRCDOM = "AE",
SRCVAR = "AESTDTC",
SRCSEQ = AESEQ
)
)

# Define censor source
eot <- censor_source(
dataset_name = "adsl",
date = pmin(TRTEDT + days(10), EOSDT),
censor = 1,
set_values_to = exprs(
EVENTDESC = "END OF TRT",
SRCDOM = "ADSL",
SRCVAR = "TRTEDT"
)
)

# Test for duplicate detection
expect_warning(
Copy link
Collaborator

Choose a reason for hiding this comment

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

expect_snapshot() should be used because the message is created by the function which is tested. This ensures that the complete message looks as intended.

derive_param_tte(
dataset_adsl = adsl,
start_date = TRTSDT,
event_conditions = list(ttae),
censor_conditions = list(eot),
source_datasets = list(adsl = adsl, ae = ae),
set_values_to = exprs(PARAMCD = "TTAE"),
check_type = "warning"
),
regexp = "Dataset contains duplicate records"
)
})

## Test 16: derive_param_tte produces consistent results regardless of input sort order ----
test_that("list_tte_source_objects Test 16: derive_param_tte produces consistent results
regardless of input sort order", {
# Define ADSL dataset
adsl <- tibble::tribble(
~USUBJID, ~TRTSDT, ~TRTEDT, ~EOSDT,
"01", ymd("2020-12-06"), ymd("2021-03-02"), ymd("2021-03-06"),
"02", ymd("2021-01-16"), ymd("2021-01-20"), ymd("2021-02-03")
) %>%
mutate(STUDYID = "AB42")

# Define AE dataset
ae <- tibble::tribble(
~USUBJID, ~AESTDTC, ~AESEQ, ~AEDECOD,
"01", "2021-01-03", 1, "Flu",
"01", "2021-03-04", 2, "Cough",
"01", "2021-01-03", 3, "Flu"
) %>%
mutate(
STUDYID = "AB42",
AESTDT = ymd(AESTDTC)
)

# Define event source with order
ttae <- event_source(
dataset_name = "ae",
date = AESTDT,
set_values_to = exprs(
EVENTDESC = "AE",
SRCDOM = "AE",
SRCVAR = "AESTDTC",
SRCSEQ = "AESEQ"
ProfessorP-beep marked this conversation as resolved.
Show resolved Hide resolved
),
order = exprs(AESEQ)
)

# Define censor source with order
eot <- censor_source(
dataset_name = "adsl",
date = pmin(TRTEDT + days(10), EOSDT),
censor = 1,
set_values_to = exprs(
EVENTDESC = "END OF TRT",
SRCDOM = "ADSL",
SRCVAR = "TRTEDT"
),
order = exprs(TRTEDT)
)

# Run derive_param_tte with sorted AE dataset
result_sorted <- derive_param_tte(
dataset_adsl = adsl,
start_date = TRTSDT,
event_conditions = list(ttae),
censor_conditions = list(eot),
source_datasets = list(adsl = adsl, ae = arrange(ae, AESEQ)),
set_values_to = exprs(PARAMCD = "TTAE")
)

# Run derive_param_tte with reverse-sorted AE dataset
result_unsorted <- derive_param_tte(
dataset_adsl = adsl,
start_date = TRTSDT,
event_conditions = list(ttae),
censor_conditions = list(eot),
source_datasets = list(adsl = adsl, ae = arrange(ae, desc(AESEQ))),
set_values_to = exprs(PARAMCD = "TTAE")
)

# Validate that the results are the same
expect_dfs_equal(result_sorted, result_unsorted, keys = "USUBJID")
})
Loading