【问题标题】:Non-linear curve fitting -- fitnlm and lsqcurvefit give different error values非线性曲线拟合——fitnlm 和 lsqcurvefit 给出不同的误差值
【发布时间】:2021-02-26 16:24:22
【问题描述】:

我正在尝试对生物结合实验进行非线性拟合。我一直在使用 MATLAB 中的 lsqcurve 拟合功能,考虑到拟合效果如何,我对大置信区间感到有些失望。作为比较,我尝试了 fitnlm 算法,我得到了相同的拟合值,但置信区间要小得多。

我是 MATLAB 新手,没有很强的统计背景。为什么这两种算法会在不同的置信区间下给出相同的拟合?还是我混淆了这两个值代表什么?我是否有理由使用 NLM 算法仅仅因为它工作得更好?感谢您提供任何见解和要考虑的事情!代码复制如下。

LSQCURVE 方法

% Two state binding model
fun = @(x,xdata)(x(1)-x(2))*(xdata./(x(3)+xdata))-x(2);

% Parameterize 
x0 = [max(F), min(F), mean(C)];

% Perform the fit. In order to calculate confidence intervals, the full
% lsqcurvefit results are returned. Beta holds the fit values.

[beta,resnorm,resid,exitflag,output,lambda,J] = lsqcurvefit(fun,x0,xdata,ydata);
ci = nlparci(beta,resid,'jacobian',J);
beta(3) % Kd (parameter of interest)
beta(3)-ci(3) % Kd error

FIT NLM 方法

fun = @(b,x)((b(1)-b(2))*(x./(b(3)+x))-b(2));

% Parameterize 
b0 = [max(F), min(F), mean(C)];

% Perform the fit. 
nlm = fitnlm(C,F,fun,b0)

beta = nlm.Coefficients.Estimate;
beta_error = nlm.Coefficients.SE;

beta(3) % Kd
beta_error(3) % Kd error

样本数据(第 1 列是 X 或浓度 (C);第 2 列是 Y 或荧光 (F))

1.0e+04 *

    1.0000    5.6787
    0.5000    5.0545
    0.2500    4.4922
    0.1250    3.5727
    0.0625    2.5402
    0.0312    1.4649
    0.0156    0.6791
    0.0078    0.3283
    0.0039    0.1652
    0.0020    0.0958
    0.0010    0.0291
    0.0005    0.0274

【问题讨论】:

  • 每个函数默认使用不同的估计算法。请参阅lsqcurvefit(尤其是“算法”部分)和nlinfitfitnlm 页面将读者指向nlinfit)的手册页。另请参阅此问题:stackoverflow.com/questions/22547428/…
  • 您好,Vicky,感谢您的回复。我确实尝试了带有 lsqcurvefit 函数的 Levenberg–Marquardt 算法,但这似乎没有帮助......
  • 我刚刚比较了ci = nlparci(...)nlm.coefCI(),结果对我来说是一样的。正如您的代码似乎暗示的那样,您不可能将置信区间(好吧,估计的系数减去区间的下限)与标准误差进行比较,是吗? (顺便说一句,我用nls在R中复制了你的例子,结果是一样的。)
  • 好点 - 我想我将置信区间和标准误差混为一谈。我追求测量的标准误差,根据这篇文章,fitnlm 似乎更适合这个:mathworks.com/matlabcentral/answers/…。再次感谢您的帮助!

标签: matlab curve-fitting


【解决方案1】:

可以通过以下非常简单的方法(无需反复试验)获得参数 b1 、 b2 、 b3 的良好近似值。

如果结果不够准确,可以使用这些近似值作为初始值(而不是猜测)来启动一种迭代方法,例如您已经尝试过的方法。这保证了更好的收敛性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 2021-05-08
    • 2018-03-19
    • 2014-03-29
    • 2017-12-18
    • 1970-01-01
    相关资源
    最近更新 更多