I am trying to fit oral pharmacokinetic function using R nls. The function can be seen here:
I tried the following:
dat <- data.frame(
Time = c(10, 15, 20, 30, 40, 60, 90, 120, 180, 210, 240, 300, 360),
C_PO = c(0,0.28,0.55,1.2,2,1.95,1.85,1.6,
0.86,0.78,0.6,0.21,0.18))
plot(dat$C_PO ~ dat$Time, data = dat, log = "y")
fit <- nls(C_PO~ka*100* (exp(-k*Time) - exp(-ka*Time))/(v*(ka- k)),
data = dat,
start = list(ka = 0.09, k = 0.01, v = 50))
#> Error in nls(C_PO ~ ka * 100 * (exp(-k * Time) - exp(-ka * Time))/(v * : singular gradient
The code is trying to fit a non-linear model according to the concentration values C_PO
over a time period Time
. The initial values were calculated using graph stripping methods. However, the error message reads "singular gradient." How can this be fixed?