Skip to content

Commit

Permalink
add tests and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kaigu1990 committed Feb 26, 2024
1 parent 07cacf9 commit 8d77ee6
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 48 deletions.
43 changes: 22 additions & 21 deletions R/onco_resp.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#' 5. Set to not estimable (NE) if:
#' - there is at least one CR, PR, SD, NE.
#'
#' After the previous steps, select the best one using the order 'CR>PR>SD>PD>NE'
#' After executing the previous steps, select the best one using the order 'CR>PR>SD>PD>NE'
#' for each subject. If the BOR is not unique, the first one (based on ADT) is selected.
#'
#' @return
Expand Down Expand Up @@ -95,13 +95,13 @@
#' "7", "2020-02-02", "2020-04-01", "NE",
#' "8", "2020-02-01", "2020-02-16", "PD"
#' ) %>%
#' mutate(
#' ADT = ymd(ADTC),
#' TRTSDT = ymd(TRTSDTC),
#' dplyr::mutate(
#' ADT = lubridate::ymd(ADTC),
#' TRTSDT = lubridate::ymd(TRTSDTC),
#' PARAMCD = "OVR",
#' PARAM = "Overall Response by Investigator"
#' ) %>%
#' select(-TRTSDTC)
#' dplyr::select(-TRTSDTC)
#'
#' # Derive BOR without confirmation.
#' derive_bor(data = adrs)
Expand All @@ -126,7 +126,8 @@ derive_bor <- function(data,
rs <- if (spec_date == "pd_date") {
data %>%
group_by(!!sym(unique_id)) %>%
filter(row_number() <= match("PD", AVALC) | all(AVALC != "PD"))
filter(row_number() <= match("PD", AVALC) | all(AVALC != "PD")) %>%
ungroup()
} else {
data
}
Expand All @@ -142,20 +143,20 @@ derive_bor <- function(data,
)
) %>%
left_join(aval_map, by = c("AVALC" = "avalc_temp")) %>%
mutate(AVAL = aval_temp) %>%
mutate(AVAL = .data$aval_temp) %>%
arrange(!!sym(unique_id), AVAL, ADT) %>%
# select the best and first one as the best overall response.
distinct(USUBJID, .keep_all = TRUE) %>%
distinct(!!sym(unique_id), .keep_all = TRUE) %>%
mutate(
PARAMCD = "BOR",
PARAM = "Best Overall Response"
) %>%
select(-c(avalc_temp, aval_temp))
select(-c("avalc_temp", "aval_temp"))
} else {
conf_cr <- rs %>%
left_join(
select(rs, !!sym(unique_id), ADT, AVALC),
by = "USUBJID", relationship = "many-to-many"
select(rs, !!sym(unique_id), "ADT", "AVALC"),
by = unique_id, relationship = "many-to-many"
) %>%
# keep the joined observations are after the original observations (e.g. AVALC.x)
filter(AVALC.x == "CR" & ADT.y > ADT.x) %>%
Expand All @@ -165,7 +166,7 @@ derive_bor <- function(data,
) %>%
group_by(!!sym(unique_id)) %>%
filter(
row_number() <= min(match(TRUE, flag))
row_number() <= min(match(TRUE, .data$flag))
) %>%
# define how many NE and which responses can be acceptable between these two assessments.
filter(sum(AVALC.y == "NE") <= max_ne & all(AVALC.y %in% c("CR", "NE"))) %>%
Expand All @@ -179,16 +180,16 @@ derive_bor <- function(data,

conf_pr <- rs %>%
left_join(
select(rs, !!sym(unique_id), ADT, AVALC),
by = "USUBJID", relationship = "many-to-many"
select(rs, !!sym(unique_id), "ADT", "AVALC"),
by = unique_id, relationship = "many-to-many"
) %>%
filter(AVALC.x == "PR" & ADT.y > ADT.x) %>%
mutate(
flag = AVALC.y %in% c("CR", "PR") & ADT.y >= ADT.x + days(ref_interval)
) %>%
group_by(!!sym(unique_id)) %>%
filter(
row_number() <= min(match(TRUE, flag))
row_number() <= min(match(TRUE, .data$flag))
) %>%
filter(sum(AVALC.y == "NE") <= max_ne & all(AVALC.y %in% c("CR", "PR", "NE"))) %>%
ungroup() %>%
Expand All @@ -203,19 +204,19 @@ derive_bor <- function(data,
# CR, PR and SD can be considered as SD that occurs at least 28 days after treatment start.
filter(AVALC %in% c("CR", "PR", "SD") &
ADT >= !!sym(ref_date) + days(ref_start_window)) %>%
distinct(USUBJID, .keep_all = TRUE) %>%
distinct(!!sym(unique_id), .keep_all = TRUE) %>%
mutate(AVALC = "SD") %>%
select(names(rs))

pd <- rs %>%
filter(AVALC == "PD") %>%
distinct(USUBJID, .keep_all = TRUE) %>%
distinct(!!sym(unique_id), .keep_all = TRUE) %>%
mutate(AVALC = "PD") %>%
select(names(rs))

ne <- rs %>%
filter(AVALC %in% c("CR", "PR", "SD", "NE")) %>%
distinct(USUBJID, .keep_all = TRUE) %>%
distinct(!!sym(unique_id), .keep_all = TRUE) %>%
mutate(AVALC = "NE") %>%
select(names(rs))

Expand All @@ -224,13 +225,13 @@ derive_bor <- function(data,
) %>%
left_join(aval_map, by = c("AVALC" = "avalc_temp")) %>%
mutate(
AVAL = aval_temp,
AVAL = .data$aval_temp,
PARAMCD = "CBOR",
PARAM = "Confirmed Best Overall Response"
) %>%
arrange(!!sym(unique_id), AVAL, ADT) %>%
distinct(USUBJID, .keep_all = TRUE) %>%
select(-aval_temp)
distinct(!!sym(unique_id), .keep_all = TRUE) %>%
select(-"aval_temp")
}

bor_res
Expand Down
4 changes: 4 additions & 0 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#' @importFrom lubridate ymd days
NULL

utils::globalVariables(c(
"ADT", "ADT.x", "ADT.y", "AVAL", "AVALC", "AVALC.x", "AVALC.y", "."
))

.onLoad <- function(libname, pkgname) {
op <- options()
op.stabiot <- list(
Expand Down
12 changes: 5 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ knitr::opts_chunk$set(
[![R-CMD-check](https://github.com/kaigu1990/stabiot/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/kaigu1990/stabiot/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

The goal of `stabiot` is to assist statisticians and programmers in using R functions
and methods to oversee the outputs often produced by SAS from vendors in clinical
The goal of `stabiot` is to assist statisticians and statistical programmers in using R functions and methods to oversee the outputs produced by SAS from outsourcing in clinical
trials. The data sets would be ADaM format preferably, but they do not have to
follow the CDISC standard.
strictly follow the CDISC standards.

In order to ensure the quality and accuracy of the results, I prefer to wrap mature
R package rather than rebuild the statistical methods. For now the completed sections
are listed as shown below.
To guarantee accurate results, I prefer to wrap mature R package rather than rebuild statistical methods. For present, the completed sections are listed below.

- Simulation of sample size determination by Bayesian.
- Summarize Least-squares Means from models, such as ANCOVA and MMRM.
- Computing response rate, odds ratio with or without stratification, and corresponding
- Compute response rate, odds ratio with or without stratification, and corresponding
confidence interval.
- Derive best overall response (confirmed or not confirmed BOR) per RECIST 1.1

## Installation

Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
[![R-CMD-check](https://github.com/kaigu1990/stabiot/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/kaigu1990/stabiot/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

The goal of `stabiot` is to assist statisticians and programmers in
using R functions and methods to oversee the outputs often produced by
SAS from vendors in clinical trials. The data sets would be ADaM format
preferably, but they do not have to follow the CDISC standard.
The goal of `stabiot` is to assist statisticians and statistical
programmers in using R functions and methods to oversee the outputs
produced by SAS from outsourcing in clinical trials. The data sets would
be ADaM format preferably, but they do not have to strictly follow the
CDISC standards.

In order to ensure the quality and accuracy of the results, I prefer to
wrap mature R package rather than rebuild the statistical methods. For
now the completed sections are listed as shown below.
To guarantee accurate results, I prefer to wrap mature R package rather
than rebuild statistical methods. For present, the completed sections
are listed below.

- Simulation of sample size determination by Bayesian.
- Summarize Least-squares Means from models, such as ANCOVA and MMRM.
- Computing response rate, odds ratio with or without stratification,
and corresponding confidence interval.
- Compute response rate, odds ratio with or without stratification, and
corresponding confidence interval.
- Derive best overall response (confirmed or not confirmed BOR) per
RECIST 1.1

## Installation

Expand Down
6 changes: 6 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
ADRS
ADT
ADaM
ANCOVA
AVAL
AVALC
BOR
BinomCI
BinomDiffCI
CDISC
Expand All @@ -12,6 +17,7 @@ MMRM
OddsRatio
PN
Pre
RECIST
TRT
clogit
magrittr
Expand Down
10 changes: 5 additions & 5 deletions man/derive_bor.Rd

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

9 changes: 3 additions & 6 deletions tests/spelling.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
if (requireNamespace("spelling", quietly = TRUE)) {
spelling::spell_check_test(
vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE
)
}
if(requireNamespace('spelling', quietly = TRUE))
spelling::spell_check_test(vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE)
Loading

0 comments on commit 8d77ee6

Please sign in to comment.