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 でクラスカル・ウォリス検定

Posted at

Octave でクラスカル・ウォリス検定

独立 $k$ 標本の代表値の差のノンパラメトリック検定である。

kruskal_wallis_testkruskalwallis があるが,引数の指定法と箱ひげ図が描けるかどうかの違いで,本質的には同じである。

使用例 1

kruskal_wallis_test の場合

usage 1:
[pval, k, df] = kruskal_wallis_test (x1, …)

引数は,各グループの測定値ベクトルを列挙する
戻り値を指定しない場合は p 値のみが表示される
戻り値を指定した場合は,後で変数を使用する(表示するなど)ことができる
# statistics が必要
pkg load statistics

% 表示精度を高くする(任意)
format long
x1 = [2;1;2;3;3;2;2;1;2;3;4];
x2 = [1;1;2;2;2;2;3;2;1;2;3;4;5;2];
x3 = [2;1;2;1;2;3;3;3];
kruskal_wallis_test(x1, x2, x3);
pval: 0.959295

戻り値を変数に代入する場合

[p, k, df] = kruskal_wallis_test(x1, x2, x3);
printf("chisq = %.5g,  df = %d,  p value = %.5g\n", k, df, p)
chisq = 0.083114,  df = 2,  p value = 0.95929

使用例 2

kruskalwallis の場合

usage 2:
p = kruskalwallis (x, g)
p = kruskalwallis (x, g, displayopt)
[p, tbl] = kruskalwallis (x, …)
[p, tbl, stats] = kruskalwallis (x, …)

y は測定値ベクトル,g は測定値がどのグループのものかを示すベクトル
分散分析表が表示される
displayopt は,デフォルトで "on" であり,箱ひげ図も描かれる(描かないためには "off" を指定する)
x = [x1; x2; x3]; % 使用例 1 より
g1 = repmat(1, length(x1), 1);
g2 = repmat(2, length(x2), 1);
g3 = repmat(3, length(x3), 1);
g = [g1; g2; g3];

分散分析表と共にデフォルトで箱ひげ図が描かれる。

kruskalwallis(x, g)
              Kruskal-Wallis ANOVA Table
Source        SS      df      MS      Chi-sq  Prob>Chi-sq
---------------------------------------------------------
Columns       6.86     2       3.43     0.08  9.59295e-01
Error      2634.64    30      87.82
Total      2641.50    32
ans = 0.959294686028659

output_10_1.png

tblstats には多くの情報が含まれるが,必要なものを取り出して使う。

[p, tbl, stats] = kruskalwallis(x, g, "off");
chisq = tbl{2,5}
df = tbl{2,3}
p
chisq = 8.311393319911214e-02
df = 2
p = 0.959294686028659
printf("chisq = %.5g,  df = %d,  p value = %.5g\n", chisq, df, p)
chisq = 0.083114,  df = 2,  p value = 0.95929
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?