필터 지우기
필터 지우기

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 CenterFile Exchange에서 Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by