Error bar with CI 95 on bar graph

43 Ansichten (letzte 30 Tage)
Anum Ali
Anum Ali am 15 Nov. 2019
Bearbeitet: Adam Danz am 9 Dez. 2020
Hi,
Can anyone tell how to apply CI 95% error bars on grouped bar graph.
Thanks
  6 Kommentare
Adam Danz
Adam Danz am 15 Nov. 2019
Bearbeitet: Adam Danz am 15 Nov. 2019
Your method of computing CIs (using tinv) requires that your data form a normal distribution. You're also only computing 1-tail of the CI, is that intentional?
Anum Ali
Anum Ali am 15 Nov. 2019
I require something like thisconfidence.png

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Adam Danz
Adam Danz am 15 Nov. 2019
Bearbeitet: Adam Danz am 9 Dez. 2020
Here's an anonymous function that computes the 95% CI based on the tinv method which requires that your data approximately form a normal distirbution. See this link for more information on this function.
% x is a vector, matrix, or any numeric array of data. NaNs are ignored.
% p is a the confident level (ie, 95 for 95% CI)
% The output is 1x2 vector showing the [lower,upper] interval values.
CIFcn = @(x,p)std(x(:),'omitnan')/sqrt(sum(~isnan(x(:)))) * tinv(abs([0,1]-(1-p/100)/2),sum(~isnan(x(:)))-1) + mean(x(:),'omitnan');
% Demo
% x = randn(100,1) + 5;
% p = 95;
% CI = CIFcn(x,p)
Here's a demo using your code
EE = [0.0363 0.0312 0.0274 0.0244 0.0220 0.0200 0.0183 0.0168 0.0155 0.0143];
CIFcn = @(x,p)std(x(:),'omitnan')/sqrt(sum(~isnan(x(:)))) * tinv(abs([0,1]-(1-p/100)/2),sum(~isnan(x(:)))-1) + mean(x(:),'omitnan');
CI = CIFcn(EE,96);
% Compute the distance of the upper and lower bounds
CIdist = abs(CI-mean(EE));
% plot
plot(1, mean(EE), 'bo')
hold on
errorbar(1, mean(EE), CIdist(1), CIdist(2))
ylim([0, .05])
grid on
  4 Kommentare
Anum Ali
Anum Ali am 15 Nov. 2019
Ya I get the concept of your solution but now I edited to all data still it gave the error
Error using errorbar (line 70)
X, Y, and error bars all must be the same length.
Error in ra30 (line 206)
errorbar(p_device, EE,CI)
because CI only had two values ? why CI has two values?
Adam Danz
Adam Danz am 15 Nov. 2019
Bearbeitet: Adam Danz am 15 Nov. 2019
I couldn't possibly answer that without knowing what inputs you're providing.
I have no idea what your data look like. Are you provding the CIFcn() function a matrix? a vector? If you're providing a matrix and you'd like to compute the CIs for each column, you'll need to provide each column as input individually or rewrite the function.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by