View source: R/analyse_exponential_drift.R
| exponential_drift | R Documentation |
Calculate a two-phase curve: a fast monoexponential() primary response
plus a slow linear secondary drift beginning near the primary asymptote.
Model family fit by analyse_kinetics() with
method = "exponential_drift", and by stats::nls() via the self-starting
wrapper SSexponential_drift().
exponential_drift(t, A, B, tau, slope_B, drift_fraction, TD = NULL)
t |
A numeric vector of the predictor variable (time). |
A |
A numeric parameter for the starting baseline of the response variable. |
B |
A numeric parameter for the ending asymptote of the response variable. |
tau |
A numeric parameter for the time constant ( |
slope_B |
A numeric parameter for the linear drift rate |
drift_fraction |
A numeric fraction of the primary amplitude |
TD |
A numeric parameter for the time delay before the onset of the
exponential response, in units of the predictor variable |
5-parameter: A + (B - A) * (1 - exp(-t / tau)) + slope_B * pmax(t + tau * log(1 - drift_fraction), 0)
6-parameter: A + (B - A) * (1 - exp(-pmax(t - TD, 0) / tau)) + slope_B * pmax(t - TD + tau * log(1 - drift_fraction), 0)
A, B, tau, and TD are as for monoexponential(). The drift onset
is not a free estimate: the secondary drift is exactly zero before
TD - tau * log(1 - drift_fraction) (TD = 0 when absent), and
drift_fraction = 0.95 places the onset at TD + 3 * tau.
The excursion point texc is where the drift rate overtakes the decaying
primary rate, TD + tau * log(|B - A| / (|slope_B| * tau)), floored at the
drift onset.
A numeric vector of predicted values the same length as the
predictor variable t.
analyse_kinetics(), SSexponential_drift(),
monoexponential(), biexponential(), sigmoidal_drift()
## create an exponential curve with late linear drift and random noise
set.seed(13)
t <- 1:180
x <- exponential_drift(
t, A = 10, B = 100, tau = 12,
slope_B = -0.5, drift_fraction = 0.95, TD = 15
) + rnorm(length(t), 0, 2)
data <- data.frame(t, x)
## the drift onset fraction is held constant in the formula
model <- nls(
x ~ SSexponential_drift(
t, A, B, tau, slope_B, drift_fraction = 0.95, TD
),
data = data,
algorithm = "port",
lower = c(-Inf, -Inf, 0, -Inf, 0),
control = nls.control(warnOnly = TRUE)
)
summary(model)
y <- predict(model, data)
if (requireNamespace("ggplot2", quietly = TRUE)) {
ggplot2::ggplot(data, ggplot2::aes(t, x)) +
theme_mnirs() +
ggplot2::geom_point() +
ggplot2::geom_line(ggplot2::aes(y = y))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.