[R] Understanding how nls() works

Patrick Connolly p_connolly at slingshot.co.nz
Wed Apr 24 08:40:31 CEST 2013


I'm trying to understand what goes on in the process that nls() uses.
This converges without much drama:

> rate.nls <- nls(Dev ~ exp(rho * (T)) - exp(rho*Tmax - (Tmax - T)/del)+ 
+                 lam , data = xx, trace = TRUE,
+                 start = c(rho = 0.15, del = 7, lam = .02, Tmax = 30))
599.7841 :   0.15  7.00  0.02 30.00 
4.69849 :   0.14673457  6.83443060 -0.01417782 29.94392535 
0.06971343 :   0.14787121  6.75095966 -0.01281743 28.88851217 
0.01197127 :   0.1460683  6.8334550 -0.0128118 30.1599472 
0.008279834 :   0.14406976  6.92819920 -0.01281783 31.63914711 
0.002267513 :   0.1437983  6.9426081 -0.0127973 31.9153204 
0.002264977 :   0.14377323  6.94385235 -0.01279224 31.95091153 
0.002264977 :   0.14378546  6.94326629 -0.01278643 31.95045828 
0.002264977 :   0.14378124  6.94346882 -0.01278843 31.95065902 
0.002264977 :   0.14378271  6.94339837 -0.01278772 31.95059050 

If I make one parameter further away from optimum, I get this:

> rate.nls <- nls(Dev ~ exp(rho * (T)) - exp(rho*Tmax - (Tmax - T)/del)+ 
+                 lam , data = xx, trace = TRUE, 
+                 nls.control(warnOnly = TRUE),
+                 start = c(rho = 0.15, del = 7, lam = 1.02, Tmax = 30))
59.80968 :   0.15  7.00  1.02 30.00 
4.69849 :   0.14673457  6.83443060 -0.01417782 29.94392535 
0.06973771 :   0.14787046  6.75099517 -0.01281668 28.88853959 
0.0119916 :   0.1460709  6.8333430 -0.0128098 30.1600040 
0.008369133 :   0.14406664  6.92834092 -0.01281926 31.63978393 
0.002267664 :   0.1438008  6.9424901 -0.0127959 31.9151258 
0.002264977 :   0.1437771  6.9436655 -0.0127904 31.9507300 
0.002264977 :   0.14378253  6.94340678 -0.01278781 31.95059843 
0.002264977 :   0.1437849  6.9432936 -0.0127867 31.9504860 
Warning message:
In nls(Dev ~ exp(rho * (T)) - exp(rho * Tmax - (Tmax - T)/del) +  :
  step factor 0.000488281 reduced below 'minFactor' of 0.000976562


There's no surprise that the traces will be different, but I can't
understand why the first iteration gives exactly the same result in
both cases.  *Then* they diverge.  What is the explanation?  (Maybe if
I knew what the step factor refers to, it could be clearer but I
suspect it doesn't come in at that stage.)

I can't think of a way of making a minimal working example but I'd
guess that it's not necessary to explain the procedure.  I could
supply my xx dataframe if it's indispensible to the explanation.

TIA

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}                   Great minds discuss ideas    
 _( Y )_  	         Average minds discuss events 
(:_~*~_:)                  Small minds discuss people  
 (_)-(_)  	                      ..... Eleanor Roosevelt
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.



More information about the R-help mailing list