uncertainty in linear fit

41 次查看(过去 30 天)
Thar
Thar 2018-2-6
Hi all!
I want to ask about the uncertainty in the slope and in the constant term in a linear fit.
I found two function:
[p,S,mu] = polyfit(x,y,1);
[ynew,delta]= polyval(p,x,S,mu);
and
cf = fit(x,y,'poly1');
cf_coeff = coeffvalues(cf);
cf_confint = confint(cf);
a = cf_coeff(1);
b = cf_coeff(2);
a_uncert = (cf_confint(2,1) - cf_confint(1,1))/2;
b_uncert = (cf_confint(2,2) - cf_confint(1,2))/2;
when i apply the two functions in my x,y data i find different coefficient. What is the different between the two functions and how can i apply them in x{a},y{a} data?
Thank you!

回答(1 个)

Jos (10584)
Jos (10584) 2018-2-7
编辑:Jos (10584) 2018-2-7
Unfortunately, the first output of the function polyfit, being the coefficients of the fit changes, with the requested number of outputs. As an example:
x = 1:10 ;
y = 2*x + 3 ;
p1 = polyfit(x,y,1)
[p2, S] = polyfit(x,y,1)
[p3, S, mu] = polyfit(x,y,1) % p3 is different!
This is only very cryptically mentioned in the documentation and is easily overlooked. I am not sure why this behaviour is implemented, but The Mathworks is likely to have its reasons ...
I suggest you to use the function fit to estimate the uncertainty in the parameters, as these are easy to retrieve. If you only need the coefficients, p = polyfit(x,y,n) will do, of course.
  1 个评论
Liviu Ivanescu
Liviu Ivanescu 2020-1-9
[p3, S, mu] = polyfit(x,y,1)
uses a scaled version of x, see docs on polyfit for details ; that's why one gets different results.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by