How to Add Linear Trendline that Considers Errorbars

25 ビュー (過去 30 日間)
Matlab_Student
Matlab_Student 2017 年 3 月 31 日
編集済み: Isabel Allegro 2023 年 4 月 4 日
x = [662 1173 1332];
y = [654.3724 1124.827 1271.512];
yneg = [0.089207 0.799102 0.799102];
ypos = [0.089207 0.799102 0.799102];
xneg = [0.174485 1.796169 1.672245];
xpos = [0.174485 1.796169 1.672245];
errorbar(x,y,yneg,ypos,xneg,xpos)
Above is my code. I have three data points with errorbars. How can I add a special linear trendline (if there is such option for me) for the three points that takes into account the errorbars? In other words, it will be different from a regular trendline for the points without errorbars.
  2 件のコメント
Rik
Rik 2017 年 3 月 31 日
I think you will either need the original dataset or you need to generate a dataset. But more important is the question what you mean with taking into account the errorbars.
Matlab_Student
Matlab_Student 2017 年 4 月 1 日
Yes I am not making it clear. I was told that once you add the uncertainty to the data such as changing the point (1,500) to (1±0.01,500±2) the trendline will change.

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

回答 (3 件)

Joseph Cheng
Joseph Cheng 2017 年 3 月 31 日
編集済み: Joseph Cheng 2017 年 3 月 31 日
so if you want to take in the span of the error bars why not take into account the error bar points:
clf;
x = [1 2 3]';
y = [1 2 3]';
yneg = [.25 .1 .01];
ypos = [.15 .05 .01];
errorbar(x,y,yneg,ypos)
Ofitline = polyfit(x,y,1);
hold on, plot(x,polyval(Ofitline,x),'--b')
Errx = repmat(x,3,1);
Erry = [y; y-yneg';y+ypos'];
Efitline = polyfit(Errx,Erry,1);
hold on, plot(x,polyval(Efitline,x),'--r')
i did it in one position as i don't yet have the both direction error bars. but just fit a line with points at the bounds of the error bar. I did not include the original data as it can weight the answer in the positive or error bar.

DS
DS 2018 年 10 月 1 日
編集済み: DS 2018 年 10 月 1 日
The error bars of your dataset represents a distribution of the data. I would suggest use the original data to fit the line. If you generate a set of data using your error bar, make sure that this new set of data represent the correct distribution of the original data. For example, if you just linspace(mean-error, mean+error, 100), these 100 points distribute evenly from mean-error to mean+error. But the thing is that, if your data follow a normal distribution (there are more data points close to the mean value), the evenly distributed data points from linspace() are NOT useful in the fitting.

Isabel Allegro
Isabel Allegro 2023 年 3 月 17 日
編集済み: Isabel Allegro 2023 年 4 月 4 日

カテゴリ

Help Center および File ExchangeErrorbars についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by