Skip to content

Commit

Permalink
lbt15 prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit committed Jul 10, 2023
1 parent 65724ad commit 6056949
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 13 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Collate:
'lbt06.R'
'lbt07.R'
'lbt14.R'
'lbt15.R'
'mht01.R'
'mng01.R'
'package.R'
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export(lbt14)
export(lbt14_main)
export(lbt14_post)
export(lbt14_pre)
export(lbt15)
export(lbt15_main)
export(lbt15_pre)
export(lvls)
export(main)
export(mht01)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Update `EXT01` to allow it to be displayed by `PARCAT2`.
* Add `COXT01` template. `COXT02` is based on `COXT01` now.
* Add `AET05` and `AET05_ALL` template.
* Add `LBT15` based on `LBT04`.

# chevron 0.2.0

Expand Down
29 changes: 19 additions & 10 deletions R/lbt04.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#' @describeIn lbt04 Main TLG function
#'
#' @inheritParams gen_args
#' @param abn_range (`string`) column describing anomaly magnitude
#' @param baseline (`string`) column describing anomaly at baseline.
#'
#' @details
#' * Only count LOW or HIGH values.
#' * Lab test results with missing `ANRIND` values are excluded.
#' * Lab test results with missing `abn_range` values are excluded.
#' * Split columns by arm, typically `ACTARM`.
#' * Does not include a total column by default.
#'
Expand All @@ -18,30 +20,35 @@
#'
lbt04_main <- function(adam_db,
arm_var = "ACTARM",
abn_range = "ANRIND",
baseline = "BNRIND",
...) {
assert_all_tablenames(adam_db, c("adsl", "adlb"))
checkmate::assert_string(arm_var)
assert_valid_variable(
adam_db$adlb, c("PARAM", "PARCAT1"),
types = list("characater", "factor")
)
assert_valid_variable(adam_db$adlb, c("AVALCAT1", "ANRIND"), na_ok = TRUE, empty_ok = TRUE, min_chars = 0L)
assert_valid_variable(adam_db$adlb, c("AVALCAT1", abn_range), na_ok = TRUE, empty_ok = TRUE, min_chars = 0L)
assert_valid_variable(adam_db$adlb, c("USUBJID"), types = list(c("character", "factor")), empty_ok = TRUE)
assert_valid_variable(adam_db$adsl, c("USUBJID"), types = list(c("character", "factor")))
assert_valid_variable(adam_db$adlb, baseline, types = list(c("character", "factor")), empty_ok = TRUE)
checkmate::assert_true(
any(lvls(adam_db$adlb$ANRIND) %in% c("HIGH HIGH", "HIGH", "LOW", "LOW LOW")) || all(is.na(adam_db$adlb$ANRIND))
any(lvls(adam_db$adlb[[abn_range]]) %in% c("HIGH HIGH", "HIGH", "LOW", "LOW LOW")) ||
all(is.na(adam_db$adlb[[abn_range]]))
)
assert_valid_var_pair(adam_db$adsl, adam_db$adlb, arm_var)
lbl_anrind <- var_labels_for(adam_db$adlb, "ANRIND")
lbl_abn_range <- var_labels_for(adam_db$adlb, abn_range)
lbl_param <- var_labels_for(adam_db$adlb, "PARAM")

lyt <- lbt04_lyt(
arm_var = arm_var,
var_parcat = "PARCAT1",
var_param = "PARAM",
lbl_param = lbl_param,
var_anrind = "ANRIND",
lbl_anrind = lbl_anrind
abn_range = abn_range,
lbl_abn_range = lbl_abn_range,
variables = list(id = "USUBJID", baseline = baseline)
)

tbl <- build_table(lyt, adam_db$adlb, alt_counts_df = adam_db$adsl)
Expand All @@ -62,8 +69,9 @@ lbt04_lyt <- function(arm_var,
var_parcat,
var_param,
lbl_param,
var_anrind,
lbl_anrind) {
abn_range,
lbl_abn_range,
variables) {
basic_table(show_colcounts = TRUE) %>%
split_cols_by(arm_var) %>%
split_rows_by(
Expand All @@ -78,12 +86,13 @@ lbt04_lyt <- function(arm_var,
indent_mod = 0L
) %>%
count_abnormal(
var = var_anrind,
var = abn_range,
abnormal = list(Low = c("LOW", "LOW LOW"), High = c("HIGH", "HIGH HIGH")),
exclude_base_abn = TRUE,
variables = variables,
.formats = list(fraction = format_fraction_fixed_dp)
) %>%
append_topleft(paste(" ", lbl_anrind))
append_topleft(paste(" ", lbl_abn_range))
}

#' @describeIn lbt04 Preprocessing
Expand Down
51 changes: 51 additions & 0 deletions R/lbt15.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# lbt15 ----

#' @describeIn lbt15 Main TLG function
#' @source `lbt04.R`
#' @export
#'
lbt15_main <- modify_default_args(lbt04_main, abn_range = "ATOXGR", baseline = "BTOXGR")

#' @describeIn lbt15 Preprocessing
#'
#' @inheritParams gen_args
#'
#' @export
#'
lbt15_pre <- function(adam_db, ...) {
format <- rule(
"LOW" = c("-2", "-3", "-4"),
"MODERATE/NORMAL" = c("-1", "0", "1"),
"HIGH" = c("2", "3", "4")
)

adam_db$adlb <- adam_db$adlb %>%
filter(
.data$ONTRTFL == "Y",
.data$PARCAT2 == "SI",
!is.na(.data$ATOXGR)
) %>%
mutate(
PARAM = with_label(.data$PARAM, "Laboratory Test"),
ANRIND = with_label(.data$ANRIND, "Direction of Abnormality")
) %>%
mutate(
ATOXGR = reformat(.data$ATOXGR, .env$format),
BTOXGR = reformat(.data$BTOXGR, .env$format)
)

adam_db
}

#' `LBT15` Laboratory Test Shifts to NCI-CTCAE Grade 3-4 Post-Baseline Table.
#'
#' @include chevron_tlg-S4class.R
#' @export
#'
#' @examples
#' run(lbt15, syn_data)
lbt15 <- chevron_t(
main = lbt15_main,
preprocess = lbt15_pre,
postprocess = lbt04_post
)
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ reference:
- lbt06
- lbt07
- lbt14
- lbt15
- mht01
- mng01
- pdt01
Expand Down
14 changes: 12 additions & 2 deletions man/lbt04.Rd

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

10 changes: 9 additions & 1 deletion man/lbt04_lyt.Rd

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

48 changes: 48 additions & 0 deletions man/lbt15.Rd

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

126 changes: 126 additions & 0 deletions tests/testthat/_snaps/lbt15.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# lbt15 functions with default argument value return expected result with test data

Code
cat(export_as_txt(res, lpp = 100))
Output
Laboratory Test A: Drug X B: Placebo C: Combination
Analysis Toxicity Grade (N=134) (N=134) (N=132)
—————————————————————————————————————————————————————————————————————————————————————
CHEMISTRY
Alanine Aminotransferase Measurement
Low 6/47 (12.8%) 3/53 (5.7%) 3/65 (4.6%)
High 2/47 (4.3%) 3/46 (6.5%) 1/63 (1.6%)
C-Reactive Protein Measurement
Low 5/55 (9.1%) 3/63 (4.8%) 4/53 (7.5%)
High 5/56 (8.9%) 5/58 (8.6%) 1/48 (2.1%)
Immunoglobulin A Measurement
Low 3/46 (6.5%) 7/52 (13.5%) 5/54 (9.3%)
High 3/43 (7.0%) 4/52 (7.7%) 6/55 (10.9%)
COAGULATION
Alanine Aminotransferase Measurement
Low 3/54 (5.6%) 4/58 (6.9%) 5/50 (10.0%)
High 7/55 (12.7%) 7/52 (13.5%) 2/50 (4.0%)
C-Reactive Protein Measurement
Low 5/57 (8.8%) 1/50 (2.0%) 4/52 (7.7%)
High 7/54 (13.0%) 3/46 (6.5%) 2/50 (4.0%)
Immunoglobulin A Measurement
Low 5/54 (9.3%) 8/64 (12.5%) 0/56
High 5/49 (10.2%) 7/67 (10.4%) 1/56 (1.8%)
HEMATOLOGY
Alanine Aminotransferase Measurement
Low 2/49 (4.1%) 3/48 (6.2%) 5/61 (8.2%)
High 3/48 (6.2%) 6/45 (13.3%) 5/57 (8.8%)
C-Reactive Protein Measurement
Low 4/50 (8.0%) 5/48 (10.4%) 8/59 (13.6%)
High 1/47 (2.1%) 3/46 (6.5%) 5/56 (8.9%)
Immunoglobulin A Measurement
Low 3/59 (5.1%) 6/57 (10.5%) 6/52 (11.5%)
High 4/57 (7.0%) 3/59 (5.1%) 10/53 (18.9%)

# lbt15 can handle all NA values

Code
cat(export_as_txt(res, lpp = 100))
Output
————————————————————————————————————————————————————————————————————————————————————————
Null Report: No observations met the reporting criteria for inclusion in this output.

# lbt15 can handle missing levels

Code
cat(export_as_txt(res, lpp = 100))
Output
Laboratory Test A: Drug X B: Placebo C: Combination
ATOXGR (N=134) (N=134) (N=132)
————————————————————————————————————————————————————————————————————————————————
CHEMISTRY
Alanine Aminotransferase Measurement
Low 0/47 0/53 0/65
High 0/47 0/46 0/63
C-Reactive Protein Measurement
Low 0/55 0/63 0/53
High 0/56 0/58 0/48
Immunoglobulin A Measurement
Low 0/46 0/52 0/54
High 0/43 0/52 0/55
COAGULATION
Alanine Aminotransferase Measurement
Low 0/54 0/58 0/50
High 0/55 0/52 0/50
C-Reactive Protein Measurement
Low 0/57 0/50 0/52
High 0/54 0/46 0/50
Immunoglobulin A Measurement
Low 0/54 0/64 0/56
High 0/49 0/67 0/56
HEMATOLOGY
Alanine Aminotransferase Measurement
Low 0/49 0/48 0/61
High 0/48 0/45 0/57
C-Reactive Protein Measurement
Low 0/50 0/48 0/59
High 0/47 0/46 0/56
Immunoglobulin A Measurement
Low 0/59 0/57 0/52
High 0/57 0/59 0/53

# lbt15 can handle some NA values

Code
cat(export_as_txt(res, lpp = 100))
Output
Laboratory Test A: Drug X B: Placebo C: Combination
Analysis Toxicity Grade (N=134) (N=134) (N=132)
—————————————————————————————————————————————————————————————————————————————————————
CHEMISTRY
Alanine Aminotransferase Measurement
Low 6/47 (12.8%) 3/53 (5.7%) 3/65 (4.6%)
High 2/47 (4.3%) 3/46 (6.5%) 1/63 (1.6%)
C-Reactive Protein Measurement
Low 5/55 (9.1%) 3/63 (4.8%) 4/53 (7.5%)
High 5/56 (8.9%) 5/58 (8.6%) 1/48 (2.1%)
Immunoglobulin A Measurement
Low 3/46 (6.5%) 7/52 (13.5%) 5/54 (9.3%)
High 3/43 (7.0%) 4/52 (7.7%) 6/55 (10.9%)
COAGULATION
Alanine Aminotransferase Measurement
Low 3/54 (5.6%) 4/58 (6.9%) 5/50 (10.0%)
High 7/55 (12.7%) 7/52 (13.5%) 2/50 (4.0%)
C-Reactive Protein Measurement
Low 5/57 (8.8%) 1/50 (2.0%) 4/52 (7.7%)
High 7/54 (13.0%) 3/46 (6.5%) 2/50 (4.0%)
Immunoglobulin A Measurement
Low 5/54 (9.3%) 8/64 (12.5%) 0/56
High 5/49 (10.2%) 7/67 (10.4%) 1/56 (1.8%)
HEMATOLOGY
Alanine Aminotransferase Measurement
Low 2/49 (4.1%) 3/48 (6.2%) 5/61 (8.2%)
High 3/48 (6.2%) 6/45 (13.3%) 5/57 (8.8%)
C-Reactive Protein Measurement
Low 4/50 (8.0%) 5/48 (10.4%) 8/59 (13.6%)
High 1/47 (2.1%) 3/46 (6.5%) 5/56 (8.9%)
Immunoglobulin A Measurement
Low 3/59 (5.1%) 6/57 (10.5%) 6/52 (11.5%)
High 4/57 (7.0%) 3/59 (5.1%) 10/53 (18.9%)

Loading

0 comments on commit 6056949

Please sign in to comment.