[R] nls.control in gnls

Claus Ekstroem claus at ekstroem.dk
Thu Jul 24 10:47:15 CEST 2003


I've made a selfStart function for use with gnls and the 
following piece of code works nicely:

check1 <- gnls(y ~ spot.shape.fct(xcord, ycord, background, spotintensity, 
                                  rho, sigma, delta, mux, muy),
              start=getInitial(y ~ spot.shape.fct(xcord, ycord, 
                                   background, spotintensity, rho, 
                                   sigma, delta, mux, muy), data=claus),

spot.shape.fct is the selfStart function and I later want to include 
a correlation term which is why I'm using gnls instead of nls. I want to 
get rid of the start= option, but I keep getting the following error 

Error in nls(formula = y ~ spot.shape.fct(xcord, ycord, background, 
spotintensity,  : 
        number of iterations exceeded maximum of 50

>From the help page and the glns code I can see that the initial start 
values are improved by estimating the parameters in a model without the 
correlation structures that are possible with gnls. This is quite 
reasonable and will quite likely improve the convergence succes and time 
once a correlation is introduced.

Obviously the call to nls does not converge before the standard 50 
iterations specified in nls.control so I was wondering if it is possible 
to pass nls.control information on to nls when calling gnls?

Several work-around exists:

* Write a better initial function to get more precise starting values, 
i.e., fewer iterations needed for nls.

* Make a new function  my.own.gnls  where nls.control(maxiter=100) is 
set in the call to nls.

Maybe it would even be a good idea to pass nlsMaxIter from gnlsControl 
on to the initial call to nls? As far as I can see from the code it is 
only used in maximization after the call to get the starting value.

Happy R'ing


Claus Thorn Ekstrøm <ekstrom at dina.kvl.dk>
Dept of Mathematics and Physics, KVL
Thorvaldsensvej 40
DK-1871 Frederiksberg C
Phone:[+45] 3528 2341
Fax:  [+45] 3528 2350

More information about the R-help mailing list