astamm / nloptr

nloptr provides an R interface to NLopt, a free/open-source library for nonlinear optimization providing a common interface to a number of different optimization routines which can handle nonlinear constraints and lower and upper bounds for the controls.
https://astamm.github.io/nloptr/
Other
105 stars 35 forks source link

nloptr stops iterating too early compared to lm or optim #114

Closed gittybobomber closed 2 years ago

gittybobomber commented 2 years ago

It seems to be impossible to get the correct result for a multiple regression with nloptr, as the iterations stop too early. Message says "Optimization stopped because ftol_rel or ftol_abs (above) was reached. " but this does not seem plausible at (as compared tp lm or optim).

I described the problem including sample code here: https://stackoverflow.com/questions/71563947/r-nloptr-problem-rebuilding-linear-regression-optimization-stops-too-early

Is there a solution?

eddelbuettel commented 2 years ago

Please don't crosspost. You haven't demonstrated an issue in nloptr, you are asking for help using it (and posting at SO was a good first step).

I think I have similar 'finger exercises" as a gradstudent but I think you should reformulate your problem as a likelihood maximization (where we know OLS aka lm() has the BLUE properties [and per Hansen (2021) even BUE but I digree]). You then be able to recover the parameters estimates in one project step by lm().

gittybobomber commented 2 years ago

Thanks for your comment. I found out that the answer on my question is: Use "algorithm"="NLOPT_LN_SBPLX"

astamm commented 2 years ago

Thanks @eddelbuettel for following up on this. I'll close the issue.