[R] nls() newbie convergence question

Bernard Leemon bernie.leemon at gmail.com
Thu Jun 5 01:15:53 CEST 2008


I'm sure this must be a nls() newbie question, but I'm stumped.
I'm trying to do the example from Draper
and Yang (1997).  They give this snippet of S-Plus code:

Specify the weight function:
weight < - function(y,x1,x2,b0,b1,b2)
{
pred <-  b0+b1*x1 + b2*x2
parms <- abs(b1*b2)^(1/3)
(y-pred)/parms
}
Fit the model
gmfit < -nls(~weight(y,x1,x2,b0,b1,b2), observe,list("starting value"))

in converting this to R, I left the weight function alone and replaced the
nls() with

gmfit <-
 nls(~weight(y,x1,x2,b0,b1,b2),data=dydata,trace=TRUE,start=list(b0=1,b1=1,b2=1))

where dydata is the appropriate data.frame.

nls() quickly (6 iterations) finds the exact values from Draper & Yang for
b0, b1, and b2 but
despite reporting a discrepancy of only 3.760596e-29 by the 7th iteration,
it merrily goes on
to 50 iterations and thinks it never converged.  how do I tell nls() that
I'm actually quite
happy with 3.760596e-29 and it need not work further?

I've attached the full file if you want to play with it.

thanks,
  gary mcclelland (aka bernie)


More information about the R-help mailing list