Calculating linear fit with respect from origin (0,0)
3 ビュー (過去 30 日間)
古いコメントを表示
I have a data of DataX and Data Y, which is plotted in the blue line as in picture.I am trying to analyse how much the blue line is deviated from the black dotted line x and y = [0:1:7]. The thing is, if i want to compare the linear fit, the linear fit of my data does not start from 0 (yellow line).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156700/image.jpeg)
Can anyone suggest what kind of metric that I can use here? If possible, I would like a way to measure say for example if the fit of my data falls below the dotted line, the value will be <0, and if it is above the >0.
2 件のコメント
Massimo Zanetti
2016 年 9 月 28 日
There is no data above the dotted line. Can you explain better? Do you want to measure the distance of the Data with respect to the Linear Fit Data?
採用された回答
Massimo Zanetti
2016 年 9 月 28 日
編集済み: Massimo Zanetti
2016 年 9 月 28 日
Ok, you just have to use the right statistics. Look here:
%random points
x=1:10;
y=rand(1,10);
%fit data
p=polyfit(x,y,1);
yfit=p(2)+x*p(1);
%residuals
yres = y-yfit;
%deviation from mean
ymean = mean(y(:));
ydev = y-ymean;
%compute R2
SSR = sum(yres.^2);
SST = sum(ydev.^2);
R2 = 1-SSR/SST;
%plot fitting
plot(x,y,'b',x,yfit,'r');
The R2 number is Rsquared statistics explaining how the fit line well represents the points.
2 件のコメント
Massimo Zanetti
2016 年 9 月 28 日
編集済み: Massimo Zanetti
2016 年 9 月 28 日
Ok, so it is much simple. Just replace the polyfit line with reference one.
%random points
x=1:10;
y=rand(1,10);
yref=1:10;
%residuals
yres_ref = y-yref;
%deviation from mean
ymean = mean(y(:));
ydev = y-ymean;
%compute R2
SSR = sum(yres_ref.^2);
SST = sum(ydev.^2);
R2 = 1-SSR/SST;
%plot fitting
plot(x,y,'b',x,yref,'r');
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Descriptive Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!