[R] nls max iterations reached, but parameter estimates are correct

natan hoefnagel n.hoefnagel at science.ru.nl
Mon Aug 12 16:54:16 CEST 2013


Dear All,

I am trying to fit a regression (growth curve) through my data using nls().
I want to learn how this works, so I made up my own simple data:

PGC = function(K, P0, r, t)  { (K*P0*exp(r*t)) / (K+P0*(exp(r*t)-1)) }
x <- seq(1:20)
y<-PGC(6, 0.1, 0.4, x)

Plotting this data yields a nice s-shaped growth curve including a 
horizontal asymptote.

Then I wanted to test the function nls():
m<-nls(y~PGC(K,P0,r,x),start=list(K=5,P0=0.01,r=0.3),trace=TRUE)

I deliberately used starting values a bit off. I used trace=TRUE based 
on an answer in the thread about changing maximum nr of iterations - 
first check where the iterations are going. I want the parameter 
estimates to be saved in 'm' for later use.
Running this line results in a list of 50 iterations for 3 parameters 
(K, P0,r) and the error message:
"Error in nls(y ~ PGC(K, P0, r, x), start = list(K = 5, P0 = 0.01, r = 
0.3),  :
   number of iterations exceeded maximum of 50"

However, I can see that the right parameter values are reached after 12 
iterations (The values I used to create 'y').

My questions: Why does it continue to iterate?
Is there a way to still get the parameter estimates for further use (for 
example plot the fitted line)? It seems that they are note saved in 'm'.

Any help would be very welcome,

Evan



More information about the R-help mailing list