aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--R/set_nd.R45
-rw-r--r--man/set_nd.Rd2
3 files changed, 32 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index b0775e1..579b8bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+commit a071d46f698397a6c8247e19eceb0fcd5f139056
+Author: Johannes Ranke <jranke@uni-bremen.de>
+Date: 2019-10-10 12:25:42 +0200
+
+ Fix set_nd for metabolites, handle zero at time zero
+
commit a5503d3e26408f7308a7bf4da617205b93d17422
Author: Johannes Ranke <jranke@uni-bremen.de>
Date: 2019-10-10 09:21:46 +0200
diff --git a/R/set_nd.R b/R/set_nd.R
index b2fb720..a9f3df4 100644
--- a/R/set_nd.R
+++ b/R/set_nd.R
@@ -17,7 +17,7 @@
#' @param loq Limit of quantification(numeric). Must be specified if the FOCUS rule to
#' stop after the first non-detection is to be applied
#' @param time_zero Is the first value in the series a time zero value?
-#' @param time_zero_nd_value Which value should we use for non-detects or zero values at time zero?
+#' @param time_zero_nd_value Which value should we use for non-detects at time zero?
#' @param stop_after_first_nondetect Should we really stop after the first non-detection?
#' @references FOCUS (2014) Generic Guidance for Estimating Persistence and Degradation
#' Kinetics from Environmental Fate Studies on Pesticides in EU Registration, Version 1.1,
@@ -51,12 +51,12 @@ set_nd <- function(r, lod, loq = NA,
nq = 0.5 * (lod + loq)
result[r == "nq"] <- nq
} else {
- if (any(r == "nq")) stop("You need to specify lod and loq")
+ if (any(r == "nq", na.rm = TRUE)) stop("You need to specify lod and loq")
}
# Handle nd values
if (time_zero) {
- if (r[1] %in% c("nd", 0)) {
+ if (r[1] %in% c("nd")) {
residues_present = FALSE
result[1] <- time_zero_nd_value
} else {
@@ -73,32 +73,37 @@ set_nd <- function(r, lod, loq = NA,
# residues_in_next
if (i < length(r)) {
next_value <- r[i + 1]
- if (next_value == "nd") residues_in_next = FALSE
+ if (is.na(next_value) || next_value == "nd") residues_in_next = FALSE
else residues_in_next = TRUE
} else {
residues_in_next = FALSE
}
- if (r[i] == "nd") {
- if (residues_present | residues_in_next) {
- result[i] <- 0.5 * lod
- } else {
- result[i] <- NA
- }
+ if (is.na(r[i])) {
+ residues_present <- FALSE
+ result[i] <- NA
+ } else {
+ if (r[i] == "nd") {
+ if (residues_present | residues_in_next) {
+ result[i] <- 0.5 * lod
+ } else {
+ result[i] <- NA
+ }
- if (stop_after_first_nondetect) {
- if (residues_present & !residues_in_next) {
- remaining <- (i + 1):length(r)
- if (!any(suppressWarnings(as.numeric(r[remaining])) > loq, na.rm = TRUE)) {
- result[remaining] <- NA
- return(as.numeric(result))
+ if (stop_after_first_nondetect) {
+ if (residues_present & !residues_in_next) {
+ remaining <- (i + 1):length(r)
+ if (!any(suppressWarnings(as.numeric(r[remaining])) > loq, na.rm = TRUE)) {
+ result[remaining] <- NA
+ return(as.numeric(result))
+ }
}
}
+ if (!residues_in_next) residues_present <- FALSE
+ else residues_present <- TRUE
+ } else {
+ residues_present <- TRUE
}
- if (!residues_in_next) residues_present <- FALSE
- else residues_present <- TRUE
- } else {
- residues_present <- TRUE
}
}
return(as.numeric(result))
diff --git a/man/set_nd.Rd b/man/set_nd.Rd
index 085b606..cef2705 100644
--- a/man/set_nd.Rd
+++ b/man/set_nd.Rd
@@ -22,7 +22,7 @@ stop after the first non-detection is to be applied}
\item{time_zero}{Is the first value in the series a time zero value?}
-\item{time_zero_nd_value}{Which value should we use for non-detects or zero values at time zero?}
+\item{time_zero_nd_value}{Which value should we use for non-detects at time zero?}
\item{stop_after_first_nondetect}{Should we really stop after the first non-detection?}
}

Contact - Imprint