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 833 fixes #845

Merged
merged 37 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c5108ed
Working draft for AE_Assess unit test
collleenmclaughlin Oct 21, 2022
42db8a3
Updated assess helper functions and updated test_AE_Assess accordingly
collleenmclaughlin Oct 21, 2022
20e6d47
Updated assess helper functions and ind assess test codes
collleenmclaughlin Oct 25, 2022
fd2233e
Added "qtl" to input per CI fail
collleenmclaughlin Oct 25, 2022
62381ab
Documentation updates
collleenmclaughlin Oct 25, 2022
29339a8
More documentation updates
collleenmclaughlin Oct 25, 2022
e30bf18
Added testthat:: to fix CI
collleenmclaughlin Oct 25, 2022
7e430e8
git ignore for gsm submodule
collleenmclaughlin Oct 25, 2022
cadea77
Merge remote-tracking branch 'origin/dev' into fix-791
collleenmclaughlin Oct 25, 2022
6c63ac9
Final documentation update for unit tests
collleenmclaughlin Oct 25, 2022
3890204
Removing gsm from gitignore
collleenmclaughlin Oct 28, 2022
dc99636
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
be0d1d2
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
1b9c126
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
253006c
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
1cba61b
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
ea82410
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
b9d4816
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
b2e8a80
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
bbba48f
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
07f98d9
Update R/tests-assess_helpers.R
collleenmclaughlin Oct 28, 2022
43af3eb
Updated testthat data per review comments
collleenmclaughlin Oct 28, 2022
50f23af
Merge branch 'dev' into fix-791
collleenmclaughlin Oct 28, 2022
c3f528f
documentation update
collleenmclaughlin Oct 28, 2022
8ce9786
Fixing conflicts
collleenmclaughlin Oct 28, 2022
36102fc
PD snapshot update
collleenmclaughlin Oct 28, 2022
bcc8c6b
Added test helper function for funnel
collleenmclaughlin Oct 28, 2022
ecb4d3d
update unit tests
mattroumaya Nov 1, 2022
7e7331e
fix test
mattroumaya Nov 1, 2022
4a5c79e
Merge pull request #844 from Gilead-BioStats/fix-791-mr
collleenmclaughlin Nov 1, 2022
19c0107
Merge branch 'dev' into fix-791
mattroumaya Nov 1, 2022
e94e291
Merge pull request #824 from Gilead-BioStats/fix-791
mattroumaya Nov 1, 2022
e183fa1
Merge remote-tracking branch 'origin/dev' into fix-833-mr
mattroumaya Nov 1, 2022
f61e3b0
rename + docs
mattroumaya Nov 1, 2022
08cb5ef
update assess functions and unit tests
mattroumaya Nov 1, 2022
91f0450
resolve merge conflicts
mattroumaya Nov 1, 2022
ec24f4d
update pkgdown reference index
mattroumaya Nov 1, 2022
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
35 changes: 30 additions & 5 deletions R/AE_Assess.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,38 @@ AE_Assess <- function(

# dfAnalyzed --------------------------------------------------------------
if (strMethod == "NormalApprox") {
lData$dfAnalyzed <- gsm::Analyze_NormalApprox(lData$dfTransformed, strType = strType, bQuiet = bQuiet)
lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(lData$dfTransformed, vThreshold = vThreshold, strType = strType, bQuiet = bQuiet)

lData$dfAnalyzed <- gsm::Analyze_NormalApprox(
dfTransformed = lData$dfTransformed,
strType = strType,
bQuiet = bQuiet
)

lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(
dfTransformed = lData$dfTransformed,
vThreshold = vThreshold,
strType = strType,
bQuiet = bQuiet
)

} else if (strMethod == "poisson") {
lData$dfAnalyzed <- gsm::Analyze_Poisson(lData$dfTransformed, bQuiet = bQuiet)
lData$dfBounds <- gsm::Analyze_Poisson_PredictBounds(lData$dfTransformed, vThreshold = vThreshold, bQuiet = bQuiet)

lData$dfAnalyzed <- gsm::Analyze_Poisson(
dfTransformed = lData$dfTransformed,
bQuiet = bQuiet
)

lData$dfBounds <- gsm::Analyze_Poisson_PredictBounds(
dfTransformed = lData$dfTransformed,
vThreshold = vThreshold,
bQuiet = bQuiet
)
} else if (strMethod == "identity") {
lData$dfAnalyzed <- gsm::Analyze_Identity(lData$dfTransformed)

lData$dfAnalyzed <- gsm::Analyze_Identity(
dfTransformed = lData$dfTransformed
)

}

strAnalyzeFunction <- paste0("Analyze_", tools::toTitleCase(strMethod))
Expand Down
2 changes: 1 addition & 1 deletion R/Analyze_NormalApprox.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Analyze_NormalApprox <- function(
arrange(.data$Score)

if (!bQuiet) {
cli::cli_text("{.var OverallMetric}, {.var Factor}, {.var Score} columns created from normal approxiamtion")
cli::cli_text("{.var OverallMetric}, {.var Factor}, and {.var Score} columns created from normal approximation.")
}

return(dfAnalyzed)
Expand Down
16 changes: 14 additions & 2 deletions R/Disp_Assess.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,20 @@ Disp_Assess <- function(

# dfAnalyzed --------------------------------------------------------------
if (strMethod == "NormalApprox") {
lData$dfAnalyzed <- gsm::Analyze_NormalApprox(lData$dfTransformed, strType = strType, bQuiet = bQuiet)
lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(lData$dfTransformed, vThreshold = vThreshold, strType = strType, bQuiet = bQuiet)

lData$dfAnalyzed <- gsm::Analyze_NormalApprox(
dfTransformed = lData$dfTransformed,
strType = strType,
bQuiet = bQuiet
)

lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(
dfTransformed = lData$dfTransformed,
vThreshold = vThreshold,
strType = strType,
bQuiet = bQuiet
)

} else if (strMethod == "fisher") {
lData$dfAnalyzed <- gsm::Analyze_Fisher(lData$dfTransformed, bQuiet = bQuiet)
} else if (strMethod == "identity") {
Expand Down
1 change: 1 addition & 0 deletions R/Flag_NormalApprox.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#' strNumeratorCol = "Count",
#' strDenominatorCol = "Exposure"
#' )
#'
#' dfAnalyzed <- Analyze_NormalApprox(dfTransformed, strType = "rate")
#' dfFlagged <- Flag_NormalApprox(dfAnalyzed, vThreshold = c(-3, -2, 2, 3))
#'
Expand Down
17 changes: 15 additions & 2 deletions R/LB_Assess.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,22 @@ LB_Assess <- function(
if (!bQuiet) cli::cli_alert_success("{.fn Transform_Rate} returned output with {nrow(lData$dfTransformed)} rows.")

# dfAnalyzed --------------------------------------------------------------

if (strMethod == "NormalApprox") {
lData$dfAnalyzed <- gsm::Analyze_NormalApprox(lData$dfTransformed, strType = strType, bQuiet = bQuiet)
lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(lData$dfTransformed, vThreshold = vThreshold, strType = strType, bQuiet = bQuiet)

lData$dfAnalyzed <- gsm::Analyze_NormalApprox(
dfTransformed = lData$dfTransformed,
strType = strType,
bQuiet = bQuiet
)

lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(
dfTransformed = lData$dfTransformed,
vThreshold = vThreshold,
strType = strType,
bQuiet = bQuiet
)

} else if (strMethod == "fisher") {
lData$dfAnalyzed <- gsm::Analyze_Fisher(lData$dfTransformed, bQuiet = bQuiet)
} else if (strMethod == "identity") {
Expand Down
16 changes: 14 additions & 2 deletions R/PD_Assess.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,20 @@ PD_Assess <- function(

# dfAnalyzed --------------------------------------------------------------
if (strMethod == "NormalApprox") {
lData$dfAnalyzed <- gsm::Analyze_NormalApprox(lData$dfTransformed, strType = strType, bQuiet = bQuiet)
lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(lData$dfTransformed, vThreshold = vThreshold, strType = strType, bQuiet = bQuiet)

lData$dfAnalyzed <- gsm::Analyze_NormalApprox(
dfTransformed = lData$dfTransformed,
strType = strType,
bQuiet = bQuiet
)

lData$dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(
dfTransformed = lData$dfTransformed,
vThreshold = vThreshold,
strType = strType,
bQuiet = bQuiet
)

} else if (strMethod == "poisson") {
lData$dfAnalyzed <- gsm::Analyze_Poisson(lData$dfTransformed, bQuiet = bQuiet)
lData$dfBounds <- gsm::Analyze_Poisson_PredictBounds(lData$dfTransformed, vThreshold = vThreshold, bQuiet = bQuiet)
Expand Down
141 changes: 139 additions & 2 deletions R/tests-assess_helpers.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,142 @@
test_logical_assess_parameters <- function(assess_function, dfInput) {
test_valid_output_assess <- function(
assess_function,
dfInput
) {
output <- assess_function(dfInput = dfInput)

testthat::expect_true(is.list(output))
testthat::expect_snapshot(names(output))
testthat::expect_snapshot(names(output$lData))
testthat::expect_snapshot(names(output$lCharts))
testthat::expect_true("data.frame" %in% class(output$lData$dfTransformed))
testthat::expect_true("data.frame" %in% class(output$lData$dfAnalyzed))
testthat::expect_true("data.frame" %in% class(output$lData$dfFlagged))
testthat::expect_true("data.frame" %in% class(output$lData$dfSummary))
testthat::expect_true(output$lChecks$status)

if (exists("dfBounds", where = output$lData)) {
testthat::expect_true("data.frame" %in% class(output$lData$dfBounds))
}

}


################################################################

test_grouping_assess <- function(
assess_function,
dfInput
) {
subsetGroupCols <- function(assessOutput) {
assessOutput[["lData"]][["dfSummary"]] %>% select("GroupID")
}
site <- assess_function(dfInput)
study <- assess_function(dfInput, strGroup = "Study")
country <- assess_function(dfInput, strGroup = "Country")
customGroup <- assess_function(dfInput, strGroup = "CustomGroup")

testthat::expect_snapshot(subsetGroupCols(site))
testthat::expect_snapshot(subsetGroupCols(study))
testthat::expect_snapshot(subsetGroupCols(country))
testthat::expect_snapshot(subsetGroupCols(customGroup))
testthat::expect_false(all(map_lgl(list(site, study, country, customGroup), ~ all(map_lgl(., ~ is_grouped_df(.))))))
}

################################################################

test_invalid_data_assess <- function(
assess_function,
dfInput
) {
testthat::expect_null(assess_function("Hi")[["lData"]])
testthat::expect_snapshot_error(assess_function(dfInput, strMethod = 123))
testthat::expect_snapshot_error(assess_function(dfInput, strMethod = "abacus"))
testthat::expect_snapshot_error(assess_function(dfInput, strMethod = c("identity", "poisson")))
testthat::expect_snapshot_error(assess_function(dfInput, vThreshold = "A"))
testthat::expect_snapshot_error(assess_function(dfInput, vThreshold = 1))
testthat::expect_error(assess_function(dfInput, strGroup = "something"))
}

################################################################

test_invalid_data_assess_identity <- function(
assess_function,
dfInput
) {
testthat::expect_null(assess_function("Hi")[["lData"]])
testthat::expect_error(assess_function(dfInput, nThreshold = FALSE), "nThreshold must be numeric")
testthat::expect_error(assess_function(dfInput, nThreshold = "A"), "nThreshold must be numeric")
testthat::expect_error(assess_function(dfInput, nThreshold = c(1, 1)), "nThreshold must be length 1")
testthat::expect_error(assess_function(dfInput, strGroup = "something"), "strGroup must be one of: Site, Study, Country, or CustomGroup")
}

################################################################

test_missing_column_assess <- function(
assess_function,
dfInput
) {
dfInput_test <- dfInput %>% select("SiteID")
missing_req_col <- assess_function(dfInput = dfInput_test)

testthat::expect_silent(missing_req_col)
testthat::expect_null(missing_req_col$lData)
testthat::expect_null(missing_req_col$lCharts)
}

################################################################

test_invalid_mapping_assess <- function(
assess_function,
dfInput,
mapping
) {
mapping_edited <- mapping
mapping_edited$dfInput$strSiteCol <- "cupcakes"
invalid_map <- dfInput %>% assess_function(lMapping = mapping_edited)

testthat::expect_null(invalid_map$lData)
testthat::expect_null(invalid_map$lCharts)
testthat::expect_equal(invalid_map[["lChecks"]][["dfInput"]][["tests_if"]][["has_expected_columns"]][["warning"]],
"the following columns not found in df: cupcakes")
}

################################################################

test_identity <- function(
assess_function,
dfInput
) {
identity <- assess_function(dfInput, strMethod = "identity")

testthat::expect_error(assess_function(dfInput, strMethod = "identity"), NA)
testthat::expect_equal(names(identity$lCharts), c("barMetric", "barScore"))
testthat::expect_null(identity$lCharts$scatter)
testthat::expect_null(identity$lData$dfBounds)
}

################################################################

test_NA_count <- function(
assess_function,
dfInput
) {
dfInputNA <- dfInput
dfInputNA[1, "Count"] <- NA
count_check <- assess_function(dfInput = dfInputNA)

testthat::expect_silent(count_check)
testthat::expect_null(count_check$lData)
testthat::expect_null(count_check$lCharts)
}

################################################################

test_logical_assess_parameters <- function(
assess_function,
dfInput
) {
testthat::expect_snapshot(
assessment <- assess_function(dfInput, bQuiet = FALSE)
assessOutput <- assess_function(dfInput = dfInput, bQuiet = FALSE)
)
}
8 changes: 3 additions & 5 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ reference:
desc: Generate a visualization from the Assessment results
- contents:
- starts_with("Visualize_")
- Analyze_Binary_PredictBounds
- Analyze_NormalApprox_PredictBounds
- Analyze_Poisson_PredictBounds
- Analyze_Rate_PredictBounds

- title: Map
desc: Generate input data from multiple clinical data standards (generally Raw+ or SDTM-)
Expand All @@ -24,11 +23,10 @@ reference:
- title: Analyze
desc: Conduct statistical analysis based on input data
- contents:
- Analyze_Binary
- Analyze_NormalApprox
- Analyze_Identity
- Analyze_Fisher
- Analyze_Poisson
- Analyze_Rate

- title: Data Pipeline
desc: Create site-level summary, analyzed, and flagged data for an assessment
Expand All @@ -37,7 +35,7 @@ reference:
- Transform_Rate
- Flag
- Flag_Fisher
- Flag_Funnel
- Flag_NormalApprox
- Flag_Poisson
- Summarize

Expand Down
1 change: 1 addition & 0 deletions man/Flag_NormalApprox.Rd

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

Loading