diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | DESCRIPTION | 2 | ||||
-rw-r--r-- | NAMESPACE | 4 | ||||
-rw-r--r-- | R/set_nd.R | 118 | ||||
-rw-r--r-- | R/set_nd_nq.R | 164 | ||||
-rw-r--r-- | _pkgdown.yml | 2 | ||||
-rw-r--r-- | docs/reference/index.html | 11 | ||||
-rw-r--r-- | docs/reference/set_nd.html | 222 | ||||
-rw-r--r-- | docs/reference/set_nd_nq.html | 284 | ||||
-rw-r--r-- | docs/sitemap.xml | 2 | ||||
-rw-r--r-- | man/set_nd.Rd | 64 | ||||
-rw-r--r-- | man/set_nd_nq.Rd | 103 | ||||
-rw-r--r-- | test.log | 8 | ||||
-rw-r--r-- | tests/testthat/test_set_nd.R | 64 |
14 files changed, 627 insertions, 427 deletions
@@ -1,3 +1,9 @@ +commit a2ca8be6f5593f0afd833ea73b62149055ee84f9 +Author: Johannes Ranke <jranke@uni-bremen.de> +Date: 2019-10-10 14:56:35 +0200 + + Do not mess with zero values at time zero + commit a071d46f698397a6c8247e19eceb0fcd5f139056 Author: Johannes Ranke <jranke@uni-bremen.de> Date: 2019-10-10 12:25:42 +0200 diff --git a/DESCRIPTION b/DESCRIPTION index 39e174b..af046d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: pfm Type: Package Title: Utilities for Pesticide Fate Modelling Version: 0.5.7 -Date: 2019-10-10 +Date: 2019-10-15 Authors@R: person("Johannes Ranke", email = "jranke@uni-bremen.de", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0003-4371-6538")) @@ -36,8 +36,8 @@ export(perc_runoff_reduction_exposit) export(pfm_degradation) export(read.TOXSWA_cwa) export(sawtooth) -export(set_nd) -export(set_nd_focus) +export(set_nd_nq) +export(set_nd_nq_focus) export(soil_DT50) export(soil_Kfoc) export(soil_N) diff --git a/R/set_nd.R b/R/set_nd.R deleted file mode 100644 index a9f3df4..0000000 --- a/R/set_nd.R +++ /dev/null @@ -1,118 +0,0 @@ -#' Set non-detects in residue series without replicates -#' -#' Sets non-detects directly before or directly after detects to NA. Values between -#' lod and loq are set to their mean value if an loq is specified. -#' If 'time_zero' is set to TRUE, the residue series is assumed to start with time -#' zero, and non-detects at time zero are set to 'time_zero_nd_value'. For the -#' set_nd_focus variant, this is zero, otherwise this argument has NA as default -#' value. -#' If stopping after the first non-detection is requested, as in in the FOCUS -#' variant of the function, an loq has to be specified in order to decide -#' if any later detections are above the loq. -#' -#' @param r A character vector of sequential residues without replicates, with -#' non-detects specified as 'nd' and unquantified values above the limit of -#' detection specified as 'nq', otherwise coercible to numeric -#' @param lod Limit of detection (numeric) -#' @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 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, -#' 18 December 2014, p. 251 -#' @describeIn set_nd Set non-detects in residues series -#' @export -#' @examples -#' # FOCUS (2014) p. 75/76 and 131/132 -#' parent_1 <- c(.12, .09, .05, .03, "nd", "nd", "nd", "nd", "nd", "nd") -#' set_nd(parent_1, 0.02) -#' parent_2 <- c(.12, .09, .05, .03, "nd", "nd", .03, "nd", "nd", "nd") -#' set_nd(parent_2, 0.02) -#' set_nd_focus(parent_2, 0.02, loq = 0.05) -#' parent_3 <- c(.12, .09, .05, .03, "nd", "nd", .06, "nd", "nd", "nd") -#' set_nd(parent_3, 0.02) -#' set_nd_focus(parent_3, 0.02, loq = 0.05) -#' metabolite <- c("nd", "nd", "nd", 0.03, 0.06, 0.10, 0.11, 0.10, 0.09, 0.05, 0.03, "nd", "nd") -#' set_nd(metabolite, 0.02) -set_nd <- function(r, lod, loq = NA, - time_zero = TRUE, time_zero_nd_value = NA, stop_after_first_nondetect = FALSE) -{ - - if (stop_after_first_nondetect & is.na(loq)) { - stop("You need to specify an loq to decide if the curve should be cut off after the first non-detect") - } - - result <- r - - # Handle nq values - if (!missing(loq)) { - nq = 0.5 * (lod + loq) - result[r == "nq"] <- nq - } else { - 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")) { - residues_present = FALSE - result[1] <- time_zero_nd_value - } else { - residues_present = TRUE - } - start_i <- 2 - } else { - residues_present <- if (r[1] == "nd") FALSE else TRUE - start_i <- 1 - } - - for (i in start_i:length(r)) { - - # residues_in_next - if (i < length(r)) { - next_value <- r[i + 1] - if (is.na(next_value) || next_value == "nd") residues_in_next = FALSE - else residues_in_next = TRUE - } else { - residues_in_next = FALSE - } - - 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 (!residues_in_next) residues_present <- FALSE - else residues_present <- TRUE - } else { - residues_present <- TRUE - } - } - } - return(as.numeric(result)) -} - -#' @describeIn set_nd Set non-detects in residues series according to FOCUS rules -#' @export -set_nd_focus <- function(r, lod, loq = NA, time_zero = TRUE) { - result <- set_nd(r, lod, loq = loq, time_zero = time_zero, - time_zero_nd_value = 0, stop_after_first_nondetect = TRUE) - return(result) -} diff --git a/R/set_nd_nq.R b/R/set_nd_nq.R new file mode 100644 index 0000000..a372879 --- /dev/null +++ b/R/set_nd_nq.R @@ -0,0 +1,164 @@ +#' Set non-detects and unquantified values in residue series without replicates + +#' This function automates replacing unquantified values in residue time and +#' depth series. For time series, the function performs part of the residue +#' processing proposed in the FOCUS kinetics guidance for parent compounds +#' and metabolites. For two-dimensional residue series over time and depth, +#' it automates the proposal of Boesten et al (2015). + +#' @param res_raw Character vector of a residue time series, or matrix of +#' residue values with rows representing depth profiles for a specific sampling +#' time, and columns representing time series of residues at the same depth. +#' Values below the limit of detection (lod) have to be coded as "nd", values +#' between the limit of detection and the limit of quantification, if any, have +#' to be coded as "nq". Samples not analysed have to be coded as "na". All +#' values that are not "na", "nd" or "nq" have to be coercible to numeric +#' @param lod Limit of detection (numeric) +#' @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_presence Do we assume that residues occur at time zero? +#' This only affects samples from the first sampling time that have been +#' reported as "nd" (not detected). +#' @references Boesten, J. J. T. I., van der Linden, A. M. A., Beltman, W. H. +#' J. and Pol, J. W. (2015). Leaching of plant protection products and their +#' transformation products; Proposals for improving the assessment of leaching +#' to groundwater in the Netherlands — Version 2. Alterra report 2630, Alterra +#' Wageningen UR (University & Research centre) +#' @references FOCUS (2014) Generic Guidance for Estimating Persistence and Degradation +#' Kinetics from Environmental Fate Studies on Pesticides in EU Registration, Version 1.1, +#' 18 December 2014, p. 251 +#' @return A numeric vector, if a vector was supplied, or a numeric matrix otherwise +#' @export +#' @examples +#' # FOCUS (2014) p. 75/76 and 131/132 +#' parent_1 <- c(.12, .09, .05, .03, "nd", "nd", "nd", "nd", "nd", "nd") +#' set_nd_nq(parent_1, 0.02) +#' parent_2 <- c(.12, .09, .05, .03, "nd", "nd", .03, "nd", "nd", "nd") +#' set_nd_nq(parent_2, 0.02) +#' set_nd_nq_focus(parent_2, 0.02, loq = 0.05) +#' parent_3 <- c(.12, .09, .05, .03, "nd", "nd", .06, "nd", "nd", "nd") +#' set_nd_nq(parent_3, 0.02) +#' set_nd_nq_focus(parent_3, 0.02, loq = 0.05) +#' metabolite <- c("nd", "nd", "nd", 0.03, 0.06, 0.10, 0.11, 0.10, 0.09, 0.05, 0.03, "nd", "nd") +#' set_nd_nq(metabolite, 0.02) +#' set_nd_nq_focus(metabolite, 0.02, 0.05) +#' # +#' # Boesten et al. (2015), p. 57/58 +#' table_8 <- matrix( +#' c(10, 10, rep("nd", 4), +#' 10, 10, rep("nq", 2), rep("nd", 2), +#' 10, 10, 10, "nq", "nd", "nd", +#' "nq", 10, "nq", rep("nd", 3), +#' "nd", "nq", "nq", rep("nd", 3), +#' rep("nd", 6), rep("nd", 6)), +#' ncol = 6, byrow = TRUE) +#' set_nd_nq(table_8, 0.5, 1.5, time_zero_presence = TRUE) +#' table_10 <- matrix( +#' c(10, 10, rep("nd", 4), +#' 10, 10, rep("nd", 4), +#' 10, 10, 10, rep("nd", 3), +#' "nd", 10, rep("nd", 4), +#' rep("nd", 18)), +#' ncol = 6, byrow = TRUE) +#' set_nd_nq(table_10, 0.5, time_zero_presence = TRUE) +set_nd_nq <- function(res_raw, lod, loq = NA, time_zero_presence = FALSE) { + if (!is.character(res_raw)) { + stop("Please supply a vector or a matrix of character values") + } + if (is.vector(res_raw)) { + was_vector <- TRUE + res_raw <- as.matrix(res_raw) + } else { + was_vector <- FALSE + if (!is.matrix(res_raw)) { + stop("Please supply a vector or a matrix of character values") + } + } + nq <- 0.5 * (loq + lod) + nda <- 0.5 * lod # not detected but adjacent to detection + res_raw[res_raw == "nq"] <- nq + + if (!time_zero_presence) { + for (j in 1:ncol(res_raw)) { + if (res_raw[1, j] == "nd") res_raw[1, j] <- "na" + } + } + res_raw[res_raw == "na"] <- NA + + not_nd_na <- function(value) !(grepl("nd", value) | is.na(value)) + + for (i in 1:nrow(res_raw)) { + for (j in 1:ncol(res_raw)) { + if (!is.na(res_raw[i, j]) && res_raw[i, j] == "nd") { + if (i > 1) { # check earlier sample in same layer + if (not_nd_na(res_raw[i - 1, j])) res_raw[i, j] <- "nda" + } + if (i < nrow(res_raw)) { # check later sample + if (not_nd_na(res_raw[i + 1, j])) res_raw[i, j] <- "nda" + } + if (j > 1) { # check above sample at the same time + if (not_nd_na(res_raw[i, j - 1])) res_raw[i, j] <- "nda" + } + if (j < ncol(res_raw)) { # check sample below at the same time + if (not_nd_na(res_raw[i, j + 1])) res_raw[i, j] <- "nda" + } + } + } + } + res_raw[res_raw == "nda"] <- nda + res_raw[res_raw == "nd"] <- NA + + result <- as.numeric(res_raw) + dim(result) <- dim(res_raw) + dimnames(result) <- dimnames(res_raw) + if (was_vector) result <- as.vector(result) + return(result) +} + +#' @describeIn set_nd_nq Set non-detects in residue time series according to FOCUS rules +#' @param set_first_sample_nd Should the first sample be set to "first_sample_nd_value" +#' in case it is a non-detection? +#' @param first_sample_nd_value Value to be used for the first sample if it is a non-detection +#' @param ignore_below_loq_after_first_nd Should we ignore values below the LOQ after the first +#' non-detection that occurs after the quantified values? +#' @export +set_nd_nq_focus <- function(res_raw, lod, loq = NA, + set_first_sample_nd = TRUE, first_sample_nd_value = 0, + ignore_below_loq_after_first_nd = TRUE) +{ + + if (!is.vector(res_raw)) stop("FOCUS rules are only specified for one-dimensional time series") + + if (ignore_below_loq_after_first_nd & is.na(loq)) { + stop("You need to specify an LOQ") + } + + n <- length(res_raw) + if (ignore_below_loq_after_first_nd) { + for (i in 3:n) { + if (!res_raw[i - 2] %in% c("na", "nd")) { + if (res_raw[i - 1] == "nd") { + res_remaining <- res_raw[i:n] + res_remaining_unquantified <- ifelse(res_remaining == "na", TRUE, + ifelse(res_remaining == "nd", TRUE, + ifelse(res_remaining == "nq", TRUE, + ifelse(suppressWarnings(as.numeric(res_remaining)) < loq, TRUE, FALSE)))) + res_remaining_numeric <- suppressWarnings(as.numeric(res_remaining)) + res_remaining_below_loq <- ifelse(res_remaining == "nq", TRUE, + ifelse(!is.na(res_remaining_numeric) & res_remaining_numeric < loq, TRUE, FALSE)) + if (all(res_remaining_unquantified)) { + res_raw[i:n] <- ifelse(res_remaining_below_loq, "nd", res_remaining) + } + } + } + } + } + + result <- set_nd_nq(res_raw, lod = lod, loq = loq) + + if (set_first_sample_nd) { + if (res_raw[1] == "nd") result[1] <- first_sample_nd_value + } + + return(result) +} diff --git a/_pkgdown.yml b/_pkgdown.yml index e12082d..b40e223 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -18,7 +18,7 @@ reference: - pfm_degradation - SFO_actual_twa - FOMC_actual_twa - - set_nd + - set_nd_nq - title: Predicted environmental concentrations in soil contents: - PEC_soil diff --git a/docs/reference/index.html b/docs/reference/index.html index 455ee07..e9c7098 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -170,9 +170,14 @@ </tr><tr> <td> - <p><code><a href="set_nd.html">set_nd()</a></code> <code><a href="set_nd.html">set_nd_focus()</a></code> </p> - </td> - <td><p>Set non-detects in residue series without replicates</p></td> + <p><code><a href="set_nd_nq.html">set_nd_nq()</a></code> <code><a href="set_nd_nq.html">set_nd_nq_focus()</a></code> </p> + </td> + <td><p>Set non-detects and unquantified values in residue series without replicates +This function automates replacing unquantified values in residue time and +depth series. For time series, the function performs part of the residue +processing proposed in the FOCUS kinetics guidance for parent compounds +and metabolites. For two-dimensional residue series over time and depth, +it automates the proposal of Boesten et al (2015).</p></td> </tr> </tbody><tbody> <tr> diff --git a/docs/reference/set_nd.html b/docs/reference/set_nd.html deleted file mode 100644 index 7b0e779..0000000 --- a/docs/reference/set_nd.html +++ /dev/null @@ -1,222 +0,0 @@ -<!-- Generated by pkgdown: do not edit by hand --> -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8"> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<meta name="viewport" content="width=device-width, initial-scale=1.0"> - -<title>Set non-detects in residue series without replicates — set_nd • pfm</title> - -<!-- jquery --> -<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> -<!-- Bootstrap --> - -<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" /> -<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script> - -<!-- Font Awesome icons --> -<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/all.min.css" integrity="sha256-nAmazAk6vS34Xqo0BSrTb+abbtFlgsFK7NKSi6o7Y78=" crossorigin="anonymous" /> -<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/v4-shims.min.css" integrity="sha256-6qHlizsOWFskGlwVOKuns+D1nB6ssZrHQrNj1wGplHc=" crossorigin="anonymous" /> - -<!-- clipboard.js --> -<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script> - -<!-- headroom.js --> -<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/headroom.min.js" integrity="sha256-DJFC1kqIhelURkuza0AvYal5RxMtpzLjFhsnVIeuk+U=" crossorigin="anonymous"></script> -<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script> - -<!-- pkgdown --> -<link href="../pkgdown.css" rel="stylesheet"> -<script src="../pkgdown.js"></script> - - - -<meta property="og:title" content="Set non-detects in residue series without replicates — set_nd" /> - -<meta property="og:description" content="Sets non-detects directly before or directly after detects to NA. Values between -lod and loq are set to their mean value if an loq is specified. -If 'time_zero' is set to TRUE, the residue series is assumed to start with time -zero, and non-detects at time zero are set to 'time_zero_nd_value'. For the -set_nd_focus variant, this is zero, otherwise this argument has NA as default -value. -If stopping after the first non-detection is requested, as in in the FOCUS -variant of the function, an loq has to be specified in order to decide -if any later detections are above the loq." /> -<meta name="twitter:card" content="summary" /> - - - -<!-- mathjax --> -<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script> -<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script> - -<!--[if lt IE 9]> -<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> -<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> -<![endif]--> - - - - </head> - - <body> - <div class="container template-reference-topic"> - <header> - <div class="navbar navbar-default navbar-fixed-top" role="navigation"> - <div class="container"> - <div class="navbar-header"> - <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false"> - <span class="sr-only">Toggle navigation</span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - </button> - <span class="navbar-brand"> - <a class="navbar-link" href="../index.html">pfm</a> - <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.5.7</span> - </span> - </div> - - <div id="navbar" class="navbar-collapse collapse"> - <ul class="nav navbar-nav"> - <li> - <a href="../index.html"> - <span class="fas fa fas fa-home fa-lg"></span> - - </a> -</li> -<li> - <a href="../reference/index.html">Reference</a> -</li> - </ul> - - <ul class="nav navbar-nav navbar-right"> - - </ul> - - </div><!--/.nav-collapse --> - </div><!--/.container --> -</div><!--/.navbar --> - - - - </header> - -<div class="row"> - <div class="col-md-9 contents"> - <div class="page-header"> - <h1>Set non-detects in residue series without replicates</h1> - - <div class="hidden name"><code>set_nd.Rd</code></div> - </div> - - <div class="ref-description"> - - <p>Sets non-detects directly before or directly after detects to NA. Values between -lod and loq are set to their mean value if an loq is specified. -If 'time_zero' is set to TRUE, the residue series is assumed to start with time -zero, and non-detects at time zero are set to 'time_zero_nd_value'. For the -set_nd_focus variant, this is zero, otherwise this argument has NA as default -value. -If stopping after the first non-detection is requested, as in in the FOCUS -variant of the function, an loq has to be specified in order to decide -if any later detections are above the loq.</p> - - </div> - - <pre class="usage"><span class='fu'>set_nd</span>(<span class='no'>r</span>, <span class='no'>lod</span>, <span class='kw'>loq</span> <span class='kw'>=</span> <span class='fl'>NA</span>, <span class='kw'>time_zero</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>, <span class='kw'>time_zero_nd_value</span> <span class='kw'>=</span> <span class='fl'>NA</span>, - <span class='kw'>stop_after_first_nondetect</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>) - -<span class='fu'>set_nd_focus</span>(<span class='no'>r</span>, <span class='no'>lod</span>, <span class='kw'>loq</span> <span class='kw'>=</span> <span class='fl'>NA</span>, <span class='kw'>time_zero</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)</pre> - - <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2> - <table class="ref-arguments"> - <colgroup><col class="name" /><col class="desc" /></colgroup> - <tr> - <th>r</th> - <td><p>A character vector of sequential residues without replicates, with -non-detects specified as 'nd' and unquantified values above the limit of -detection specified as 'nq', otherwise coercible to numeric</p></td> - </tr> - <tr> - <th>lod</th> - <td><p>Limit of detection (numeric)</p></td> - </tr> - <tr> - <th>loq</th> - <td><p>Limit of quantification(numeric). Must be specified if the FOCUS rule to -stop after the first non-detection is to be applied</p></td> - </tr> - <tr> - <th>time_zero</th> - <td><p>Is the first value in the series a time zero value?</p></td> - </tr> - <tr> - <th>time_zero_nd_value</th> - <td><p>Which value should we use for non-detects or zero values at time zero?</p></td> - </tr> - <tr> - <th>stop_after_first_nondetect</th> - <td><p>Should we really stop after the first non-detection?</p></td> - </tr> - </table> - - <h2 class="hasAnchor" id="functions"><a class="anchor" href="#functions"></a>Functions</h2> - - -<ul> -<li><p><code>set_nd</code>: Set non-detects in residues series</p></li> -<li><p><code>set_nd_focus</code>: Set non-detects in residues series according to FOCUS rules</p></li> -</ul> - - <h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2> - - <p>FOCUS (2014) Generic Guidance for Estimating Persistence and Degradation - Kinetics from Environmental Fate Studies on Pesticides in EU Registration, Version 1.1, - 18 December 2014, p. 251</p> - - - <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2> - <pre class="examples"><div class='input'><span class='co'># FOCUS (2014) p. 75/76 and 131/132</span> -<span class='no'>parent_1</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>.12</span>, <span class='fl'>.09</span>, <span class='fl'>.05</span>, <span class='fl'>.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>) -<span class='fu'>set_nd</span>(<span class='no'>parent_1</span>, <span class='fl'>0.02</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 NA NA NA NA NA</div><div class='input'><span class='no'>parent_2</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>.12</span>, <span class='fl'>.09</span>, <span class='fl'>.05</span>, <span class='fl'>.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='fl'>.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>) -<span class='fu'>set_nd</span>(<span class='no'>parent_2</span>, <span class='fl'>0.02</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 0.01 0.03 0.01 NA NA</div><div class='input'><span class='fu'>set_nd_focus</span>(<span class='no'>parent_2</span>, <span class='fl'>0.02</span>, <span class='kw'>loq</span> <span class='kw'>=</span> <span class='fl'>0.05</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 NA NA NA NA NA</div><div class='input'><span class='no'>parent_3</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>.12</span>, <span class='fl'>.09</span>, <span class='fl'>.05</span>, <span class='fl'>.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='fl'>.06</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>) -<span class='fu'>set_nd</span>(<span class='no'>parent_3</span>, <span class='fl'>0.02</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 0.01 0.06 0.01 NA NA</div><div class='input'><span class='fu'>set_nd_focus</span>(<span class='no'>parent_3</span>, <span class='fl'>0.02</span>, <span class='kw'>loq</span> <span class='kw'>=</span> <span class='fl'>0.05</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 0.01 0.06 0.01 NA NA</div><div class='input'><span class='no'>metabolite</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='fl'>0.03</span>, <span class='fl'>0.06</span>, <span class='fl'>0.10</span>, <span class='fl'>0.11</span>, <span class='fl'>0.10</span>, <span class='fl'>0.09</span>, <span class='fl'>0.05</span>, <span class='fl'>0.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>) -<span class='fu'>set_nd</span>(<span class='no'>metabolite</span>, <span class='fl'>0.02</span>)</div><div class='output co'>#> [1] NA NA 0.01 0.03 0.06 0.10 0.11 0.10 0.09 0.05 0.03 0.01 NA</div></pre> - </div> - <div class="col-md-3 hidden-xs hidden-sm" id="sidebar"> - <h2>Contents</h2> - <ul class="nav nav-pills nav-stacked"> - <li><a href="#arguments">Arguments</a></li> - - <li><a href="#functions">Functions</a></li> - - <li><a href="#references">References</a></li> - - <li><a href="#examples">Examples</a></li> - </ul> - - </div> -</div> - - - <footer> - <div class="copyright"> - <p>Developed by Johannes Ranke.</p> -</div> - -<div class="pkgdown"> - <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.4.1.</p> -</div> - - </footer> - </div> - - - - - </body> -</html> - - diff --git a/docs/reference/set_nd_nq.html b/docs/reference/set_nd_nq.html new file mode 100644 index 0000000..ff751dd --- /dev/null +++ b/docs/reference/set_nd_nq.html @@ -0,0 +1,284 @@ +<!-- Generated by pkgdown: do not edit by hand --> +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> +<meta http-equiv="X-UA-Compatible" content="IE=edge"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> + +<title>Set non-detects and unquantified values in residue series without replicates +This function automates replacing unquantified values in residue time and +depth series. For time series, the function performs part of the residue +processing proposed in the FOCUS kinetics guidance for parent compounds +and metabolites. For two-dimensional residue series over time and depth, +it automates the proposal of Boesten et al (2015). — set_nd_nq • pfm</title> + +<!-- jquery --> +<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> +<!-- Bootstrap --> + +<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" /> +<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script> + +<!-- Font Awesome icons --> +<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/all.min.css" integrity="sha256-nAmazAk6vS34Xqo0BSrTb+abbtFlgsFK7NKSi6o7Y78=" crossorigin="anonymous" /> +<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/v4-shims.min.css" integrity="sha256-6qHlizsOWFskGlwVOKuns+D1nB6ssZrHQrNj1wGplHc=" crossorigin="anonymous" /> + +<!-- clipboard.js --> +<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script> + +<!-- headroom.js --> +<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/headroom.min.js" integrity="sha256-DJFC1kqIhelURkuza0AvYal5RxMtpzLjFhsnVIeuk+U=" crossorigin="anonymous"></script> +<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script> + +<!-- pkgdown --> +<link href="../pkgdown.css" rel="stylesheet"> +<script src="../pkgdown.js"></script> + + + +<meta property="og:title" content="Set non-detects and unquantified values in residue series without replicates +This function automates replacing unquantified values in residue time and +depth series. For time series, the function performs part of the residue +processing proposed in the FOCUS kinetics guidance for parent compounds +and metabolites. For two-dimensional residue series over time and depth, +it automates the proposal of Boesten et al (2015). — set_nd_nq" /> + +<meta property="og:description" content="Set non-detects and unquantified values in residue series without replicates +This function automates replacing unquantified values in residue time and +depth series. For time series, the function performs part of the residue +processing proposed in the FOCUS kinetics guidance for parent compounds +and metabolites. For two-dimensional residue series over time and depth, +it automates the proposal of Boesten et al (2015)." /> +<meta name="twitter:card" content="summary" /> + + + +<!-- mathjax --> +<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script> +<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script> + +<!--[if lt IE 9]> +<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> +<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> +<![endif]--> + + + + </head> + + <body> + <div class="container template-reference-topic"> + <header> + <div class="navbar navbar-default navbar-fixed-top" role="navigation"> + <div class="container"> + <div class="navbar-header"> + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + </button> + <span class="navbar-brand"> + <a class="navbar-link" href="../index.html">pfm</a> + <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.5.7</span> + </span> + </div> + + <div id="navbar" class="navbar-collapse collapse"> + <ul class="nav navbar-nav"> + <li> + <a href="../index.html"> + <span class="fas fa fas fa-home fa-lg"></span> + + </a> +</li> +<li> + <a href="../reference/index.html">Reference</a> +</li> + </ul> + + <ul class="nav navbar-nav navbar-right"> + + </ul> + + </div><!--/.nav-collapse --> + </div><!--/.container --> +</div><!--/.navbar --> + + + + </header> + +<div class="row"> + <div class="col-md-9 contents"> + <div class="page-header"> + <h1>Set non-detects and unquantified values in residue series without replicates +This function automates replacing unquantified values in residue time and +depth series. For time series, the function performs part of the residue +processing proposed in the FOCUS kinetics guidance for parent compounds +and metabolites. For two-dimensional residue series over time and depth, +it automates the proposal of Boesten et al (2015).</h1> + + <div class="hidden name"><code>set_nd_nq.Rd</code></div> + </div> + + <div class="ref-description"> + + <p>Set non-detects and unquantified values in residue series without replicates +This function automates replacing unquantified values in residue time and +depth series. For time series, the function performs part of the residue +processing proposed in the FOCUS kinetics guidance for parent compounds +and metabolites. For two-dimensional residue series over time and depth, +it automates the proposal of Boesten et al (2015).</p> + + </div> + + <pre class="usage"><span class='fu'>set_nd_nq</span>(<span class='no'>res_raw</span>, <span class='no'>lod</span>, <span class='kw'>loq</span> <span class='kw'>=</span> <span class='fl'>NA</span>, <span class='kw'>time_zero_presence</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>) + +<span class='fu'>set_nd_nq_focus</span>(<span class='no'>res_raw</span>, <span class='no'>lod</span>, <span class='kw'>loq</span> <span class='kw'>=</span> <span class='fl'>NA</span>, <span class='kw'>set_first_sample_nd</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>, + <span class='kw'>first_sample_nd_value</span> <span class='kw'>=</span> <span class='fl'>0</span>, <span class='kw'>ignore_below_loq_after_first_nd</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)</pre> + + <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2> + <table class="ref-arguments"> + <colgroup><col class="name" /><col class="desc" /></colgroup> + <tr> + <th>res_raw</th> + <td><p>Character vector of a residue time series, or matrix of +residue values with rows representing depth profiles for a specific sampling +time, and columns representing time series of residues at the same depth. +Values below the limit of detection (lod) have to be coded as "nd", values +between the limit of detection and the limit of quantification, if any, have +to be coded as "nq". Samples not analysed have to be coded as "na". All +values that are not "na", "nd" or "nq" have to be coercible to numeric</p></td> + </tr> + <tr> + <th>lod</th> + <td><p>Limit of detection (numeric)</p></td> + </tr> + <tr> + <th>loq</th> + <td><p>Limit of quantification(numeric). Must be specified if the FOCUS rule to +stop after the first non-detection is to be applied</p></td> + </tr> + <tr> + <th>time_zero_presence</th> + <td><p>Do we assume that residues occur at time zero? +This only affects samples from the first sampling time that have been +reported as "nd" (not detected).</p></td> + </tr> + <tr> + <th>set_first_sample_nd</th> + <td><p>Should the first sample be set to "first_sample_nd_value" +in case it is a non-detection?</p></td> + </tr> + <tr> + <th>first_sample_nd_value</th> + <td><p>Value to be used for the first sample if it is a non-detection</p></td> + </tr> + <tr> + <th>ignore_below_loq_after_first_nd</th> + <td><p>Should we ignore values below the LOQ after the first +non-detection that occurs after the quantified values?</p></td> + </tr> + </table> + + <h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2> + + <p>A numeric vector, if a vector was supplied, or a numeric matrix otherwise</p> + + <h2 class="hasAnchor" id="functions"><a class="anchor" href="#functions"></a>Functions</h2> + + +<ul> +<li><p><code>set_nd_nq_focus</code>: Set non-detects in residue time series according to FOCUS rules</p></li> +</ul> + + <h2 class="hasAnchor" id="references"><a class="anchor" href="#references"></a>References</h2> + + <p>Boesten, J. J. T. I., van der Linden, A. M. A., Beltman, W. H. +J. and Pol, J. W. (2015). Leaching of plant protection products and their +transformation products; Proposals for improving the assessment of leaching +to groundwater in the Netherlands — Version 2. Alterra report 2630, Alterra +Wageningen UR (University & Research centre)</p> +<p>FOCUS (2014) Generic Guidance for Estimating Persistence and Degradation + Kinetics from Environmental Fate Studies on Pesticides in EU Registration, Version 1.1, + 18 December 2014, p. 251</p> + + + <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2> + <pre class="examples"><div class='input'><span class='co'># FOCUS (2014) p. 75/76 and 131/132</span> +<span class='no'>parent_1</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>.12</span>, <span class='fl'>.09</span>, <span class='fl'>.05</span>, <span class='fl'>.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>) +<span class='fu'>set_nd_nq</span>(<span class='no'>parent_1</span>, <span class='fl'>0.02</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 NA NA NA NA NA</div><div class='input'><span class='no'>parent_2</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>.12</span>, <span class='fl'>.09</span>, <span class='fl'>.05</span>, <span class='fl'>.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='fl'>.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>) +<span class='fu'>set_nd_nq</span>(<span class='no'>parent_2</span>, <span class='fl'>0.02</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 0.01 0.03 0.01 NA NA</div><div class='input'><span class='fu'>set_nd_nq_focus</span>(<span class='no'>parent_2</span>, <span class='fl'>0.02</span>, <span class='kw'>loq</span> <span class='kw'>=</span> <span class='fl'>0.05</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 NA NA NA NA NA</div><div class='input'><span class='no'>parent_3</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>.12</span>, <span class='fl'>.09</span>, <span class='fl'>.05</span>, <span class='fl'>.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='fl'>.06</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>) +<span class='fu'>set_nd_nq</span>(<span class='no'>parent_3</span>, <span class='fl'>0.02</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 0.01 0.06 0.01 NA NA</div><div class='input'><span class='fu'>set_nd_nq_focus</span>(<span class='no'>parent_3</span>, <span class='fl'>0.02</span>, <span class='kw'>loq</span> <span class='kw'>=</span> <span class='fl'>0.05</span>)</div><div class='output co'>#> [1] 0.12 0.09 0.05 0.03 0.01 0.01 0.06 0.01 NA NA</div><div class='input'><span class='no'>metabolite</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, <span class='fl'>0.03</span>, <span class='fl'>0.06</span>, <span class='fl'>0.10</span>, <span class='fl'>0.11</span>, <span class='fl'>0.10</span>, <span class='fl'>0.09</span>, <span class='fl'>0.05</span>, <span class='fl'>0.03</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>) +<span class='fu'>set_nd_nq</span>(<span class='no'>metabolite</span>, <span class='fl'>0.02</span>)</div><div class='output co'>#> [1] NA NA 0.01 0.03 0.06 0.10 0.11 0.10 0.09 0.05 0.03 0.01 NA</div><div class='input'><span class='fu'>set_nd_nq_focus</span>(<span class='no'>metabolite</span>, <span class='fl'>0.02</span>, <span class='fl'>0.05</span>)</div><div class='output co'>#> [1] 0.00 NA 0.01 0.03 0.06 0.10 0.11 0.10 0.09 0.05 0.03 0.01 NA</div><div class='input'><span class='co'>#</span> +<span class='co'># Boesten et al. (2015), p. 57/58</span> +<span class='no'>table_8</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span>( + <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>10</span>, <span class='fl'>10</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>4</span>), + <span class='fl'>10</span>, <span class='fl'>10</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nq"</span>, <span class='fl'>2</span>), <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>2</span>), + <span class='fl'>10</span>, <span class='fl'>10</span>, <span class='fl'>10</span>, <span class='st'>"nq"</span>, <span class='st'>"nd"</span>, <span class='st'>"nd"</span>, + <span class='st'>"nq"</span>, <span class='fl'>10</span>, <span class='st'>"nq"</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>3</span>), + <span class='st'>"nd"</span>, <span class='st'>"nq"</span>, <span class='st'>"nq"</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>3</span>), + <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>6</span>), <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>6</span>)), + <span class='kw'>ncol</span> <span class='kw'>=</span> <span class='fl'>6</span>, <span class='kw'>byrow</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>) +<span class='fu'>set_nd_nq</span>(<span class='no'>table_8</span>, <span class='fl'>0.5</span>, <span class='fl'>1.5</span>, <span class='kw'>time_zero_presence</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)</div><div class='output co'>#> [,1] [,2] [,3] [,4] [,5] [,6] +#> [1,] 10.00 10.00 0.25 0.25 NA NA +#> [2,] 10.00 10.00 1.00 1.00 0.25 NA +#> [3,] 10.00 10.00 10.00 1.00 0.25 NA +#> [4,] 1.00 10.00 1.00 0.25 NA NA +#> [5,] 0.25 1.00 1.00 0.25 NA NA +#> [6,] NA 0.25 0.25 NA NA NA +#> [7,] NA NA NA NA NA NA</div><div class='input'><span class='no'>table_10</span> <span class='kw'><-</span> <span class='fu'><a href='https://rdrr.io/r/base/matrix.html'>matrix</a></span>( + <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>10</span>, <span class='fl'>10</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>4</span>), + <span class='fl'>10</span>, <span class='fl'>10</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>4</span>), + <span class='fl'>10</span>, <span class='fl'>10</span>, <span class='fl'>10</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>3</span>), + <span class='st'>"nd"</span>, <span class='fl'>10</span>, <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>4</span>), + <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='st'>"nd"</span>, <span class='fl'>18</span>)), + <span class='kw'>ncol</span> <span class='kw'>=</span> <span class='fl'>6</span>, <span class='kw'>byrow</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>) +<span class='fu'>set_nd_nq</span>(<span class='no'>table_10</span>, <span class='fl'>0.5</span>, <span class='kw'>time_zero_presence</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)</div><div class='output co'>#> [,1] [,2] [,3] [,4] [,5] [,6] +#> [1,] 10.00 10.00 0.25 NA NA NA +#> [2,] 10.00 10.00 0.25 NA NA NA +#> [3,] 10.00 10.00 10.00 0.25 NA NA +#> [4,] 0.25 10.00 0.25 NA NA NA +#> [5,] NA 0.25 NA NA NA NA +#> [6,] NA NA NA NA NA NA +#> [7,] NA NA NA NA NA NA</div></pre> + </div> + <div class="col-md-3 hidden-xs hidden-sm" id="sidebar"> + <h2>Contents</h2> + <ul class="nav nav-pills nav-stacked"> + <li><a href="#arguments">Arguments</a></li> + + <li><a href="#value">Value</a></li> + + <li><a href="#functions">Functions</a></li> + + <li><a href="#references">References</a></li> + + <li><a href="#examples">Examples</a></li> + </ul> + + </div> +</div> + + + <footer> + <div class="copyright"> + <p>Developed by Johannes Ranke.</p> +</div> + +<div class="pkgdown"> + <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.4.1.</p> +</div> + + </footer> + </div> + + + + + </body> +</html> + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 79d9b14..b619e4d 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -100,7 +100,7 @@ <loc>https://pkgdown.jrwb.de/pfm/reference/sawtooth.html</loc> </url> <url> - <loc>https://pkgdown.jrwb.de/pfm/reference/set_nd.html</loc> + <loc>https://pkgdown.jrwb.de/pfm/reference/set_nd_nq.html</loc> </url> <url> <loc>https://pkgdown.jrwb.de/pfm/reference/soil_scenario_data_EFSA_2015.html</loc> diff --git a/man/set_nd.Rd b/man/set_nd.Rd deleted file mode 100644 index cef2705..0000000 --- a/man/set_nd.Rd +++ /dev/null @@ -1,64 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/set_nd.R -\name{set_nd} -\alias{set_nd} -\alias{set_nd_focus} -\title{Set non-detects in residue series without replicates} -\usage{ -set_nd(r, lod, loq = NA, time_zero = TRUE, time_zero_nd_value = NA, - stop_after_first_nondetect = FALSE) - -set_nd_focus(r, lod, loq = NA, time_zero = TRUE) -} -\arguments{ -\item{r}{A character vector of sequential residues without replicates, with -non-detects specified as 'nd' and unquantified values above the limit of -detection specified as 'nq', otherwise coercible to numeric} - -\item{lod}{Limit of detection (numeric)} - -\item{loq}{Limit of quantification(numeric). Must be specified if the FOCUS rule to -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 at time zero?} - -\item{stop_after_first_nondetect}{Should we really stop after the first non-detection?} -} -\description{ -Sets non-detects directly before or directly after detects to NA. Values between -lod and loq are set to their mean value if an loq is specified. -If 'time_zero' is set to TRUE, the residue series is assumed to start with time -zero, and non-detects at time zero are set to 'time_zero_nd_value'. For the -set_nd_focus variant, this is zero, otherwise this argument has NA as default -value. -If stopping after the first non-detection is requested, as in in the FOCUS -variant of the function, an loq has to be specified in order to decide -if any later detections are above the loq. -} -\section{Functions}{ -\itemize{ -\item \code{set_nd}: Set non-detects in residues series - -\item \code{set_nd_focus}: Set non-detects in residues series according to FOCUS rules -}} - -\examples{ -# FOCUS (2014) p. 75/76 and 131/132 -parent_1 <- c(.12, .09, .05, .03, "nd", "nd", "nd", "nd", "nd", "nd") -set_nd(parent_1, 0.02) -parent_2 <- c(.12, .09, .05, .03, "nd", "nd", .03, "nd", "nd", "nd") -set_nd(parent_2, 0.02) -set_nd_focus(parent_2, 0.02, loq = 0.05) -parent_3 <- c(.12, .09, .05, .03, "nd", "nd", .06, "nd", "nd", "nd") -set_nd(parent_3, 0.02) -set_nd_focus(parent_3, 0.02, loq = 0.05) -metabolite <- c("nd", "nd", "nd", 0.03, 0.06, 0.10, 0.11, 0.10, 0.09, 0.05, 0.03, "nd", "nd") -set_nd(metabolite, 0.02) -} -\references{ -FOCUS (2014) Generic Guidance for Estimating Persistence and Degradation - Kinetics from Environmental Fate Studies on Pesticides in EU Registration, Version 1.1, - 18 December 2014, p. 251 -} diff --git a/man/set_nd_nq.Rd b/man/set_nd_nq.Rd new file mode 100644 index 0000000..b2da429 --- /dev/null +++ b/man/set_nd_nq.Rd @@ -0,0 +1,103 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_nd_nq.R +\name{set_nd_nq} +\alias{set_nd_nq} +\alias{set_nd_nq_focus} +\title{Set non-detects and unquantified values in residue series without replicates +This function automates replacing unquantified values in residue time and +depth series. For time series, the function performs part of the residue +processing proposed in the FOCUS kinetics guidance for parent compounds +and metabolites. For two-dimensional residue series over time and depth, +it automates the proposal of Boesten et al (2015).} +\usage{ +set_nd_nq(res_raw, lod, loq = NA, time_zero_presence = FALSE) + +set_nd_nq_focus(res_raw, lod, loq = NA, set_first_sample_nd = TRUE, + first_sample_nd_value = 0, ignore_below_loq_after_first_nd = TRUE) +} +\arguments{ +\item{res_raw}{Character vector of a residue time series, or matrix of +residue values with rows representing depth profiles for a specific sampling +time, and columns representing time series of residues at the same depth. +Values below the limit of detection (lod) have to be coded as "nd", values +between the limit of detection and the limit of quantification, if any, have +to be coded as "nq". Samples not analysed have to be coded as "na". All +values that are not "na", "nd" or "nq" have to be coercible to numeric} + +\item{lod}{Limit of detection (numeric)} + +\item{loq}{Limit of quantification(numeric). Must be specified if the FOCUS rule to +stop after the first non-detection is to be applied} + +\item{time_zero_presence}{Do we assume that residues occur at time zero? +This only affects samples from the first sampling time that have been +reported as "nd" (not detected).} + +\item{set_first_sample_nd}{Should the first sample be set to "first_sample_nd_value" +in case it is a non-detection?} + +\item{first_sample_nd_value}{Value to be used for the first sample if it is a non-detection} + +\item{ignore_below_loq_after_first_nd}{Should we ignore values below the LOQ after the first +non-detection that occurs after the quantified values?} +} +\value{ +A numeric vector, if a vector was supplied, or a numeric matrix otherwise +} +\description{ +Set non-detects and unquantified values in residue series without replicates +This function automates replacing unquantified values in residue time and +depth series. For time series, the function performs part of the residue +processing proposed in the FOCUS kinetics guidance for parent compounds +and metabolites. For two-dimensional residue series over time and depth, +it automates the proposal of Boesten et al (2015). +} +\section{Functions}{ +\itemize{ +\item \code{set_nd_nq_focus}: Set non-detects in residue time series according to FOCUS rules +}} + +\examples{ +# FOCUS (2014) p. 75/76 and 131/132 +parent_1 <- c(.12, .09, .05, .03, "nd", "nd", "nd", "nd", "nd", "nd") +set_nd_nq(parent_1, 0.02) +parent_2 <- c(.12, .09, .05, .03, "nd", "nd", .03, "nd", "nd", "nd") +set_nd_nq(parent_2, 0.02) +set_nd_nq_focus(parent_2, 0.02, loq = 0.05) +parent_3 <- c(.12, .09, .05, .03, "nd", "nd", .06, "nd", "nd", "nd") +set_nd_nq(parent_3, 0.02) +set_nd_nq_focus(parent_3, 0.02, loq = 0.05) +metabolite <- c("nd", "nd", "nd", 0.03, 0.06, 0.10, 0.11, 0.10, 0.09, 0.05, 0.03, "nd", "nd") +set_nd_nq(metabolite, 0.02) +set_nd_nq_focus(metabolite, 0.02, 0.05) +# +# Boesten et al. (2015), p. 57/58 +table_8 <- matrix( + c(10, 10, rep("nd", 4), + 10, 10, rep("nq", 2), rep("nd", 2), + 10, 10, 10, "nq", "nd", "nd", + "nq", 10, "nq", rep("nd", 3), + "nd", "nq", "nq", rep("nd", 3), + rep("nd", 6), rep("nd", 6)), + ncol = 6, byrow = TRUE) +set_nd_nq(table_8, 0.5, 1.5, time_zero_presence = TRUE) +table_10 <- matrix( + c(10, 10, rep("nd", 4), + 10, 10, rep("nd", 4), + 10, 10, 10, rep("nd", 3), + "nd", 10, rep("nd", 4), + rep("nd", 18)), + ncol = 6, byrow = TRUE) +set_nd_nq(table_10, 0.5, time_zero_presence = TRUE) +} +\references{ +Boesten, J. J. T. I., van der Linden, A. M. A., Beltman, W. H. +J. and Pol, J. W. (2015). Leaching of plant protection products and their +transformation products; Proposals for improving the assessment of leaching +to groundwater in the Netherlands — Version 2. Alterra report 2630, Alterra +Wageningen UR (University & Research centre) + +FOCUS (2014) Generic Guidance for Estimating Persistence and Degradation + Kinetics from Environmental Fate Studies on Pesticides in EU Registration, Version 1.1, + 18 December 2014, p. 251 +} @@ -5,11 +5,11 @@ Testing pfm ✔ | OK F W S | Context
⠏ | 0 | Exposit calculations
✔ | 7 | Exposit calculations
⠏ | 0 | Geometric mean calculation
✔ | 6 | Geometric mean calculation -
⠏ | 0 | Check max_twa for parent mkinfit models against analytical solutions
⠋ | 1 | Check max_twa for parent mkinfit models against analytical solutions
✔ | 1 | Check max_twa for parent mkinfit models against analytical solutions [1.9 s] +
⠏ | 0 | Check max_twa for parent mkinfit models against analytical solutions
⠋ | 1 | Check max_twa for parent mkinfit models against analytical solutions
✔ | 1 | Check max_twa for parent mkinfit models against analytical solutions [1.0 s]
⠏ | 0 | Simple PEC sediment calculations
✔ | 1 | Simple PEC sediment calculations
⠏ | 0 | Simple PEC soil calculations
⠙ | 2 | Simple PEC soil calculations
✔ | 17 | Simple PEC soil calculations [0.2 s]
⠏ | 0 | Simple PEC surface water calculations with drift entry
✔ | 2 | Simple PEC surface water calculations with drift entry -
⠏ | 0 | Processing of residue series
✔ | 8 | Processing of residue series +
⠏ | 0 | Processing of residue series
✔ | 11 | Processing of residue series
⠏ | 0 | Actual and time weighted average concentrations for SFO kinetics
✔ | 1 | Actual and time weighted average concentrations for SFO kinetics
⠏ | 0 | FOCUS Step 1 calculations
⠹ | 3 | FOCUS Step 1 calculations
✔ | 9 | FOCUS Step 1 calculations [0.1 s]
⠏ | 0 | FOCUS Steps 12 input files
✔ | 8 | FOCUS Steps 12 input files @@ -17,9 +17,9 @@ Testing pfm
⠏ | 0 | UK drainage PEC calculations
✔ | 12 | UK drainage PEC calculations ══ Results ═════════════════════════════════════════════════════════════════════════════════════════ -Duration: 8.0 s +Duration: 7.0 s -OK: 79 +OK: 82 Failed: 0 Warnings: 0 Skipped: 0 diff --git a/tests/testthat/test_set_nd.R b/tests/testthat/test_set_nd.R index 6b73e2d..232e7c6 100644 --- a/tests/testthat/test_set_nd.R +++ b/tests/testthat/test_set_nd.R @@ -1,4 +1,5 @@ context("Processing of residue series") + # FOCUS (2014) page 76 (parent) and page 132 (metabolite) parent_1 <- c(.12, .09, .05, .03, "nd", "nd", "nd", "nd", "nd", "nd") @@ -6,39 +7,80 @@ parent_2 <- c(.12, .09, .05, .03, "nd", "nd", .03, "nd", "nd", "nd") parent_3 <- c(.12, .09, .05, .03, "nd", "nd", .06, "nd", "nd", "nd") metabolite <- c("nd", "nd", "nd", 0.03, 0.06, 0.10, 0.11, 0.10, 0.09, 0.05, 0.03, "nd", "nd") -test_that("Simple residue series processed as intended", { +test_that("Simple residue series are processed as intended", { - expect_equal(set_nd(parent_1, 0.02), + expect_equal(set_nd_nq(parent_1, 0.02), c(.12, .09, .05, .03, .01, rep(NA, 5))) - expect_equal(set_nd(parent_2, 0.02, loq = 0.05), + expect_equal(set_nd_nq(parent_2, 0.02, loq = 0.05), c(.12, .09, .05, .03, .01, .01, .03, .01, NA, NA)) - expect_equal(set_nd(metabolite, 0.02, loq = 0.05), + expect_equal(set_nd_nq(metabolite, 0.02, loq = 0.05), c(NA, NA, .01, .03, .06, .1, .11, .1, .09, .05, .03, .01, NA)) - expect_equal(set_nd(c("nd", 1, 0.2, "nd"), 0.1), c(NA, 1, 0.2, 0.05)) + expect_equal(set_nd_nq(c("nd", 1, 0.2, "nd"), 0.1), + c(NA, 1, 0.2, 0.05)) }) test_that("Simple residue series are processed as in the FOCUS guidance", { # Parent 1 - expect_error(set_nd_focus(parent_1, 0.02), - "You need to specify an loq") - expect_equal(set_nd_focus(parent_1, 0.02, 0.05), + expect_error(set_nd_nq_focus(parent_1, 0.02), + "You need to specify an LOQ") + expect_equal(set_nd_nq_focus(parent_1, 0.02, 0.05), c(.12, .09, .05, .03, .01, rep(NA, 5))) # Parent 2 - expect_equal(set_nd_focus(parent_2, 0.02, loq = 0.05), + expect_equal(set_nd_nq_focus(parent_2, 0.02, loq = 0.05), c(.12, .09, .05, .03, .01, rep(NA, 5))) # Parent 3 - expect_equal(set_nd_focus(parent_3, 0.02, loq = 0.05), + expect_equal(set_nd_nq_focus(parent_3, 0.02, loq = 0.05), c(.12, .09, .05, .03, .01, .01, .06, .01, NA, NA)) # Metabolite - expect_equal(set_nd_focus(metabolite, 0.02, loq = 0.05), + expect_equal(set_nd_nq_focus(metabolite, 0.02, loq = 0.05), c(0, NA, .01, .03, .06, .1, .11, .1, .09, .05, .03, .01, NA)) }) + +test_that("Examples Boesten et al. (2015, p. 57/58) are correctly processed", { + table_8 <- matrix( + c(10, 10, rep("nd", 4), + 10, 10, rep("nq", 2), rep("nd", 2), + 10, 10, 10, "nq", "nd", "nd", + "nq", 10, "nq", rep("nd", 3), + "nd", "nq", "nq", rep("nd", 3), + rep("nd", 6), rep("nd", 6)), + ncol = 6, byrow = TRUE) + table_8_processed <- set_nd_nq(table_8, 0.5, 1.5, time_zero_presence = TRUE) + table_9 <- matrix( + c(10, 10, 0.25, 0.25, NA, NA, + 10, 10, 1, 1, 0.25, NA, + 10, 10, 10, 1, 0.25, NA, + 1, 10, 1, 0.25, NA, NA, + 0.25, 1, 1, 0.25, NA, NA, + NA, 0.25, 0.25, NA, NA, NA, + rep(NA, 6)), + ncol = 6, byrow = TRUE) + expect_equal(table_8_processed, table_9) + + table_10 <- matrix( + c(10, 10, rep("nd", 4), + 10, 10, rep("nd", 4), + 10, 10, 10, rep("nd", 3), + "nd", 10, rep("nd", 4), + rep("nd", 18)), + ncol = 6, byrow = TRUE) + table_10_processed <- set_nd_nq(table_10, 0.5, time_zero_presence = TRUE) + table_11 <- matrix( + c(10, 10, 0.25, rep(NA, 3), + 10, 10, 0.25, rep(NA, 3), + 10, 10, 10, 0.25, NA, NA, + 0.25, 10, 0.25, rep(NA, 3), + NA, 0.25, rep(NA, 4), + rep(NA, 12)), + ncol = 6, byrow = TRUE) + expect_equal(table_10_processed, table_11) +}) |