Engineering Skills

製品開発エンジニアがデータ解析のノウハウを垂れ流します

2標本におけるバラツキの差の検定(1)

2標本におけるバラツキ差のノンパラメトリック検定を実装してみます。今回はMood検定、Klots検定、Savege検定、Siegel-Tukey検定、Ansari-Bradley検定、Sukhatme検定です。

Mood検定

Mood検定は1954年に提案されています。中央値が等しいことが分かっている2群のサンプルに対して、バラツキに差があるか検定します。

Mood検定では2つのデータ群をマージして昇順でランク付けします。

各郡のサンプル数を[math] \displaystyle n_1 [/math][math] \displaystyle n_2 [/math]、サンプル数の和を[math] \displaystyle N = n_1 + n_2 [/math]として、重複なしなら順位[math] \displaystyle R [/math]は下記のようになります。

[math] \displaystyle 1 \ 2 \ 3 \dots \ N [/math]

この順位付けを用いて統計量[math] \displaystyle M [/math]を計算します。

[math] \displaystyle M = \sum_{i=1}^{n_1}{(R_{i} - \frac{N+1}{2})^2} [/math]

検定統計量[math] \displaystyle T_M [/math]は大標本での正規分布近似で下記のように計算します。

[math] \displaystyle E= \frac{n_1(N^2-1)}{12} [/math]
[math] \displaystyle V= \frac{n_1 n_2(N + 1)(N^2-4)}{180} [/math]
[math] \displaystyle T_M = \frac{M-E}{\sqrt{V}} [/math]

Klots検定

Klots検定はMood検定と同様のランク付けに基づいて計算します。

この順位付けを用いて統計量[math] \displaystyle K [/math]を計算します。

[math] \displaystyle K = \sum_{i=1}^{n_1}{ \left[ \phi^{-1}( \frac{R_{i}}{N+1})\right]^2 } [/math]

検定統計量[math] \displaystyle T_M [/math]は大標本での正規分布近似で下記のように計算します。

[math] \displaystyle E= \frac{n_1}{N} \sum_{i=1}^{N}{ \left[ \phi^{-1}( \frac{R_{i}}{N+1})\right]^2 } [/math]
[math] \displaystyle V= \frac{n_1 n_2}{N(N - 1)} \sum_{i=1}^{N}{ \left[ \phi^{-1}( \frac{R_{i}}{N+1}) \right]^4 } -\frac{n_2}{n_1(N-1)} E ^2 [/math]
[math] \displaystyle T_K = \frac{M-E}{\sqrt{V}} [/math]

Savage検定

Savage検定もMood検定と同様のランク付けに基づいて計算します。正の値だけを取るデータが対称です。

統計量[math] \displaystyle S [/math]を計算します。

[math] \displaystyle S = \sum_{i=1}^{n_1}{ \left( \frac{1}{N} + \frac{1}{N-1} + \dots + \frac{1}{N-R_{i}+1} \right) } [/math]

検定統計量[math] \displaystyle T_S [/math]は大標本での正規分布近似で下記のように計算します。

[math] \displaystyle E= n_1 [/math]
[math] \displaystyle V= \frac{n_1 n_2}{N - 1} \left(1 - \sum_{i=1}^{N} \frac{1}{i} \right) [/math]
[math] \displaystyle T_S = \frac{M-E}{\sqrt{V}} [/math]

Siegel-Tukey検定

Siegel-Tukey検定は1960年代に開発されました。Siegel-Tukey検定はWilcoxon Rank Sum検定に似ています。2群のサンプルの中央値が同一なら、バラツキが大きいサンプル群が大きなスコアを持つように計算されます。

Siegel-Tukey検定では特殊な順位付けが為されます。2つのデータ群をマージし混合でランク付け、最小値>最大値>2番目の最小値>2番目の最大値という風に交互に順位付けしていきます。

各郡のサンプル数を[math] \displaystyle n_1 [/math][math] \displaystyle n_2 [/math]、サンプル数の和を[math] \displaystyle N = n_1 + n_2 [/math]として、重複なしなら順位[math] \displaystyle R_{st} [/math]は下記のようになります。

