Data Visualization – Plotting Confidence Interval Bars from Summary Statistics

boxplotconfidence intervaldata visualizationdescriptive statisticssoftware

A bit like a box plot. I mean not necessarily the standard upper confidence interval, lower confidence interval, mean, and data range-showing box plots, but I mean like a box plot with just the three pieces of data: the 95% confidence interval and mean.

This is a screenshot of a journal article which had exactly what I want: enter image description here

I would also like to know how I would use the software the answerer mentions to create such a plot.

Best Answer

In MATLAB, you might want to try the errorbar function: http://www.mathworks.de/de/help/matlab/ref/errorbar.html

Alternatively, you can do it the dumb and manual way. For example, given a matrix of data points "a", you can calculate your means using the function m = mean(a), calculate your CIs (depending on what CI you need), and plot the results by hand.

Demonstration if you already know the mean and CI, assuming CIs are in a matrix CI (first and second column) and means are in a matrix a:

plot(1:length(CI),a,'o','markersize', 10)           % plot the mean
hold on;
plot(1:length(CI),CI(1,:),'v','markersize', 6)              % plot lower CI boundary
hold on;
plot(1:length(CI),CI(2,:),'^','markersize', 6)              % plot upper CI boundary
hold on;

for I = 1:length(CI)                                        % connect upper and lower bound with a line
line([I I],[CI(1,I) CI(2,I)])
hold on;
end;

axis([0 length(CI)+1 min(CI(1,:))*0.75 max(CI(2,:))*1.25])  % scale axis

Demonstration in the case where you know individual measurements, for a repeated-measures experiment, 3+ conditions, one condition per column, one subject per line in matrix a, no missing samples, 95% CI as by MATLAB's ttest():

[H,P,CI] = ttest(a);                                        % calculate 95% CIs for every column in matrix a
                                                            % CIs are now in the matrix CI!

plot(1:length(CI),[mean(a)],'o','markersize', 10)           % plot the mean
hold on;
plot(1:length(CI),CI(1,:),'v','markersize', 6)              % plot lower CI boundary
hold on;
plot(1:length(CI),CI(2,:),'^','markersize', 6)              % plot upper CI boundary
hold on;

for I = 1:length(CI)                                        % connect upper and lower bound with a line
line([I I],[CI(1,I) CI(2,I)])
hold on;
end;

axis([0 length(CI)+1 min(CI(1,:))*0.75 max(CI(2,:))*1.25])  % scale axis
Related Question