Why doesn't the standard deviation show on boxplot?

9 ビュー (過去 30 日間)
Sarah Ford
Sarah Ford 2023 年 9 月 27 日
編集済み: dpb 2023 年 10 月 5 日
Hi, I'm having an issue with my code. As you can see, the total and catagory 1 is plotted appropriately. The catagory 2 plot has a red x and no upper standard deviation plotted and I can't figure out why. Thank you!
close all
clear
T = readtable("BFR_ToPlot.xlsx");
A = T.Active(1:5);
B = T.OsteoisOcy(1:5);
C = T.Alone(1:5);
group =[ones(size(A));2*ones(size(B));3*ones(size(C))];
figure
hold on
boxplot([A;B;C],group,'color','k')
scatter(group, [A;B;C],'k')
somenames={'Total'; '1'; '2' };

採用された回答

dpb
dpb 2023 年 9 月 27 日
編集済み: dpb 2023 年 10 月 5 日
Read the "More About" section of the boxplot doc that explains the output plot -- in particular,
  • observation within the whisker length (the adjacent value).
  • Observations beyond the whisker length are marked as outliers. By default, an outlier is a value that is more than 1.5 times the interquartile range away from the bottom or top of the box. However, you can adjust this value by using additional input arguments. An outlier appears as a red + sign. (emphasis added --dpb)
Per the usual caveat, to be able to dig deeper would take having the actual data, at least for that case...although knowing there were 5 points can create a sample dataset that duplicates the appearance
v=[25 38 40 40 65];
subplot(1,3,2)
boxplot(v,'color','k')
hold on
scatter(1,v)
ylim([0 305])
q=quantile(v,[0.25 0.75])
q = 1×2
34.7500 46.2500
v(v>q(2)&v<max(v))
ans = 1×0 empty double row vector
shows that there are no points less than the max that are greater than the upper (75th) quantile and by definition of an outlier as above/below 1.5x the quantile range
upperoutlimit=q(2)+1.5*diff(q)
upperoutlimit = 63.5000
outlier=(v(end)>=upperoutlimit)
outlier = logical
1
shows the last point is, indeed, an outlier by that definition and since there's no other value sabove the upper quantile as max that is not an outlier, there is no upper whisker to show that value.
loweroutlimit=q(1)-1.5*diff(q)
loweroutlimit = 17.5000
outlier=(v(1)<=loweroutlimit)
outlier = logical
0
You'll be able to verify the same tests with the exact values you have/used.
The particular dataset is anomalous owing to the one outlier and in having so few elements that that one outlier creates the situation you see.
As far as the standard deviation, the box plot doesn't show it at all at any time.
  2 件のコメント
Sarah Ford
Sarah Ford 2023 年 10 月 4 日
Its obvious that I need to brush up on my statistics. Thanks a lot this is very helpful
dpb
dpb 2023 年 10 月 4 日
編集済み: dpb 2023 年 10 月 5 日
No problem...I always have to get a refresher on boxplot details myself since don't use them daily...

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by