[math] \displaystyle 1 \ 4 \ 5 \ 8 \ 9 \dots N \dots 7 \ 6 \ 3 \ 2 [/math]

この順位付けを用いて統計量[math] \displaystyle U [/math]を計算します。統計量Uは[math] \displaystyle U_1 [/math][math] \displaystyle U_2 [/math]のうち小さい方とします。

[math] \displaystyle U_1 = \sum_{i=1}^{n_1}{R_{sk_i}} - \frac{1}{2}n_1(n_1+1) [/math]
[math] \displaystyle U_2 = \sum_{i=1}^{n_2}{R_{sk_i}} - \frac{1}{2}n_2(n_2+1) [/math]

検定統計量[math] \displaystyle T_U [/math]は大標本での正規分布近似で下記のように計算します。

[math] \displaystyle E= -\frac{1}{2}+\frac{1}{2}n_1 n_2 [/math]
[math] \displaystyle V= \frac{n_1 n_2(N + 1)}{12} [/math]
[math] \displaystyle T_U = \frac{U-E}{\sqrt{V}} [/math]

Ansari-Bradley検定

Ansari-Bradley検定は、位置が等しいことがわかっている二母集団に対して「バラツキが等しいかどうか」を検定します。第1群の分布関数を第2群の分布関数とおいて帰無仮説を検定するイメージです。

Ansari-Bradley検定では特殊な順位付けが為されます。2つのデータ群をマージし混合でランク付け、小さいほうから半分までは「1,2,3,…」と昇順で順位をつけ,残りは「…,3,2,1」と降順で順位をつけます。

各郡のサンプル数を[math] \displaystyle n_1 [/math][math] \displaystyle n_2 [/math]、サンプル数の和を[math] \displaystyle N = n_1 + n_2 [/math]として、重複なしなら順位[math] \displaystyle R_{ab} [/math]は下記のようになります。

[math] \displaystyle 1 \ 2 \ 3 \ 4 \dots \frac{N}{2} \dots 4 \ 3 \ 2 \ 1 [/math]

この順位付けを用いて統計量Aを計算します。

[math] \displaystyle A = \sum_{i=1}^{n_1}{R_{ab_i}} [/math]
[math] \displaystyle T_A = \frac{A-E}{\sqrt{V}} [/math]

[math] \displaystyle N [/math]が偶数の場合

[math] \displaystyle E= \frac{n_1(N+2)}{4} [/math]
[math] \displaystyle V= \frac{n_1 n_2(N-2)(N+2)}{48(N-1)} [/math]

[math] \displaystyle N [/math]が奇数の場合

[math] \displaystyle E= \frac{n_1(N+1)^2}{4N} [/math]
[math] \displaystyle V= \frac{n_1 n_2(N+1)(N^2 + 3)}{48N^2} [/math]

Sukhatme検定

Sukhatme検定は中央値が0のデータを対象とします。あるいは中央値などで規格化したデータが対称です。

統計量[math] \displaystyle SK [/math]は下記で計算されます。

[math] \displaystyle SK = \frac{1}{ n_{1} n_{2} }\sum_{i=1}^{n_1}{\sum_{j=1}^{n_2}{ D(X_i , Y_j) }} [/math]

ここで

[math] \displaystyle D(X , Y) = \left\{ \begin{array}{l} 1; \quad 0 < X < Y \quad or \quad Y < X < 0 \\ 0; \quad otherwise \end{array} \right. [/math]

検定統計量[math] \displaystyle T_{SK} [/math]は大標本での正規分布近似で下記のように計算します。

[math] \displaystyle E= 0.25 [/math]
[math] \displaystyle V= \frac{N+7}{48n_1 n_2} [/math]
[math] \displaystyle T_{SK} = \frac{M-E}{\sqrt{V}} [/math]

まとめ

Mood検定、Klots検定、Savege検定、Siegel-Tukey検定、Ansari-Bradley検定、Sukhatme検定について、こちらのツールに実装してみました。