hello, I have got some trouble with R functions nlm(), nls() or optim() : I would like to fit 3 parameters which must stay in a precise interval. For exemple with nlm() : fn<-function(p) sum((dN-estdata(p[1],p[2],p[3]))^2) out<-nlm(fn, p=c(4, 17, 5), hessian=TRUE,print.level=2) with estdata() a function which returns value to fit with dN (observed data vactor) My problem is that only optim() allows me to set parameters interval with "L-BFGS-B" method but this one doesn't work in my case. I have heard about nls2 package (www.inra.fr/bia) but it doesn't work on Windows. Do you know any solutions Thank's a lot for reading my post Best regards Sebastien INA P-G ecology dpt
S?bastien Ballesteros wrote:> hello, I have got some trouble with R functions nlm(), > nls() or optim() : I would like to fit 3 parameters > which must stay in a precise interval. For exemple > with nlm() : > > fn<-function(p) sum((dN-estdata(p[1],p[2],p[3]))^2) > out<-nlm(fn, p=c(4, 17, 5), > hessian=TRUE,print.level=2) > > with estdata() a function which returns value to fit > with dN (observed data vactor) > > My problem is that only optim() allows me to set > parameters interval with "L-BFGS-B" method but this > one doesn't work in my case. > > I have heard about nls2 package (www.inra.fr/bia) but > it doesn't work on Windows."it doesn't work on Windows" is a very gentle description in this particular case...> Do you know any solutionsA typical trick is to redefine the function so that for points outside the boundaries increasing penalties are added (if you know enough about your function). Uwe Ligges> Thank's a lot for reading my post > > Best regards > > Sebastien > INA P-G ecology dpt > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
I have had my best luck by re-parametrizing so that I no longer needed restrictions. For example, if parameters must be positive, then I optimize over parameters in log space, taking the exponential within my function. This requires small changes to the function I'm optimizing (and the gradient, if supplied), but, for me at least, has worked better than trying to enforce box constraints as in L-BFGS-B. Hope this helps, Matt Wiener -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of S?bastien Ballesteros Sent: Tuesday, March 08, 2005 8:24 AM To: r-help at stat.math.ethz.ch Subject: [R] Non-linear minimization hello, I have got some trouble with R functions nlm(), nls() or optim() : I would like to fit 3 parameters which must stay in a precise interval. For exemple with nlm() : fn<-function(p) sum((dN-estdata(p[1],p[2],p[3]))^2) out<-nlm(fn, p=c(4, 17, 5), hessian=TRUE,print.level=2) with estdata() a function which returns value to fit with dN (observed data vactor) My problem is that only optim() allows me to set parameters interval with "L-BFGS-B" method but this one doesn't work in my case. I have heard about nls2 package (www.inra.fr/bia) but it doesn't work on Windows. Do you know any solutions Thank's a lot for reading my post Best regards Sebastien INA P-G ecology dpt ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
maybe you could re-parameterize the problem, e.g., p \in (a, b) p^* = (p - a) / (b - a) \in (0, 1) x = qlogis(p^*) \in \Re I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "S?bastien Ballesteros" <sebastien_ballesteros at yahoo.fr> To: <r-help at stat.math.ethz.ch> Sent: Tuesday, March 08, 2005 2:23 PM Subject: [R] Non-linear minimization> hello, I have got some trouble with R functions nlm(), > nls() or optim() : I would like to fit 3 parameters > which must stay in a precise interval. For exemple > with nlm() : > > fn<-function(p) sum((dN-estdata(p[1],p[2],p[3]))^2) > out<-nlm(fn, p=c(4, 17, 5), > hessian=TRUE,print.level=2) > > with estdata() a function which returns value to fit > with dN (observed data vactor) > > My problem is that only optim() allows me to set > parameters interval with "L-BFGS-B" method but this > one doesn't work in my case. > > I have heard about nls2 package (www.inra.fr/bia) but > it doesn't work on Windows. > > Do you know any solutions > > Thank's a lot for reading my post > > Best regards > > Sebastien > INA P-G ecology dpt > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
After some experimentation, I have had very good luck with the rgenoud package. It handles box constraints well and for small problems its slow speed has not been much of a problem. It has worked for me on Windows, Macintosh, and Linux. Chris JPMorgan Asset Management |---------+--------------------------------> | | S?bastien Ballesteros| | | <sebastien_ballestero| | | s at yahoo.fr> | | | Sent by: | | | r-help-bounces at stat.m| | | ath.ethz.ch | | | | | | | | | 03/08/2005 08:23 AM | | | | |---------+--------------------------------> >-----------------------------------------------------------------------------------------------------------------------------| | | | To: r-help at stat.math.ethz.ch | | cc: | | Subject: [R] Non-linear minimization | >-----------------------------------------------------------------------------------------------------------------------------| hello, I have got some trouble with R functions nlm(), nls() or optim() : I would like to fit 3 parameters which must stay in a precise interval. For exemple with nlm() : fn<-function(p) sum((dN-estdata(p[1],p[2],p[3]))^2) out<-nlm(fn, p=c(4, 17, 5), hessian=TRUE,print.level=2) with estdata() a function which returns value to fit with dN (observed data vactor) My problem is that only optim() allows me to set parameters interval with "L-BFGS-B" method but this one doesn't work in my case. I have heard about nls2 package (www.inra.fr/bia) but it doesn't work on Windows. Do you know any solutions Thank's a lot for reading my post Best regards Sebastien INA P-G ecology dpt ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates