Straight line fitting and error calculation

Hello everyone,
I have done straight line fitting by using polyfit command where i gave polynomial = 1 and found the values of m and c of the equation mx + c = y
Now i want to find errors associated with m and c i.e I want finally
m +/- error c +/- error
It would be nice if anyone could help me with it. I am badly stuck :(
Thanks

 採用された回答

Star Strider
Star Strider 2015 年 1 月 30 日

1 投票

I am glad you asked! See polyparci in the File Exchange.

10 件のコメント

aditi
aditi 2015 年 1 月 30 日
Thanks strider for your reply.
Could you please help on how to use it.
My present program giving m and c values uses polyfit and polyval. How should i include this in my program.
Thanks
Star Strider
Star Strider 2015 年 1 月 30 日
編集済み: Star Strider 2015 年 1 月 30 日
My pleasure!
First, download it and put it in with your other user files.
It’s internally documented, so quoting from that:
% CALLING POLYPARCI:
% [p,S] = polyfit(x,y,n); % Fit the data
% ci = polyparci(p,S); % NOTE: specifying a value for ‘alpha’ is
% optional
Call polyfit as you would normally, but include ‘S’ in the desired outputs. (Here ‘p’ is the vector of polynomial coefficients.) Then pass ‘p’ and ‘S’ to ‘polyparci’ as illustrated. It will return a matrix of confidence intervals as ‘ci’, whose columns correspond to the columns in the ‘p’ vector, so ‘ci(:,1)’ are the confidence intervals for ‘p(1)’, and so for all the others.
Example:
x = rand(10,1);
y = rand(10,1);
[p,S] = polyfit(x,y,1)
ci = polyparci(p,S)
Note that ‘polyparci’ has no relevance to polyval or anything it does.
aditi
aditi 2015 年 2 月 9 日
hey.. thanks a lot for the detailed explanation. I am highly obliged.
One more small confusion.. this will give confidence intervals for m and c but i want errors associated with these two parameters. So how will i find that from confidence intervals?
Star Strider
Star Strider 2015 年 2 月 9 日
編集済み: Star Strider 2015 年 2 月 9 日
My pleasure!
You can get the standard errors from the ‘S’ structure returned by polyfit (I call it ‘PolyS’ in this code snippet):
COVB = (PolyS.R'*PolyS.R)\eye(size(PolyS.R)) * PolyS.normr^2/PolyS.df;
SE = sqrt(diag(COVB)); % Standard Errors
aditi
aditi 2015 年 2 月 9 日
okay.. So COVB gives matrix or errors with slope and intercept? and what does SE gives? also what is R in COVB formula.. could you please explain jst a little bit so that i can understand what these commands are acually doing??
Thanks a lott once again..!! :)
Star Strider
Star Strider 2015 年 2 月 9 日
編集済み: Star Strider 2015 年 2 月 9 日
My pleasure!
The ‘COVB’ matrix is the covariance matrix for the parameters. Its diagonal are the variances of the individual parameters. The ‘SE’ variable is the standard error of the estimate for each parameter. As for its calculation from the ‘S’ structure, the documentation for polyfit explains it better than I can. See the documentation for S — Error estimation structure for details. I used those values to calculate the data necessary to generate the t-scores for the parameter confidence intervals.
aditi
aditi 2015 年 2 月 9 日
ohh... nice.. so in m +/- error and C +/- error errors are those which we are getting from SE?
Star Strider
Star Strider 2015 年 2 月 9 日
Yes.
I use the SE to calculate the confidence intervals.
aditi
aditi 2015 年 2 月 10 日
hey.. thanks a lot..!! :-)
I will bother you again if required.. bt thanks for everything.. you were of great help.. :-)
Star Strider
Star Strider 2015 年 2 月 10 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

質問済み:

2015 年 1 月 30 日

コメント済み:

2015 年 2 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by