Skip to content
Prev 100331 / 398498 Next

Different result from nls in R-2.2.1 and R-2.3.1

The way nls looks for variables in its formula is very unusual.  For 
non-parameters it has

     for(var in varNames[!varIndex])
         mf[[var]] <- eval(as.name(var), data)

inside nls, and that means that the scoping rules are first 'data' then 
the body of nls().  That's surely not what one would expect here: 
fitting functions using model.frame look in 'data' and then the 
environment of the formula (if non-null) or the parent frame.

So to avoid surprises, put fixed values in 'data'.  (Your example did not 
work in 2.2.1 when run from a function.)

I'll try to find a bug fix for 2.4.0.
On Thu, 21 Sep 2006, Frede Aakmann T?gersen wrote: