Estimating Non-Monotonic Bi-Exponential Curve Fit
In pharmacokinetic analyses, non-linear curve-fitting techniques are used to model complex biological systems. One such technique is the bi-exponential model, which can be modified to accommodate non-monotonic behavior. In this article, we’ll explore how to estimate a non-monotonic bi-exponential curve fit using R.
Introduction
The bi-exponential model is commonly used in pharmacokinetic analyses to describe the concentration of a drug over time. The standard form of the model assumes monotonic behavior, where the concentrations increase or decrease monotonically with time. However, in some cases, the behavior can be non-monotonic, meaning it changes direction. In this article, we’ll discuss how to estimate a non-monotonic bi-exponential curve fit using R.
Background
The bi-exponential model is typically described by the equation:
y = k1 * (exp(-b1x) - exp(-b2x))
where y is the concentration of the drug at time x, and k1 and b1 are parameters that describe the rate of increase, while b2 describes the rate of decrease.
Estimating Non-Monotonic Bi-Exponential Curve Fit
To estimate a non-monotonic bi-exponential curve fit, we can use R’s nls function in combination with the SSbiexp package. However, this approach requires manual specification of starting values for the parameters, which can be challenging.
One possible solution is to use the SSbiexp function directly within the nls framework. This approach allows us to avoid manual specification of starting values and instead relies on the default algorithm provided by SSbiexp.
Option 1: Using SSbiexp in nls
We can estimate a non-monotonic bi-exponential curve fit using the following code:
fit <- nls(y ~ SSbiexp(x, k1, b1, k2, b2), data = df)
This code defines an nls model with the bi-exponential equation as the response variable. The SSbiexp function is used to specify the bi-exponential form of the model.
To estimate the parameters, we can use the following code:
f <- function(x, p = coef(fit)) {
p["k1"] * exp(-exp(p["b1"]) * x) + p["k2"] * exp(-exp(p["b2"]) * x)
}
plot(y ~ x, df, type = "p", col = "blue")
curve(f, range(df$x), col = "red", add = TRUE)
This code defines a function f that computes the predicted values for the bi-exponential model. The fit object is used to extract the estimated parameters.
Option 2: Using constrOptim
Another approach is to use the constrOptim function from R’s optimization package. This function provides an alternative method for optimizing the parameters of a model, without relying on manual specification of starting values.
Here’s how we can estimate the non-monotonic bi-exponential curve fit using this approach:
x <- df$x
y <- df$y
f <- function(p) {
norm(p[1] * (exp(-p[2] * x) - exp(-p[3] * x)) - y, "2")
}
sol <- constrOptim(c(1, 0.1, 0.1), f, grad = NULL, ui = diag(3), ci = rep(0,3))
sol$par # (k, b1, b2)
This code defines a function f that computes the difference between the predicted values and the observed data. The constrOptim function is used to optimize the parameters of the model.
Comparison
We can compare the results from both approaches by computing the estimated parameters for each method:
fit <- nls(y ~ SSbiexp(x, k1, b1, k2, b2), data = df)
p <- coef(fit)
c(p["k1"], exp(p["b1"]), p["k2"], exp(p["b2"]))
sol <- constrOptim(c(1, 0.1, 0.1), f, grad = NULL, ui = diag(3), ci = rep(0,3))
p <- sol$par
c(p[1], p[2], p[3])
The results from both approaches are similar, but not identical. The nls approach provides a more robust estimate of the parameters, while the constrOptim approach provides an alternative solution.
Conclusion
In this article, we discussed how to estimate a non-monotonic bi-exponential curve fit using R. We explored two approaches: using the SSbiexp function within the nls framework and using the constrOptim function from R’s optimization package. Both approaches provide an alternative method for optimizing the parameters of the model, without relying on manual specification of starting values.
The choice between these approaches depends on personal preference and the specific requirements of the analysis. However, both methods can be used to estimate a non-monotonic bi-exponential curve fit with high accuracy.
References
- [R Development Core Team (2019)] R Development Core Team. (2019). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing.
- [Venables WN, & Ripley BD (2002)] Venables WN, & Ripley BD (2002). Modern Statistical Computing with S-PLUS. John Wiley & Sons.
- SSbiexp package documentation
Last modified on 2025-04-04