nls profile with port/constraints

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

nls profile with port/constraints

Ben Bolker-2

   Sorry to report further difficulties with
nls and profiling and constraints ... the problem
this time (which I didn't check for in my last
round of testing) is that the nls profiler doesn't
seem to respect constraints that have been
set when using the port algorithm.
   See test code below ...
   If I can I will try to hack the code, but I will
probably start by redefining my function with
some workarounds to make the fit quadratically "bad" (but well-defined)
when the parameters are negative ...
    As always, please don't hesitate to correct me
if I'm being an idiot ...

     Ben Bolker



a =2
b =0.5
x= runif(npts)
y = a*x/(1+a*b*x)+rnorm(npts,sd=0.2)

gfun <- function(a,b,x) {
   if (a<0 || b<0) stop("bounds violated")

m1 = nls(y~gfun(a,b,x),algorithm="port",


for what it's worth, the logic appears to be OK in mle in the stats4

mfun <- function(a,b,s) {
   if (a<0 || b<0 || s<0) stop("bounds violated")

m2 = mle(minuslogl=mfun,


m2b = mle(minuslogl=mfun,
## set boundary slightly above zero to avoid
## boundary cases

dev <- 2*(-logLik(m2b)+logLik(m2))

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