[R] nls.control: increasing number of iterations

Douglas Bates bates at stat.wisc.edu
Thu Jun 2 20:18:59 CEST 2005


Martin Biuw wrote:
> Hello,
> I'm using the nls function and would like to increase the number of
> iterations. According to the documentation as well as other postings on
> R-help, I've tried to do this using the "control" argument:
> 
> nls(y ~ SSfpl(x, A, B, xmid, scal), data=my.data,
> control=nls.control(maxiter=200))
> 
> but no matter how much I increase "maxiter", I get the following error
> message:
> 
> Error in nls(y ~ cbind(1, 1/(1 + exp((xmid - x)/exp(lscal)))), data =
> xy,  :
>        number of iterations exceeded maximum of 50
> 
> The second line here suggests that the maximum number of iterations is
> still 50, despite changing the "control" argument. Also, increasing
> "maxiter" to something silly, like 50000, doesn't seem to increase the
> process time, which made me a bit suspicious that I'm not giving the
> right statement to the "control" argument. Or is the function indeed
> using the increased number of "maxiter", while the error message remains
> the same rather than reflecting the requested change to nls.control?
> 
> I should say that nls converges without increasing maxiter when I use
> the full dataset, and it is only when I use a smaller subset that the
> error occurs, possibly due to noisy data. But I would very much
> appreciate if someone could clarify whether the error message is wrong
> or if my statement to the "control" argument is wrong.
> 
> Thanks very much in advance,
> Martin
> 

If you look closely you will see that the error is not occurring in your
call to nls; it is occurring in a call generated as part of the
determination of the starting estimates.  If you use explicit starting
values you will get the correct behavior for maxiter.




More information about the R-help mailing list