uncertainty in linear fit

30 ビュー (過去 30 日間)
Thar
Thar 2018 年 2 月 6 日
コメント済み: Liviu Ivanescu 2020 年 1 月 9 日
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 件のコメント
Liviu Ivanescu
Liviu Ivanescu 2020 年 1 月 9 日
polyval gives errors on y, not on slope or intercept.

サインインしてコメントする。

回答 (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 Center および File ExchangeInterpolation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by