Skip to content

Commit

Permalink
ID nondetects based on specific text result values
Browse files Browse the repository at this point in the history
  • Loading branch information
cristinamullin committed Dec 15, 2023
1 parent b9d22bb commit 785c5e4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
7 changes: 5 additions & 2 deletions R/CensoredDataSuite.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ TADA_IDCensoredData <- function(.data) {
## Flag censored data that does not have det cond populated
cens$TADA.Detection_Type <- ifelse(is.na(cens$ResultDetectionConditionText), "ResultDetectionConditionText missing", cens$TADA.Detection_Type)

## Fill in detection type when result measure value = "ND"
cens$TADA.Detection_Type <- ifelse(cens$ResultMeasureValue %in% c("ND"), "Non-Detect", cens$TADA.Detection_Type)
## Fill in detection type when text result measure value indicates it is a nondetect
cens$TADA.Detection_Type <- ifelse(cens$ResultMeasureValue %in%
c("ND", "BPQL", "BDL"),
"Non-Detect",
cens$TADA.Detection_Type)

## Let user know when detection condition text is missing from one or more results
# NOTE that at this point, TADA.Detection_Type may be NA if there are detection conditions in dataset that are not present in domain table
Expand Down
57 changes: 53 additions & 4 deletions R/Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,59 @@ TADA_AutoClean <- function(.data) {
.data <- TADA_ConvertSpecialChars(.data, "DetectionQuantitationLimitMeasure.MeasureValue")

# Move detection limit value and unit to TADA Result Measure Value and Unit columns
.data$TADA.ResultMeasureValue <- ifelse(is.na(.data$TADA.ResultMeasureValue) & !is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureValue), .data$TADA.DetectionQuantitationLimitMeasure.MeasureValue, .data$TADA.ResultMeasureValue)
.data$TADA.ResultMeasure.MeasureUnitCode <- ifelse(is.na(.data$TADA.ResultMeasure.MeasureUnitCode) & !is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureUnitCode), .data$TADA.DetectionQuantitationLimitMeasure.MeasureUnitCode, .data$TADA.ResultMeasure.MeasureUnitCode)
.data$TADA.ResultMeasureValueDataTypes.Flag <- ifelse(.data$TADA.ResultMeasureValueDataTypes.Flag == "Blank" & !is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureValue), "Result Value/Unit Copied from Detection Limit", .data$TADA.ResultMeasureValueDataTypes.Flag)

# Consider moving this to ID censored data in the future?
# this first row copies all over when result is blank but
# TADA.DetectionQuantitationLimitMeasure.MeasureValue is not and the
# TADA.ResultMeasureValueDataTypes.Flag is not Text
# Imp note: TADA result values are NA for text even though they are not NA in the original result value
.data$TADA.ResultMeasureValue <- ifelse(
is.na(.data$TADA.ResultMeasureValue)
& !is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureValue)
& .data$TADA.ResultMeasureValueDataTypes.Flag != "Text",
.data$TADA.DetectionQuantitationLimitMeasure.MeasureValue,
.data$TADA.ResultMeasureValue)
# this does the same as above for the units
.data$TADA.ResultMeasure.MeasureUnitCode <- ifelse(
is.na(.data$TADA.ResultMeasure.MeasureUnitCode)
& !is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureUnitCode)
& .data$TADA.ResultMeasureValueDataTypes.Flag != "Text",
.data$TADA.DetectionQuantitationLimitMeasure.MeasureUnitCode,
.data$TADA.ResultMeasure.MeasureUnitCode)
.data$TADA.ResultMeasureValueDataTypes.Flag <- ifelse(
.data$TADA.ResultMeasureValueDataTypes.Flag == "Blank"
& !is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureValue),
"Result Value/Unit Copied from Detection Limit",
.data$TADA.ResultMeasureValueDataTypes.Flag)

# this copies det lim result value and unit over to TADA result value and unit
# when the result value is TEXT but there is a specific text value that indicates
# the result is censored (BPQL, BDL, ND)
# and the TADA.DetectionQuantitationLimitMeasure.MeasureValue provided
.data$TADA.ResultMeasureValueDataTypes.Flag <- ifelse(
.data$TADA.ResultMeasureValueDataTypes.Flag == "Text" &
.data$ResultMeasureValue == "BPQL" |
.data$ResultMeasureValue == "BDL" |
.data$ResultMeasureValue == "ND" &
!is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureValue),
"Result Value/Unit Copied from Detection Limit",
.data$TADA.ResultMeasureValueDataTypes.Flag)
.data$TADA.ResultMeasureValue <- ifelse(
is.na(.data$TADA.ResultMeasureValue)
& !is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureValue)
& .data$ResultMeasureValue == "BPQL" |
.data$ResultMeasureValue == "BDL" |
.data$ResultMeasureValue == "ND" ,
.data$TADA.DetectionQuantitationLimitMeasure.MeasureValue,
.data$TADA.ResultMeasureValue)
# this does the same as above for the units
.data$TADA.ResultMeasure.MeasureUnitCode <- ifelse(
!is.na(.data$TADA.DetectionQuantitationLimitMeasure.MeasureUnitCode)
& .data$ResultMeasureValue == "BPQL" |
.data$ResultMeasureValue == "BDL" |
.data$ResultMeasureValue == "ND" ,
.data$TADA.DetectionQuantitationLimitMeasure.MeasureUnitCode,
.data$TADA.ResultMeasure.MeasureUnitCode)

# Identify detection limit data
print("TADA_Autoclean: identifying detection limit data.")
.data <- TADA_IDCensoredData(.data)
Expand Down

0 comments on commit 785c5e4

Please sign in to comment.