1
0

More than 1 year has passed since last update.

scipy.stats: ウィルコクソンの符号付順位和検定 wilcoxon

Posted at

scipy.stats: ウィルコクソンの符号付順位和検定 wilcoxon

wilcoxon(x, y=None, zero_method='wilcox', correction=False, alternative='two-sided', mode='auto', *, axis=0, nan_policy='propagate')

zero_method はデフォルト以外に 2 つあるが,一般的ではないのでデフォルトのままがよいであろう。

mode'auto', 'exact', 'approx' の 3 通りであるが,'exact''approx' を明示的に指定したほうがよい。

correctionmode='approx' のときに連続性の補正をするとき True を指定する。デフォルトは False

alternative はデフォルトで両側検定 'two-sided'。片側検定の場合には対立仮説の方向により 'greater''less'

from scipy.stats import wilcoxon
import numpy as np
x = np.array([1.83,  0.50,  1.62,  2.48, 1.68, 1.88, 1.55, 3.06, 1.30])
y = np.array([0.878, 0.647, 0.598, 2.05, 1.06, 1.29, 1.06, 3.14, 1.29])
wilcoxon(x, y, mode='exact', alternative='greater')
WilcoxonResult(statistic=40.0, pvalue=0.01953125)

前もって差をとり,一つの引数で与える場合も同じ結果になる。

wilcoxon(x - y, mode='exact', alternative='greater')
WilcoxonResult(statistic=40.0, pvalue=0.01953125)
wilcoxon(x - y, mode='approx', correction=False, alternative='greater')
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scipy/stats/_morestats.py:3159: UserWarning: Sample size too small for normal approximation.
  warnings.warn("Sample size too small for normal approximation.")





WilcoxonResult(statistic=40.0, pvalue=0.019075855086707567)
wilcoxon(x - y, mode='approx', correction=True, alternative='greater')
WilcoxonResult(statistic=40.0, pvalue=0.022005492006475714)

小数点付きのデータを使うときは注意が必要である。以下のデータに対する 2 通りの検定は同じ結果を与える。

v = np.array([0.8, 0.7, 0.8, 1.1, 0.8, 1.0, 0.4, 0.6, 1.0, 0.9, 0.7, 0.7, 0.7, 0.6, 0.9, 1.0, 0.9, 0.4, 1.1, 1.0])
w = np.array([0.8, 0.6, 0.9, 1.0, 1.0, 1.1, 0.5, 0.5, 0.9, 1.0, 0.5, 0.6, 0.8, 0.6, 0.8, 0.9, 0.8, 0.7, 1.1, 1.1])
wilcoxon(v, w, mode='approx', alternative='less')
WilcoxonResult(statistic=66.5, pvalue=0.31366091966486587)
wilcoxon(v - w, mode='approx', alternative='less')
WilcoxonResult(statistic=66.5, pvalue=0.31366091966486587)

しかしそれぞれのデータを10倍して,整数値として検定を行うと前二者の結果と異なる。こちらのほうが正しい結果である。

v10 = np.array([8, 7, 8, 11, 8, 10, 4, 6, 10, 9, 7, 7, 7, 6, 9, 10, 9, 4, 11, 10])
w10 = np.array([8, 6, 9, 10, 10, 11, 5, 5, 9, 10, 5, 6, 8, 6, 8, 9, 8, 7, 11, 11])
wilcoxon(v10 - w10, mode='approx', alternative='less')
WilcoxonResult(statistic=75.5, pvalue=0.47978797468487205)
wilcoxon(v*10 - w*10, mode='approx', alternative='less')
WilcoxonResult(statistic=75.5, pvalue=0.47978797468487205)

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