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

Fix 201 qc ae map raw #214

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion R/AE_Assess.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#' - `SiteID` - Site ID
#' - `Count` - Number of Adverse Events
#' - `Exposure` - Number of days of exposure
#' - `Rate` - Rate of Exposure (Count / Exposure)
#'
#' The Assessment
#' - \code{\link{Transform_EventCount}} creates `dfTransformed`.
Expand Down Expand Up @@ -47,7 +48,8 @@ AE_Assess <- function( dfInput, vThreshold=NULL, cLabel="", cMethod="poisson",bD
"cLabel is not character" = is.character(cLabel),
"cMethod is not 'poisson' or 'wilcoxon'" = cMethod %in% c("poisson","wilcoxon"),
"bDataList is not logical" = is.logical(bDataList),
"One or more of these columns: SubjectID, SiteID, Count, Exposure, and Rate not found in dfInput"=all(c("SubjectID","SiteID", "Count","Exposure", "Rate") %in% names(dfInput))
"One or more of these columns: SubjectID, SiteID, Count, Exposure, and Rate not found in dfInput"=all(c("SubjectID","SiteID", "Count","Exposure", "Rate") %in% names(dfInput)),
"cMethod must be length 1" = length(cMethod) == 1
)
lAssess <- list()
lAssess$dfInput <- dfInput
Expand Down
7 changes: 4 additions & 3 deletions R/AE_Map_Raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#'
#' Note that the function can generate data summaries for specific types of AEs, but passing filtered ADAE data to dfADAE.
#'
#' @param dfAE AE dataset with columns SUBJID and rows for each AE record
#' @param dfRDSL Subject-level Raw Data (RDSL) required columns: SubjectID, SiteID, value specified in strExposureCol
#' @param dfAE AE dataset with required column SUBJID and rows for each AE record
#' @param dfRDSL Subject-level Raw Data (RDSL) with required columns: SubjectID, SiteID, value specified in strExposureCol
#' @param strExposureCol Name of exposure column. 'TimeOnTreatment' by default
#'
#' @return Data frame with one record per person data frame with columns: SubjectID, SiteID, Count (number of AEs), Exposure (Time on Treatment in Days), Rate (AE/Day)
Expand All @@ -40,7 +40,8 @@ AE_Map_Raw <- function( dfAE, dfRDSL, strExposureCol="TimeOnTreatment"){
"SUBJID column not found in dfAE"="SUBJID" %in% names(dfAE),
"strExposureCol is not character"=is.character(strExposureCol),
"SubjectID, SiteID and strExposureCol columns not found in dfRDSL"=all(c("SubjectID","SiteID",strExposureCol) %in% names(dfRDSL)),
"NAs found in Subject ID column of dfAE" = all(!is.na(dfAE$SUBJID))
"NAs found in SUBJID column of dfAE" = all(!is.na(dfAE$SUBJID)),
"NAs found in Subject ID column of dfRDSL" = all(!is.na(dfRDSL$SubjectID))
)

dfInput <- dfRDSL %>%
Expand Down
1 change: 1 addition & 0 deletions man/AE_Assess.Rd

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

4 changes: 2 additions & 2 deletions man/AE_Map_Raw.Rd

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

24 changes: 11 additions & 13 deletions tests/testthat/test_AE_Assess.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ test_that("incorrect inputs throw errors",{
expect_error(AE_Assess(ae_input, cLabel=123))
expect_error(AE_Assess(ae_input, cMethod="abacus"))
expect_error(AE_Assess(ae_input, bDataList="Yes"))
expect_error(AE_Assess(ae_input %>% select(-SubjectID)))
expect_error(AE_Assess(ae_input %>% select(-SiteID)))
expect_error(AE_Assess(ae_input %>% select(-Count)))
expect_error(AE_Assess(ae_input %>% select(-Exposure)))
expect_error(AE_Assess(ae_input %>% select(-Rate)))
expect_error(AE_Assess(ae_input, cMethod=c("wilcoxon", "poisson")))
})


test_that("incorrect inputs throw errors",{
expect_error(AE_Assess(ae_input %>% select(-SubjectID)))
expect_error(AE_Assess(ae_input %>% select(-SiteID)))
expect_error(AE_Assess(ae_input %>% select(-Count)))
expect_error(AE_Assess(ae_input %>% select(-Exposure)))
expect_error(AE_Assess(ae_input %>% select(-Rate)))
})

ae_list <- AE_Assess(ae_input, bDataList=TRUE)
expect_true(is.list(ae_list))
expect_equal(names(ae_list),c('dfInput','dfTransformed','dfAnalyzed','dfFlagged','dfSummary'))


test_that("Summary created when bDataList = FALSE has correct structure",{
ae_summary <- AE_Assess(ae_input, bDataList=FALSE)
expect_equal(length(unique(ae_summary$SiteID)) , length(ae_summary$SiteID))
expect_equal(names(ae_summary),c( "Assessment", "Label" , "SiteID" , "N" , "PValue" , "Flag"))
})
33 changes: 24 additions & 9 deletions tests/testthat/test_AE_Map_Raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ test_that("incorrect inputs throw errors",{
expect_error(AE_Map_Raw("Hi","Mom"))
})

test_that("invalid strExposureCol throws error",{
expect_error( AE_Map_Raw(dfAE = clindata::raw_ae, dfRDSL = clindata::rawplus_rdsl, strExposureCol= "Bad_Name" ))
})


test_that("error given if required column not found",{
expect_error(
Expand Down Expand Up @@ -119,7 +123,7 @@ test_that("NA values in input data are handled",{

dfExposure3<-tibble::tribble(
~SubjectID, ~SiteID, ~TimeOnTreatment,
NA, 1, 10,
1, 1, 10,
2, 1, NA,
3, NA, 30,
4, 2, 50
Expand All @@ -128,30 +132,41 @@ test_that("NA values in input data are handled",{

dfInput3 <-tibble::tribble(
~SubjectID, ~SiteID, ~Count, ~Exposure,~Rate,
NA, 1, 0, 10, 0,
1, 1, 4, 10, 0.4,
2, 1, 2, NA, NA,
3, NA, 0, 30, 0 ,
4, 2, 2, 50, .04
)

expect_equal(dfInput3, AE_Map_Raw(dfAE = dfAE3, dfRDSL = dfExposure3))






})


test_that("dfAE Subject NA value throws error",{
test_that("dfAE$SUBJID NA value throws error",{
dfAE4 <- tibble::tribble(~SUBJID, 1,NA,1,1,2,2,4,4)

dfExposure4<-tibble::tribble(
~SubjectID, ~SiteID, ~TimeOnTreatment,
1, 1, 10,
2, 1, 20,
3, 3, 30,
4, 2, 50
)


expect_error(AE_Map_Raw(dfAE = dfAE4, dfRDSL = dfExposure4))
})

test_that("dfRDSL$SubjectID NA value throws error",{
dfAE4 <- tibble::tribble(~SUBJID, 1,1,1,1,2,2,4,4)

dfExposure4<-tibble::tribble(
~SubjectID, ~SiteID, ~TimeOnTreatment,
NA, 1, 10,
2, 1, NA,
3, NA, 30,
2, 1, 20,
3, 2, 30,
4, 2, 50
)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test_IE_Map_Raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test_that("error given if required column not found",{
clindata::rawplus_rdsl
)
)
#"INVID", "IECAT", "IETESTCD","IETEST", "IEORRES"
expect_error(
IE_Map_Raw(
clindata::raw_ie_a2 ,
Expand Down