Skip to content
Snippets Groups Projects
Commit e3dd90d7 authored by Sebastian Henz's avatar Sebastian Henz
Browse files

Add curves_concentration_max argument to ecxsys(),

closes #29
parent 34e495cd
No related branches found
No related tags found
1 merge request!21curves_concentration_max and ec error
# stressaddition (development version) # stressaddition (development version)
* `ec()` raises an error if the curve does not cross the desired response level. * `ec()` raises an error if the curve does not cross the desired response level.
* `ecxsys()` gains a new argument `curves_concentration_max` which allows setting the maximum concentration of the predicted curves.
# stressaddition 2.1.1 # stressaddition 2.1.1
......
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
#' environmental stress. Must be between 0 and \code{effect_max}. #' environmental stress. Must be between 0 and \code{effect_max}.
#' @param effect_max The maximum value the effect could possibly reach. For #' @param effect_max The maximum value the effect could possibly reach. For
#' survival data in percent this should be 100 (the default). #' survival data in percent this should be 100 (the default).
#' @param curves_concentration_max The maximum concentration of the predicted
#' curves. This might be useful if for example your highest observed
#' concentration is 30 but you would like to know the predicted values at 100.
#' @param p,q The shape parameters of the beta distribution. Default is 3.2. #' @param p,q The shape parameters of the beta distribution. Default is 3.2.
#' #'
#' @return A list (of class ecxsys) containing many different objects of which #' @return A list (of class ecxsys) containing many different objects of which
...@@ -86,6 +89,7 @@ ecxsys <- function(concentration, ...@@ -86,6 +89,7 @@ ecxsys <- function(concentration,
effect_tox_observed, effect_tox_observed,
effect_tox_env_observed = NULL, effect_tox_env_observed = NULL,
effect_max = 100, effect_max = 100,
curves_concentration_max = NULL,
p = 3.2, p = 3.2,
q = 3.2) { q = 3.2) {
output <- list(args = as.list(environment())) output <- list(args = as.list(environment()))
...@@ -268,23 +272,32 @@ ecxsys <- function(concentration, ...@@ -268,23 +272,32 @@ ecxsys <- function(concentration,
} }
# smooth curves ------------------------------------------------------- # curves -------------------------------------------------------
# In order to generate a broken x-axis the concentration vector must # In order to generate a broken x-axis the concentration vector must
# also be broken in two. The left part of the axis is supposed to be at # also be broken in two. The left part of the axis is supposed to be at
# 0 but because it's a log axis I have to make the values just really # 0 but because it's a log axis I have to make the values just really
# small. The concentrations in the gap won't be used for plotting later. # small. The concentrations in the gap won't be used for plotting later.
n_smooth <- 1000 # number of points to approximate the curves len_curves <- 1000 # number of points to approximate the curves
conc_adjust_factor <- 10^-5 conc_adjust_factor <- 10^-5
output$conc_adjust_factor <- conc_adjust_factor output$conc_adjust_factor <- conc_adjust_factor
concentration_smooth <- 10 ^ seq( if (is.null(curves_concentration_max)) {
curves_concentration_max <- max(concentration)
} else if (curves_concentration_max < max(concentration)) {
if (curves_concentration_max < min(concentration[concentration > 0])) {
stop("'curves_concentration_max' is too low.")
}
warning("Your chosen value for 'curves_concentration_max' is less ",
"than the maximum observed concentration.")
}
curves_concentration <- 10 ^ seq(
log10(min_conc * conc_adjust_factor), log10(min_conc * conc_adjust_factor),
log10(max(concentration)), log10(curves_concentration_max),
length.out = n_smooth length.out = len_curves
) )
output$curves <- predict_ecxsys(output, concentration_smooth) output$curves <- predict_ecxsys(output, curves_concentration)
output$curves$use_for_plotting <- output$curves$use_for_plotting <-
concentration_smooth < min_conc * conc_adjust_factor * 1.5 | curves_concentration < min_conc * conc_adjust_factor * 1.5 |
concentration_smooth > min_conc * 1.5 curves_concentration > min_conc * 1.5
output output
} }
......
...@@ -10,6 +10,7 @@ ecxsys( ...@@ -10,6 +10,7 @@ ecxsys(
effect_tox_observed, effect_tox_observed,
effect_tox_env_observed = NULL, effect_tox_env_observed = NULL,
effect_max = 100, effect_max = 100,
curves_concentration_max = NULL,
p = 3.2, p = 3.2,
q = 3.2 q = 3.2
) )
...@@ -31,6 +32,10 @@ environmental stress. Must be between 0 and \code{effect_max}.} ...@@ -31,6 +32,10 @@ environmental stress. Must be between 0 and \code{effect_max}.}
\item{effect_max}{The maximum value the effect could possibly reach. For \item{effect_max}{The maximum value the effect could possibly reach. For
survival data in percent this should be 100 (the default).} survival data in percent this should be 100 (the default).}
\item{curves_concentration_max}{The maximum concentration of the predicted
curves. This might be useful if for example your highest observed
concentration is 30 but you would like to know the predicted values at 100.}
\item{p, q}{The shape parameters of the beta distribution. Default is 3.2.} \item{p, q}{The shape parameters of the beta distribution. Default is 3.2.}
} }
\value{ \value{
......
...@@ -164,6 +164,7 @@ test_that("function arguments are returned unchanged", { ...@@ -164,6 +164,7 @@ test_that("function arguments are returned unchanged", {
effect_tox_observed = c(90, 81, 92, 28, 0), effect_tox_observed = c(90, 81, 92, 28, 0),
effect_tox_env_observed = c(29, 27, 33, 5, 0), effect_tox_env_observed = c(29, 27, 33, 5, 0),
effect_max = 100, effect_max = 100,
curves_concentration_max = NULL,
p = 3.2, p = 3.2,
q = 3.2 q = 3.2
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment