[R] avoiding termination of nls given convergence failure

Gabor Grothendieck ggrothendieck at gmail.com
Thu Mar 12 19:23:41 CET 2009


If the goal here is to repeatedly run a particular model from
different starting values
then the nls2 package will do that for you.

On Thu, Mar 12, 2009 at 2:13 PM, Bill Shipley
<bill.shipley at usherbrooke.ca> wrote:
> Hello.  I have a script in which I repeatedly fit a nonlinear regression to
> a series of data sets using nls and the port algorithm from within a loop.
> The general structure of the loop is:
>
>  for(i in 1:n){
>
> … extract relevant vectors of dependent and independent variables …
>
> … estimate starting values for Amax and Q.LCP…
>
>
>
>
> fit<-nls(photosynthesis~fit.Mitcherlich(irradiance,Amax,LCP,Q.LCP),data=temp
> ,
>
>
> start=list(Amax=Astart,Q.LCP=x,LCP=33),control=list(maxiter=100,tol=5e-4),
>
>            na.action=na.omit,trace=T,algorithm="port",lower=c(0,0,0))
>
>>
> }
>
>
>
> Despite trying to estimate good starting values, the nls function
> occasionally experiences problems with convergence.  When this happens the
> function stops and prints an error message, thus preventing the loop from
> continuing.  Is there some what of detecting the convergence problem while
> preventing the nls function from stopping when this happens, so that the
> loop can continue?
>
>
>
> Bill Shipley
>
> North American Editor, Annals of Botany
>
> Département de biologie
>
> Université de Sherbrooke
>
> Sherbrooke (Québec) J1K 2R1
>
> Canada
>
> (819) 821-8000, poste 62079
>
> (819) 821-8049 FAX
>
>
>
> http://pages.usherbrooke.ca/jshipley/recherche/
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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