[R] problems with nonlinear fits using nls

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Feb 22 09:30:45 CET 2005


"Corey Bradshaw" <corey.bradshaw at cdu.edu.au> writes:

> Hello colleagues,
> 
>  
> 
> I am attempting to determine the nonlinear least-squares estimates of
> the nonlinear model parameters using nls. I have come across a common
> problem that R users have reported when I attempt to fit a particular
> 3-parameter nonlinear function to my dataset:
> 
>  
> 
> Error in nls(r ~ tlm(a, N.fix, k, theta), data = tlm.data, start =
> list(a = a.st,  : 
> 
>         step factor 0.000488281 reduced below `minFactor' of 0.000976563
> 
>  
....
> My function is:
> 
>  
> 
> tlm <- function(a,N,k,theta) (a*(1-((N/k)^theta)))
> 
>  
> 
> The nls fit I've coded is:
> 
>  
> 
> tlm.fit <- try(nls(r~tlm(a,N.fix,k,theta), data=tlm.data,
> start=list(a=a.st,k=k.st,theta=1),
> 
>             trace=TRUE,
> control=nls.control(maxiter=6000,tol=1e-05,minFactor=1/1024)))

When you wrap the expresssion to fit in the tlm function, you are
effectively keeping nls from using algebraic derivatives and forcing
it to do something like dtlm/da =~ (tlm(a+1e-7,...) -
tlm(a,...))/1e-7.

So you might try sticking in the actual expression 

  r ~ a * (1 - (N.fix/k)^theta)

or modify tlm to return a gradient attribute. Reparametrizing in terms
of log(k) might also help keeping you out fo trouble. 


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list