PythonでBrunnerMunzel並び替えテストをやってみる

特に意味があってではないのですがPythonでできないかなと思ってちょっといじってみました。環境とかが面倒なのでGoogle colabです。

import numpy as np
import scipy
import math
from permutations_stats.permutations import permutation_test
x=[(数値),(数値),・・・]
y=[(数値),(数値),・・・・]
permutation_test(x,y,test="brunner_munzel")

あれ、エラーが出る・・・。

!pip3 install permutations_stats

これで解決しました。もしかしてwelchでもできる?と思いましたが簡単にできることはなく

import numpy as np
from permutations_stats.permutations import permutation_test
x=[0,0,0,1,1,1,0]
y=[30,20,19,18,15,10]
permutation_test(x, y,test="ttest")
ValueError: Incorrect `test` name specified, must be one of ['brunner_munzel', 'friedman', 'friedman_t2', 'mann_whitney', 'wilcoxon'] or a function must be passed as `stat_func`

testにwelchのt検定が選択肢としてなかった・・・。

import numpy as np
from scipy.stats import ttest_ind
x=[8,4,4,1,1,1,0]
y=[11,25,19,18,15,15]
ttest_ind(x, y, equal_var=False, permutations=?)

あれ、並び替えのところどうすればいいんだ?

import numpy as np
from scipy.stats import ttest_ind
x=[8,4,4,1,1,1,0]
y=[11,25,19,18,15,15]
ttest_ind(x, y, equal_var=False, permutations=10000)

TtestResult(statistic=-6.535350141691651, pvalue=0.0005827505827505828, df=nan)

?のところには組み合わせの数が入るのでとりあえずありえないほど大きな数を入れておけば勝手に必要なところまで計算してくれるようでした。この場合はbinom(7,6)を計算すると7なので7以上であれば良いようです。

この記事が気に入ったらサポートをしてみませんか?