LoginSignup
1
1

More than 1 year has passed since last update.

scipy.stats: 正規分布の検定(オムニバス検定) normaltest

Posted at

正規分布の検定(オムニバス検定) normaltest

データは正規分布からの標本といえるか?の検定。

$H_0$:母分布は正規分布である。

$H_1$:母分布は正規分布ではない。

以下の 2 論文に基づいたオムニバス検定である。

  1. D'Agostino, R. B. (1971), "An omnibus test of normality for
    moderate and large sample size", Biometrika, 58, 341-348
  2. D'Agostino, R. and Pearson, E. S. (1973), "Tests for departure from
    normality", Biometrika, 60, 613-622

normaltest(a, axis=0, nan_policy='propagate')

1. 正規乱数について検定を行う

平均値=50,標準偏差=10 の正規乱数 25 個について検定を行う。

from scipy.stats import norm
import numpy as np
np.random.seed(123)

x = np.round(norm.rvs(loc=50, scale=10, size=25), 1)
print(*x)
39.1 60.0 52.8 34.9 44.2 66.5 25.7 45.7 62.7 41.3 43.2 49.1 64.9 43.6 45.6 45.7 72.1 71.9 60.0 53.9 57.4 64.9 40.6 61.8 37.5
normaltest(x)
NormaltestResult(statistic=1.0656167729164954, pvalue=0.5869542584547112)

オムニバス検定とは,一般に,同じデータに対する独立な $k$ 個の正規分布にしたがう検定統計量の二乗和が自由度 $k$ の $\chi^2$分布に漸近するというものである。

今回は,skewtest(x) および kurtosistest(x) が返す独立な z 値 の二乗和が自由度 2 の $\chi^2$ 分布に近似できるとする仮説検定である。

from scipy.stats import skewtest, kurtosistest
from scipy.stats import chi2
s, ps = skewtest(x) # s は歪度の検定の Z 値
k, pk = kurtosistest(x) # k は尖度の検定の Z 値
print(s, k)
statistic = s**2 + k**2 # 検定統計量
print('statistic =', statistic, '  df = 2')
print('p value =', chi2.sf(statistic, 2))
-0.022210278084285384 -1.032048194835839
statistic = 1.0656167729164954   df = 2
p value = 0.5869542584547112

$p \gt 0.05$ ゆえ,帰無仮説は棄却できない($p = 0.587$)。したがって,このデータは正規分布に従っていないとはいえないと結論する。

2. 正規乱数ではないものについて検定を行う

自由度 1 の $t$ 分布(すなわちコーシー分布)にしたがう乱数 25 個に対して検定を行ってみる。

from scipy.stats import t
import numpy as np
np.random.seed(123)

y = np.round(t.rvs(df=1, loc=50, scale=10, size=25), 1)
print(*y)
16.2 58.9 -0.0 42.4 44.1 45.3 56.6 79.1 119.6 26.6 20.6 46.9 30.4 51.7 54.6 49.3 70.2 88.0 50.3 61.7 21.9 108.7 671.3 87.3 64.7
normaltest(y)
NormaltestResult(statistic=58.02809862697257, pvalue=2.5081787582156243e-13)

$p \lt 0.05$ ゆえ,帰無仮説を棄却する($p \lt 0.00001$)。したがって,このデータは正規分布に従っていないと結論する。


1
1
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
1
1