1.游程检验
from statsmodels.sandbox.stats.runs import runstest_1samp
from statsmodels.sandbox.stats.runs import runstest_2samp
import numpy as np
#1samp
data=np.loadtxt("C:/Users/Administrator/Desktop/BaiduSyncdisk/Python/数据分析/hypothesis test/runs test data.txt")
data
runstest_1samp(data,cutoff='median')
#2samp
x = [16.75, 19.25, 22, 20.5, 22.5, 15.5, 17.25, 20.75]
y = [24.75, 21.5, 19.75, 17.5, 22.75, 23.5, 13, 19]
runstest_2samp(x,y)
输出:
一组样本 《概率论与数理统计》362页例7.6.1
(0.689202437604511, 0.4906958830600726)
两组样本
(0.25877458475338283, 0.7958091685190174)
2.秩和检验
#《概率论与数理统计》367页例7.6.6
from scipy import stats
import numpy as np
data=np.loadtxt("C:/Users/Administrator/Desktop/BaiduSyncdisk/Python/数据分析/hypothesis test/wilcoxon data.txt"
,usecols=(0,1),delimiter=",")
data
a=data[:,0]
b=data[:,1]
a,b
stats.wilcoxon(a,b)
输出:
《概率论与数理统计》367页例7.6.6
WilcoxonResult(statistic=4.0, pvalue=0.0068359375)