Skip to content
Prev 258810 / 398502 Next

nls problem with R

In addition to Andrew's advice, you should get more familiar with your nonlinear model.
There you have a baseline on the Y-axis towards which your model tends, and this will give you sensible starting values for v0 and epi.

Also, as T0 tends to 0, V2 tends to v0(1-epi(1+exp(cl*t0))).
There you have another higher point on the Y-axis, and this one will give you additional sensible starting values for cl and t0.

Plot the data and the predicted model with your initial values and sends the model-data combination to the optimizer once you see that the predicted line is close to the observed response.

V2 <- c(371000, 285000 ,156000, 20600, 4420, 3870, 5500 )
T2 <- c(0.3403 ,0.4181 ,0.4986 ,0.7451 ,1.0069 ,1.553, 1.333) #last value inserted for illustration.
#nls2 <- nls(V2~v0*(1-epi+epi*exp(-cl*(T2-t0))),start=list(v0=10^7,epi=0.9 ,cl=6.2,t0=8.7))
v0.ini <- 10^7
epi.ini <- 0.9
cl.ini <-  6.2
t0.ini <-  8.7
V2.pred.ini <- v0.ini*(1-epi.ini+epi.ini*exp(-cl.ini*(T2-t0.ini)))
plot(T2,V2)
lines(T2,V2.pred.ini)

As you can see, with your initial values the line doesn't even show on the plot.
No wonder the gradients are singular.
So go find better initial values by trial and error and check the results on the plot.
Then the optimizer called by nls will finish the job (hopefully).
Then you repeat your plot this time with the estimates instead of the initial values.
This may get you started in the business of estimating nolinear models.

HTH

Rub?n
____________________________________________________________________________________ 

Dr. Rub?n Roa-Ureta
AZTI - Tecnalia / Marine Research Unit
Txatxarramendi Ugartea z/g
48395 Sukarrieta (Bizkaia)
SPAIN