LoginSignup
1
1

More than 1 year has passed since last update.

scipy.stats: マン・ホイットニーの U 検定(ウィルコクソンの順位和検定) mannwhitneyu

Posted at

scipy.stats: マン・ホイットニーの U 検定(ウィルコクソンの順位和検定) mannwhitneyu

from scipy.stats import mannwhitneyu

mannwhitneyu(x, y, use_continuity=True, alternative='two-sided', axis=0, method='auto', *, nan_policy='propagate')

  • use_continuity : method'asymptotic' の場合は,デフォルト(True)で連続性の補正を行う。
  • alternative : デフォルトで両側検定 'two-sided'。片側検定の場合には 'less', 'greater'
  • method : デフォルトは 'auto' であるが,明示的に指定するほうがよい。
    • 'asymptotic' : 同順位補正をして標準正規分布で漸近検定。
    • 'exact' : 同順位補正はせず,正確な $p$ 値を求める。
    • 'auto' : いずれかのサンプルサイズが 8 未満で同順位がないときには 'exact',それ以外のときは 'asymptotic' をとる。
x = [0.80, 0.83, 1.89, 1.04, 1.45, 1.38, 1.91, 1.64, 0.73, 1.46]
y = [1.15, 0.88, 0.90, 0.74, 1.21]

from scipy.stats import mannwhitneyu
mannwhitneyu(x, y, alternative='greater')
MannwhitneyuResult(statistic=35.0, pvalue=0.1272061272061272)

この例の場合,use_continuity=False だけでは「連続性の補正をしない」事にならない。method='asymptotic' を指定しなければならない。

mannwhitneyu(x, y, alternative='greater', use_continuity=False)
MannwhitneyuResult(statistic=35.0, pvalue=0.1272061272061272)
mannwhitneyu(x, y, alternative='greater', use_continuity=False, method='asymptotic')
MannwhitneyuResult(statistic=35.0, pvalue=0.11033568095992347)

欠損値は np.NaN を使う。

import numpy as np
from numpy import NaN as NA

x = np.array([41, 36, 12, 18, NA, 28, 23, 19, 8, NA, 7, 16, 11, 14, 18, 14, 
    34, 6, 30, 11, 1, 11, 4, 32, NA, NA, NA, 23, 45, 115, 37])
y = np.array([96, 78, 73, 91, 47, 32, 20, 23, 21, 24, 44, 21, 28, 9, 13, 
    46, 18, 13, 24, 16, 13, 23, 36, 7, 14, 30, NA, 14, 18, 20])

以下のように指定して検定を行うと,このデータの場合には method='asymptotic', use_continuity=True を指定したことになる。

R の wilcox.test と同じ結果になる。

mannwhitneyu(x, y, nan_policy='omit')
MannwhitneyuResult(statistic=284.0, pvalue=0.11859308339648639)
mannwhitneyu(x, y, nan_policy='omit', method='asymptotic', use_continuity=True)
MannwhitneyuResult(statistic=284.0, pvalue=0.11859308339648639)
`method=exact` を指定した結果はR  coin::wilcox_test の結果($p$ = 0.1182とは異なる
mannwhitneyu(x, y, nan_policy='omit', method='exact')
MannwhitneyuResult(statistic=284.0, pvalue=0.11950059110563417)
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