3

Update: The original question is: Is there an R function using the same algorithm implemented in the "lsqnonlin" function in matlab? However, the answer is more related to searching a function in R. I think the answer is in general very helpful for R users. So I edited the title but asked the original question again here: In R, how to do nonlinear least square optimization which involves solving differential equations?

I am doing nonlinear least-square optimizations and found that the matlab function lsqnonlin performs better than all the optimization algorithms I tried in R (including the algorithms in function optimx, nlm, nlminb, solnp, etc.) in the sense that it is faster and found the "more correct" solution.

However, I did not find an implementation of the 'trust-region-reflective' algorithm in R that is used in Matlab. Does someone know if there is already an implementation? Also, is it always true that the 'trust-region-reflective' algorithm is a better algorithm for this kind of optimization?

Community
  • 1
  • 1
Zhenglei
  • 988
  • 1
  • 10
  • 21

1 Answers1

5

It sounds like lsqnonlin in the pracma package is what you're looking for.

I recommend installing the sos package for R. Its purpose is to help you answer questions like 'Is there a function out there that does this?'. findFn in this package will search what's on CRAN for the term you supply.

library(sos)
findFn('lsqnonlin')
Matthew Plourde
  • 43,932
  • 7
  • 96
  • 113
  • Thank you very much for the help. I knew neither `sos` nor `lsqnonlin` in `pracma`, I will try them out. – Zhenglei Dec 05 '12 at 15:20
  • 1
    I started working on this problem again and found that the `lsqnonlin` in the `pracma` package only implemented the levenberg-Marquardt algorithm. Here is the description of the function "lsqnonlin solves nonlinear least-squares problems, including nonlinear data-fitting problems, through the Levenberg-Marquardt approach. lsqnonneg solve nonnegative least-squares constraints problem." – Zhenglei Feb 04 '13 at 11:20