notBoxPlot - alternative to box plots.
28 Jan 2010
23 Apr 2015)
This function visualizes raw (grouped) data along with the mean, 95% confidence interval, and 1 SD.
function sem=SEM_calc(vect, CI)
% SEM_calc - standard error of the mean, confidence interval
% function sem=SEM_calc(vect, CI)
% Calculate the standard error the mean to a given confidence
% interval (CI). Note that nans do not contribute to the
% calculation of the sample size and are ignored for the SD
% calculation. Output of this function has been checked against
% known working code written in R.
% - vect: A vector upon which the SEM will be calculated. Note that
% if vect is a matrix then we calculate one SEM for each
% - CI [optional]: a p value for a different 2-tailed interval. e.g. 0.01
% This is a 2-tailed interval.
% sem - the standard error of the mean. So to plot the interval it's mu-sem
% to mu+sem.
% Example - plot a 1% interval [rather than the default %5]
% hold on
% plot(mean(r), mean(ylim),'r*')
% plot([mean(r)-S,mean(r)+S], [mean(ylim),mean(ylim)],'r-')
% hold off
% Rob Campbell
% Also see - tInterval_Calc, norminv
stdCI = 1.96 ;
CI = CI/2 ; %Convert to 2-tail
stdCI = abs(norminv(CI,0,1)) ;
sem = ( (nanstd(vect)) ./ sqrt(sum(~isnan(vect))) ) * stdCI ;