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
采纳的回答
10 个评论
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
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.
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?
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
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..!! :)
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.
ohh... nice.. so in m +/- error and C +/- error errors are those which we are getting from SE?
Yes.
I use the SE to calculate the confidence intervals.
hey.. thanks a lot..!! :-)
I will bother you again if required.. bt thanks for everything.. you were of great help.. :-)
My pleasure!
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
