2007年4月10日火曜日

対応なしのt検定:2 標本の平均値の差の検定

%MATLABの場合
echo on
N1 = 20;
N2 = 30;
x = rand(N1,1); % 標本1の一様分布の擬似乱数
x_mea = mean(x); % 標本1の平均値
disp(x_mea);
0.5539
x_std = std(x); % 標本1の不偏標準偏差
disp(x_std);
0.3199
y = rand(N2,1); % 標本2の一様分布の擬似乱数
y_mea = mean(y); % 標本2の平均値
disp(y_mea);
0.5384
y_std = std(y); % 標本2の不偏標準偏差
disp(y_std);
0.2955
%帰無仮説: x_mea(標本1の平均値)は,y_mea(標本1の平均値)である
%対立仮説: x_mea(標本1の平均値)は,y_mea(標本1の平均値)ではない
%両側5%有意水準でttest2を実行する
%2つの独立な標本が平均の等しい分布
[h,p,ci,stats] = ttest2(x,y); %共同(pooled)または共同ではない(unpooled)分散をもつ2標本T-検定
str = sprintf('h = %1.2f, p = %f, ci = [%f,%f]',h,p,ci(1),ci(2));
%h = 0 -> 帰無仮説は、棄却しない。つまり、x_mea(標本1の平均値)は,x_mea(標本2の平均値)である
disp(str);
h = 0.00, p = 0.861089, ci = [-0.161731,0.192748]
disp(stats);
tstat: 0.1759
df: 48
sd: 0.3054
disp(stats.sd);
0.3054
%2つの標本が、未知、または等しくない分散
[h,p,ci,stats] = ttest2(x,y,[],[],'unequal'); %共同(pooled)または共同ではない(unpooled)分散をもつ2標本T-検定
str = sprintf('h = %1.2f, p = %f, ci = [%f,%f]',h,p,ci(1),ci(2));
%h = 0 -> 帰無仮説は、棄却しない。つまり、x_mea(標本1の平均値)は,x_mea(標本2の平均値)である
disp(str);
h = 0.00, p = 0.863469, ci = [-0.165760,0.196777]
disp(stats);
tstat: 0.1731
df: 38.5863
sd: [2x1 double]
disp(stats.sd);
0.3199
0.2955

0 件のコメント: