Skip to content
Snippets Groups Projects

dissect ecxsys()

Merged Sebastian Henz requested to merge refactor/dissect-ecxsys into v2.0
Files
12
+ 15
17
@@ -8,11 +8,11 @@
#' smallest concentration is returned.
#'
#' @param model This can be one of three types of objects: Either the output of
#' \code{ecxsys()} (object of class "ecxsys") or the output of a call to the
#' \code{fn} function in the ecxsys output or a data frame with a
#' "concentration" column and a \code{response_name} column. See the examples.
#' \code{\link{ecxsys}} or the output of \code{\link{predict_ecxsys}} or a
#' data frame with a "concentration" column and a \code{response_name} column.
#' See the examples.
#' @param response_name The name of the effect or stress for which you want to
#' calculate the EC. Must be the name of a column in \code{model$curves}.
#' calculate the EC. Must be one of \code{colnames(model$curves)}.
#' @param response_level The desired response level as a percentage between 0
#' and 100. For example with the value 10 the function will return the EC10,
#' i.e. the concentration where the response falls below 90 \% of the maximum
@@ -30,23 +30,21 @@
#' hormesis_concentration = 0.3
#' )
#'
#' # using the ecxsys output directly:
#' ec10_a <- ec(model, "effect_tox_sys", 10)
#' # using the ecxsys() output or the curves therein directly:
#' ec(model, "effect_tox_sys", 10)
#' ec(model$curves, "effect_tox_sys", 10)
#'
#' # using predicted values:
#' ec10_b <- ec(model$curves, "effect_tox_sys", 10)
#'
#' # using the output of fn():
#' # using the output of predict_ecxsys() with custom concentrations:
#' conc <- 10^seq(-9, 1, length.out = 1000)
#' df_fn <- model$fn(conc)
#' ec10_c <- ec(df_fn, "effect_tox_sys", 10)
#' curves <- predict_ecxsys(model, conc)
#' ec(curves, "effect_tox_sys", 10)
#'
#' # using a custom data frame:
#' df_custom <- data.frame(
#' concentration = df_fn$concentration,
#' foo = df_fn$effect_tox_sys
#' concentration = curves$concentration,
#' foo = curves$effect_tox_sys
#' )
#' ec10_d <- ec(df_custom, "foo", 10)
#' ec(df_custom, "foo", 10)
#'
#' @export
ec <- function(model, response_name, response_level) {
@@ -62,7 +60,7 @@ ec <- function(model, response_name, response_level) {
response_level < 100
)
if (!inherits(model, c("ecxsys", "ecxsys_curves"))) {
if (!inherits(model, c("ecxsys", "ecxsys_predicted"))) {
if (is.data.frame(model)) {
concentration <- model$concentration
response <- model[, response_name]
@@ -72,7 +70,7 @@ ec <- function(model, response_name, response_level) {
} else if (inherits(model, "ecxsys")) {
concentration <- model$curves$concentration
response <- model$curves[, response_name]
} else if (inherits(model, "ecxsys_curves")) {
} else if (inherits(model, "ecxsys_predicted")) {
concentration <- model$concentration
response <- model[, response_name]
}
Loading