[R] nls problem with R

Rubén Roa rroa at azti.es
Wed May 4 09:50:22 CEST 2011


In addition to Andrew's advice, you should get more familiar with your nonlinear model.

>From what you wrote, as T2 tends to infinity, V2 tends to v0*(1-epi).
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



> -----Mensaje original-----
> De: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] En nombre de Andrew Robinson
> Enviado el: miércoles, 04 de mayo de 2011 9:15
> Para: sterlesser
> CC: r-help at r-project.org
> Asunto: Re: [R] nls problem with R
> 
> The fact that T2 and V2 are of different lengths seems like a 
> likely culprit.  Other than that, you need to find start 
> points that do not lead to a singular gradient.  There are 
> several books that provide advice on obtaining initial 
> parameter estimates for non-linear models.  Google Books 
> might help you.
> 
> Cheers
> 
> Andrew
> 
> 
> 
> 
> On Tue, May 03, 2011 at 09:08:03PM -0700, sterlesser wrote:
> > the original data are
> > V2 =c(371000,285000 ,156000, 20600, 4420, 3870, 5500 ) T2=c( 0.3403 
> > ,0.4181 ,0.4986 ,0.7451 ,1.0069 ,1.553)
> > 
> 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))
> > after execution error occurs as below
> > ################################################################
> > Error in nlsModel(formula, mf, start, wts) : 
> >   singular gradient matrix at initial parameter estimates Error in 
> > nlsModel(formula, mf, start, wts) :
> >   singular gradient matrix at initial parameter estimates 
> In addition: 
> > Warning messages:
> > 1: In lhs - rhs :
> >   longer object length is not a multiple of shorter object length
> > 2: In .swts * attr(rhs, "gradient") :
> >   longer object length is not a multiple of shorter object length
> > 
> > could anyone help me ?thansks
> > 
> > --
> > View this message in context: 
> > 
> http://r.789695.n4.nabble.com/nls-problem-with-R-tp3494454p3494454.htm
> > l Sent from the R help mailing list archive at Nabble.com.
> > 
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> --
> Andrew Robinson
> Program Manager, ACERA 
> Department of Mathematics and Statistics            Tel: 
> +61-3-8344-6410
> University of Melbourne, VIC 3010 Australia               
> (prefer email)
> http://www.ms.unimelb.edu.au/~andrewpr              Fax: 
> +61-3-8344-4599
> http://www.acera.unimelb.edu.au/
> 
> Forest Analytics with R (Springer, 2011) 
> http://www.ms.unimelb.edu.au/FAwR/
> Introduction to Scientific Programming and Simulation using R 
> (CRC, 2009): 
> http://www.ms.unimelb.edu.au/spuRs/
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 



More information about the R-help mailing list