matlab - Ploting Confidence interval from only mean and standard deviation -


i trying plot confidence interval mean , standard deviation (std) of data. here piece of code wrote:

 meana=1.876; %mean of  stda=0.018; % std of meanb=1.821; stdb=0.039;  meanc=1.735;  stdc=0.023;  meand=1.667; stdd=0.039;  y = [meana meanb ;        meanc meand ];      erry= [stda stdb;          stdc   stdc ]; 

if plot normal distribution cofidence inteval seems overlap

 alpha = 0.05;          % significance level   tt=1:length(y) figure mu = y(tt,1);               % mean  sigma = erry(tt,1);   cutoff1n = norminv(alpha, mu, sigma); cutoff2n = norminv(1-alpha, mu, sigma);  xn = [linspace(mu-4*sigma,cutoff1n), ... linspace(cutoff1n,cutoff2n), ... linspace(cutoff2n,mu+4*sigma)]; yn = normpdf(xn, mu, sigma); plot(xn,yn) mu = y(tt,2);               % mean sigma = erry(tt,2);   cutoff1 = norminv(alpha, mu, sigma); cutoff2 = norminv(1-alpha, mu, sigma); x = [linspace(mu-4*sigma,cutoff1), ... linspace(cutoff1,cutoff2), ... linspace(cutoff2,mu+4*sigma)]; y = normpdf(x, mu, sigma); hold on, plot(x,y) plot(x,y,'r-',xn,yn,'g-' , 'linewidth',3)  set(gca,'fontsize', 32) if tt==1 hleg1=legend('a', 'b'); title('study1') elseif tt==2 hleg1=legend('c', 'd'); title('study2')  end  set(hleg1,'location','northeastoutside')  set(gca,'fontsize',22)  xlo = [x(x<=cutoff1) cutoff1];  ylo = [y(x<=cutoff1) 0];  patch(xlo, ylo, 'r')  xhi = [cutoff2 x(x>=cutoff2)];  yhi = [0 y(x>=cutoff2)];  patch(xhi, yhi, 'r')  xlon = [xn(xn<=cutoff1n) cutoff1n];  ylon = [yn(xn<=cutoff1n) 0];   patch(xlon, ylon, 'g')    xhin = [cutoff2n xn(xn>=cutoff2n)];   yhin = [0 yn(xn>=cutoff2n)];   patch(xhin, yhin, 'g') end 

i obtined plots there overlapping in confidence interval (ci).

enter image description here

now need plot ci in form of ;

enter image description here

can plot ci around mean

%%

i calculating ci in following manner:

    se2=erry/sqrt(10);     ci2n=y-1.96*(se2);     ci2p=y+1.96*(se2); 

please tell if right way , if yes how can plot them. thanks

the 95% confidence interval on mean mu when standard deviation sigma known , sample size n given by

ci = mu +/- 1.96*sigma/sqrt(n) 

so mu = y , sigma = erry, computation of 95% confidence interval correct sample size of n = 10.

to plot these values error bars, try following using matlab's errorbar function (documentation):

n = 10; se2=erry/sqrt(n); = 1:size(se2,1)     figure     y = y(i,:);     x = 1:length(y);     e = 1.96*se2(i,:);     errorbar(1:length(y),y,e,e,'k.','markersize',18);     if == 1         c = ['a';'b'];     elseif == 2         c = ['c';'d'];     end     set(gca,'xtick',x,'xticklabels',c) end 

which produces this image (i want put image inline, lack sufficient rep).

you may notice confidence intervals not appear overlap. however, can obtain result in density plots setting n = 1, means ci = mu +/- 1.96*sigma. post second image, need more rep!


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -