0
我試圖從數據的平均值和標準偏差(std)繪製置信區間。這是我寫的一段代碼:繪製從均值和標準差的置信區間
MeanA=1.876; %mean of A
STDA=0.018; % std of A
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 ];
如果我繪製正態分佈那麼他們cofidence inteval似乎重疊
alpha = 0.05; % significance level
for 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
我obtined地塊那裏是在置信區間重疊(CI) 。
現在我需要繪製CI的形式;
別人的幫助可以繪製CI各地平均
%%
我在下列方式計算詞:
SE2=errY/sqrt(10);
CI2n=Y-1.96*(SE2);
CI2p=Y+1.96*(SE2);
請告訴我們,如果它的正確方法和如果是的話,我該如何繪製它們。由於