用于非线性最小二乘回归的"fitnlm"或"lsqcurvefit"? [英] 'fitnlm' or 'lsqcurvefit' for non-linear least squares regression?
问题描述
我正在尝试使用最小二乘法将实验数据拟合到三次多项式方程式.我有两个自变量和一个因变量,这使其成为非线性拟合.我已经使用函数"fitnlm"和"lsqcurvefit"计算了系数,建议将两者用于非线性回归拟合.尽管我输入了相同的初始系数(猜测)值,但我从这两个函数获得了不同的系数值.请告知这两个函数中哪个更好,以及我可以信赖的系数.而且,在使用lsqcurvefit时如何检查均方根误差的值?非常感谢您的任何帮助/建议/有益的意见.
I am trying to fit experimental data to a third degree polynomial equation, using least squares. I have two independent variables and one dependent variable, which makes it a non-linear fit. I have calculated the coefficients with the functions 'fitnlm' and 'lsqcurvefit', both of which are recommended for nonlinear regression fits. I obtained different values of the coefficients from the two functions, although I input the same initial coefficient (guess) values. Kindly advise as to which of the two functions is better and whose coefficients I can trust. And, how do I check the value of the Root Mean Squared Error when using lsqcurvefit? Thanks very much for any assistance/advise/helpful comments.
推荐答案
根据在matlab的主要讨论中,即nlinfit(并扩展为fitnlm)使用Levenberg-Marquardt算法.同样根据 lsqnonlin 的文档页面(这是lsqcurvefit)的默认算法为信任区域反射",但也可以选择使用Levenberg-Marquardt.如果您在lsqcurvefit函数中指定使用L-M算法选项,结果是否与fitnlm结果更接近?
It appears according to this matlab central discussion that nlinfit (and by extension fitnlm) uses the Levenberg-Marquardt algorithm. Also according to the doc page for lsqnonlin (which is the underlying function for lsqcurvefit) the default algorithm is 'trust-region-reflective' but Levenberg-Marquardt is also an option. If you specify the use of the L-M algorithm option in the lsqcurvefit function, do the results more closely match your fitnlm result?
关于如何选择lsqcurvefit中哪个算法选项更好...这是科学的乐趣所在;)LM确实在其方法中纳入了信任区域原理,因此可能存在一些理论上的重叠,并且两者被认为比Nelder-Mead之类的工具更健壮,因此我想不出有什么先验的理由要优先于另一个.
As for how to choose which of the algorithm options in lsqcurvefit is better...well that's the fun part of the science ;) L-M does incorporate trust-region principles in its approach so there may be some theoretical overlap, and both are considered more robust than something like Nelder-Mead so I can't think of much reason a priori to favor one over the other.
此处是一款mathworks参考资料,并讨论了MATLAB使用的各种非线性方程求解算法.
edit: Here is a mathworks source with discussion of the various non-linear equation solving algorithms MATLAB uses.
这篇关于用于非线性最小二乘回归的"fitnlm"或"lsqcurvefit"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!