nls: constraints (lower/upper) (PR#8401)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

nls: constraints (lower/upper) (PR#8401)

Ben Bolker-2

    I found what seems to be a glaring bug in nls when using
constraints, but it is so glaring that I'm a bit nervous
about having been stupid.  I have (1) tried to make sure
I'm up to date:

platform i486-pc-linux-gnu
arch     i486
os       linux-gnu
system   i486, linux-gnu
major    2
minor    2.0
year     2005
month    10
day      06
svn rev  35749

  (2) skimmed through the SVN logs; (3) skimmed the bug
reporting system for references to "lower" or "constraint"

    The problem is that nls() doesn't seem to work with
constraints.  Specifically, it seems to fail to set
the "lower" and "upper" components of to NULL
before trying to evaluate the formula.
There is a simple fix that makes it work
fine (for me at least -- I haven't tested extensively).

   I would submit a bug report but I'm gun-shy ...

   Sample problem and fix:
x = runif(200)
a =1
b = 1
c = -0.1
y = a+b*x+c*x^2+rnorm(200,sd=0.05)
## Error in model.frame(formula, rownames, variables, varnames, extras,
## extranames,  :
##      variable lengths differ

## hack nls()

## replace line 34:
##  mf$start <- mf$control <- mf$algorithm <-
##  mf$trace <- mf$model <- NULL
##    REVISED:
##  mf$start <- mf$control <- mf$algorithm <- mf$trace <- mf$model <-
##      mf$lower <- mf$upper <- NULL
## add "mynls <- " at the beginning, delete namespace code at the end

## works beautifully

620B Bartram Hall                            [hidden email]
Zoology Department, University of Florida
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

[hidden email] mailing list