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

minCharacterizationMean inclusive of min value and add upper bound constraint #250

Merged
merged 2 commits into from
Apr 22, 2024
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
2 changes: 1 addition & 1 deletion R/GetCovariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ getDbCovariateData <- function(connectionDetails = NULL,
}
errorMessages <- checkmate::makeAssertCollection()
minCharacterizationMean <- utils::type.convert(minCharacterizationMean, as.is = TRUE)
checkmate::assertNumeric(x = minCharacterizationMean, lower = 0, add = errorMessages)
checkmate::assertNumeric(x = minCharacterizationMean, lower = 0, upper = 1, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)
if (!is.null(connectionDetails)) {
connection <- DatabaseConnector::connect(connectionDetails)
Expand Down
4 changes: 2 additions & 2 deletions R/GetCovariatesFromOtherCohorts.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' @param covariateSettings An object of type \code{covariateSettings} as created using the
#' \code{\link{createCohortBasedCovariateSettings}} or
#' \code{\link{createCohortBasedTemporalCovariateSettings}} functions.
#' @param minCharacterizationMean The minimum mean value for characterization output. Values below this will be cut off from output. This
#' @param minCharacterizationMean The minimum mean value for binary characterization output. Values below this will be cut off from output. This
#' will help reduce the file size of the characterization output, but will remove information
#' on covariates that have very low values. The default is 0.
#' @template GetCovarParams
Expand Down Expand Up @@ -50,7 +50,7 @@ getDbCohortBasedCovariatesData <- function(connection,
checkmate::assertClass(covariateSettings, "covariateSettings", add = errorMessages)
checkmate::assertLogical(aggregated, len = 1, add = errorMessages)
minCharacterizationMean <- utils::type.convert(minCharacterizationMean, as.is = TRUE)
checkmate::assertNumeric(x = minCharacterizationMean, lower = 0, add = errorMessages)
checkmate::assertNumeric(x = minCharacterizationMean, lower = 0, upper = 1, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)
if (!missing(cohortId)) {
warning("cohortId argument has been deprecated, please use cohortIds")
Expand Down
7 changes: 3 additions & 4 deletions R/GetDefaultCovariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#' it is a temp table, do not specify \code{targetDatabaseSchema}.
#' @param targetCovariateRefTable (Optional) The name of the table where the covariate reference will be stored.
#' @param targetAnalysisRefTable (Optional) The name of the table where the analysis reference will be stored.
#' @param minCharacterizationMean The minimum mean value for characterization output. Values below this will be cut off from output. This
#' @param minCharacterizationMean The minimum mean value for binary characterization output. Values below this will be cut off from output. This
#' will help reduce the file size of the characterization output, but will remove information
#' on covariates that have very low values. The default is 0.
#'
Expand Down Expand Up @@ -85,7 +85,7 @@ getDbDefaultCovariateData <- function(connection,
}
errorMessages <- checkmate::makeAssertCollection()
minCharacterizationMean <- utils::type.convert(minCharacterizationMean, as.is = TRUE)
checkmate::assertNumeric(x = minCharacterizationMean, lower = 0, add = errorMessages)
checkmate::assertNumeric(x = minCharacterizationMean, lower = 0, upper = 1, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

settings <- .toJson(covariateSettings)
Expand Down Expand Up @@ -152,7 +152,6 @@ getDbDefaultCovariateData <- function(connection,
andromedaTableName = "covariatesContinuous",
snakeCaseToCamelCase = TRUE
)
filterCovariateDataCovariates(covariateData, "covariatesContinuous", minCharacterizationMean)
}

# Covariate reference
Expand Down Expand Up @@ -295,6 +294,6 @@ getDbDefaultCovariateData <- function(connection,
filterCovariateDataCovariates <- function(covariateData, covariatesName, minCharacterizationMean = 0) {
if ("averageValue" %in% colnames(covariateData[[covariatesName]]) && minCharacterizationMean != 0) {
covariateData[[covariatesName]] <- covariateData[[covariatesName]] %>%
dplyr::filter(.data$averageValue > minCharacterizationMean)
dplyr::filter(.data$averageValue >= minCharacterizationMean)
}
}
2 changes: 1 addition & 1 deletion R/UnitTestHelperFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#' of the createCovariate functions, or a list of such objects.
#' @param aggregated Should aggregate statistics be computed instead of covariates per
#' cohort entry?
#' @param minCharacterizationMean The minimum mean value for characterization output. Values below this will be cut off from output. This
#' @param minCharacterizationMean The minimum mean value for binary characterization output. Values below this will be cut off from output. This
#' will help reduce the file size of the characterization output, but will remove information
#' on covariates that have very low values. The default is 0.
#' @return
Expand Down
9 changes: 1 addition & 8 deletions tests/testthat/test-CovariateData.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ test_that("test filtering of covariates based on minCharacterizationMean", {
nCovariates <- covariateData$covariates %>%
collect() %>%
nrow()
nCovariatesCont <- covariateData$covariatesContinuous %>%
collect() %>%
nrow()


covariateData <- getDbCovariateData(connectionDetails = eunomiaConnectionDetails,
cdmDatabaseSchema = eunomiaCdmDatabaseSchema,
cohortDatabaseSchema = eunomiaOhdsiDatabaseSchema,
Expand All @@ -111,11 +108,7 @@ test_that("test filtering of covariates based on minCharacterizationMean", {
nCovariatesFiltered <- covariateData$covariates %>%
collect() %>%
nrow()
nCovariatesContFiltered <- covariateData$covariatesContinuous %>%
collect() %>%
nrow()
expect_true(nCovariatesFiltered < nCovariates)
expect_true(nCovariatesContFiltered < nCovariatesCont)
})

test_that("test loadCovariateData", {
Expand Down
Loading