I am trying to fit this nonlinear model in R using the nls
function.
Here is the data I am trying to fit:
tab2 = data.frame(n = c(10,100,1000,10000,100000), Time = c(3.989220e-03,
1.994681e-02, 3.311172e-01, 5.142252e+00, 1.314725e+03))
We see that time is growing exponentially, so I want to model this using nls
. This is what I have tried so far:
mod4 = nls(Time ~ exp(a + b*n), data = tab2, start = list(a = -3, b = 0))
However, this does not work, and the following error message comes up:
Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an
infinity produced when evaluating the model
I have no idea why this is happening, but I am guessing it has to do with these starting values? I got them by estimating the model using lm:
mod3 = lm(log(Time) ~ n, data = tab2); coef(mod3)
(Intercept) n
-2.5908574883 0.0001010623
Since this is pretty much the same model, I figured the coefficients would match up, but when I use values close to them for starting values, the nls
model does not work.
Any suggestions as to why this is happening?