Effacer les filtres
Effacer les filtres

uncertainty in linear fit

30 vues (au cours des 30 derniers jours)
Thar
Thar le 6 Fév 2018
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 commentaire
Liviu Ivanescu
Liviu Ivanescu le 9 Jan 2020
polyval gives errors on y, not on slope or intercept.

Connectez-vous pour commenter.

Réponses (1)

Jos (10584)
Jos (10584) le 7 Fév 2018
Modifié(e) : Jos (10584) le 7 Fév 2018
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 commentaire
Liviu Ivanescu
Liviu Ivanescu le 9 Jan 2020
[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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by