matlab f检验,在Matlab中实现Levene方差齐性检验

在Matlab中实现SPSS在独立样本t检验时候先进行的Levene方差齐性检验

z1mean=mean(z1);

z2mean=mean(z2);

z_ave=(sum(z1)+sum(z2))/NN;

SS1=N(1)*(z1mean-z_ave)^2+N(2)*(z2mean-z_ave)^2;%across groups SS2=var(z1,0,1)*(N(1)-1)+var(z2,0,1)*(N(2)-1);%inner groups

W=((NN-k)*SS1)/((k-1)*SS2);

df1=k-1;

df2=NN-k;%DOF

p=fcdf(W,df1,df2);%if tail==-1 %left-tailed test

p=1-p;% if this p<0.05, then normal two sample t-test cannot be applied h=cast(p <= 0.05, class(p));

ci = cat(dim, zeros(size(W)), ...

W./finv(alpha,df1,df2));

clear z1 z2 SS1 SS2 z_ave NN N xmean ymean z1mean z2mean x y alpha k % % if tail == 0 % two-tailed test

% p = 2*min(fcdf(F,df1,df2),fpval(F,df1,df2));

% ci = cat(dim, F.*finv(alpha/2,df2,df1), ... % ==

F./finv(1-alpha/2,df1,df2)

% F./finv(alpha/2,df1,df2));

% end

% % if tail == 1 % right one-tailed test

% p = fpval(F,df1,df2);

% ci = cat(dim, F.*finv(alpha,df2,df1), ... % ==

F./finv(1-alpha,df1,df2)

% Inf(size(F)));

% end

end

鉴于检查方差齐性只是看组间方差小于组内方差的显著性,故默认使用left-tailed test。如有相关需要也可在程序中直接修改。

你可能感兴趣的:(matlab,f检验)