[R] nls.regression syntax problem

Dieter Menne dieter.menne at menne-biomed.de
Fri Feb 18 19:50:12 CET 2005


If you add a print(p), you will find that after a few iterations
u is negative which leads to problems with the power. It sometimes help write 
u=exp(p), and compute the log later. From a statistical point of view, I am not 
always happy with that solution, but even Pinheiro/Bates use it in the nlme 
samples. 
 
 f <- function (x,p) {
 print(p)
 u <- exp(p[1])
 v <- p[2]
 w <- p[3]
 (x*u)^v+w    # You don't need the I(( here.
 }


Nonlinear regression model
  model:  y ~ f(x, c(a, b, d)) 
   data:  parent.frame() 
        a         b         d 
-2.125873 12.781581  5.577249 
 residual sum-of-squares:  21.12331 
 
Dieter




More information about the R-help mailing list