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:
system i486, linux-gnu
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 match.call() 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)
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
## 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