diff --git a/R/ecxsys.R b/R/ecxsys.R index f3a69ce022f5620a7be9a33659929444264a74d0..6d321cd0d63e150aa348714b3720ccea4846555a 100644 --- a/R/ecxsys.R +++ b/R/ecxsys.R @@ -204,11 +204,26 @@ ecxsys <- function(concentration, # interpolation between subhormesis and hormesis ---------------------- n_new <- 3 # number of new points - concentration <- interpolate(concentration, hormesis_index, n_new, TRUE) - survival_tox_observed <- interpolate(survival_tox_observed, hormesis_index, n_new) + concentration <- interpolate_sub_horm( + concentration, + hormesis_index - 1, + hormesis_index, + n_new, + TRUE + ) + survival_tox_observed <- interpolate_sub_horm( + survival_tox_observed, + hormesis_index - 1, + hormesis_index, + n_new + ) if (with_env) { - survival_tox_env_observed <- interpolate(survival_tox_env_observed, - hormesis_index, n_new) + survival_tox_env_observed <- interpolate_sub_horm( + survival_tox_env_observed, + hormesis_index - 1, + hormesis_index, + n_new + ) } hormesis_index <- hormesis_index + n_new # In the output return only the values at the original concentrations @@ -435,10 +450,16 @@ fit_LL5_model <- function(min_conc, } -interpolate <- function(x, to_index, n_new, conc = FALSE) { - from_index <- to_index - 1 # subhormesis_index +interpolate_sub_horm <- function(x, + from_index, + to_index, + n_new, + logarithmic = FALSE) { + # Interpolate between subhormesis and hormesis. This makes the curves + # smoother, less extreme. Without it the slope between subhormesis and + # hormesis would be much steeper in many cases. len <- n_new + 2 # Add 2 because seq() includes the left and right end. - if (conc) { + if (logarithmic) { x_new <- 10^seq(log10(x[from_index]), log10(x[to_index]), length.out = len) } else { x_new <- seq(x[from_index], x[to_index], length.out = len)