0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Octave で母平均の検定

1 標本データで,母平均が指定した値であるかどうかを検定する。

対応のある 2 標本データの場合は,対のデータの差をとったベクトルを与えてやればよい。

t_test() は母分散が未知の場合の検定である。母分散が既知の場合に z_test() があるが,母分散が既知などということはめったに無いことなので存在意義が全く無い(使用してはいけない)。

usage:
 [pval, t, df] = t_test (x, m, alt)

x はデータベクトル
m は特定の値
alt はデフォルトで両側検定 "!="
    片側検定は,帰無仮説が「母平均 > m」なら ">", その逆なら "<" で指定
戻り値を指定しない場合は p 値のみを表示する
pkg load statistics   % statistics が必要
format long           % 表示精度を高くする(任意)
x = [49.6; 52.5; 48.3; 50.6; 56.7; 32.8; 51.6; 46.1; 54.6; 52.0; 39.3; 49.5; 45.1; 37.1; 63.9;
     48.3; 37.4; 33.4; 37.8; 51.2; 63.0; 74.3; 54.4; 60.1; 55.6; 61.2];
y = [48.7; 36.8; 51.9; 65.5; 62.6; 57.3; 43.3; 57.7; 61.4; 69.8; 48.0; 37.1; 29.8; 53.6; 49.3;
     50.2; 46.1; 50.6; 51.4; 61.0; 50.8; 51.7; 52.4; 57.3; 55.4; 62.6];
z = x - y;
mean(z)
ans = -2.149999999999999

対応のある 2 標本の平均値の差が有意かどうかは,それぞれの測定値の差のベクトル(z の母平均が 0 であるかどうか(つまり,$m=0$)を検定すればよい。

t_test(z, 0);
  pval: 0.384954
[pval, t, df] = t_test(z, 0);
printf("t = %.5g,  df = %d,  p value = %.5g\n", t, df, pval)
t = -0.88431,  df = 25,  p value = 0.38495
[pval, t, df] = t_test(z, 0, "<");
printf("t = %.5g,  df = %d,  p value = %.5g\n", t, df, pval)
t = -0.88431,  df = 25,  p value = 0.19248
[pval, t, df] = t_test(z, 0, ">");
printf("t = %.5g,  df = %d,  p value = %.5g\n", t, df, pval)
t = -0.88431,  df = 25,  p value = 0.80752

z の母分散は未知であるが,標本分散を使ってみよう。

z_test(z, 0, var(z))
Z-test of mean(x) == 0 against mean(x) != 0,
with known var(x) == 153.688:
  pval = 0.376529
ans = 0.376528522678127

t_test() は $t$ 分布を使用するが,z_test() は標準正規分布による近似である。サンプルサイズが小さい場合には近似は十分ではない。

近似計算などする必要がないし,母分散は未知なのだから,t_test() を使えばよいのである。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?