【发布时间】:2021-06-12 21:00:31
【问题描述】:
我正在尝试计算将 CDF 指定为数组的 KS 测试,但是,我遇到了意外的结果。经过进一步评估,我发现根据我是否将 CDF 指定为可调用、字符串或数组的不同结果。我的代码如下:
import scipy.stats as st
random_variables = st.norm.rvs(loc=1, scale=1,size=1000000)
cdf_data = st.norm.cdf(random_variables, loc=1,scale=1)
params = st.norm.fit(data=random_variables)
display(params)
print('\n')
#test 1
out = kstest(rvs=random_variables,cdf='norm',args=params)
display(out, out[0], out[1])
print('\n')
#test 2
out = kstest(rvs=random_variables,cdf=st.norm.cdf,args=params)
display(out, out[0], out[1])
print('\n')
#test 3
out = kstest(rvs=random_variables,cdf=cdf_data)
display(out, out[0], out[1])
这段代码的结果是:
(1.0004825310590526, 0.9996641807017618)
KstestResult(statistic=0.0007348981302804924, pvalue=0.6523439724424506)
0.0007348981302804924
0.6523439724424506
KstestResult(statistic=0.0007348981302804924, pvalue=0.6523439724424506)
0.0007348981302804924
0.6523439724424506
KstestResult(statistic=0.500165, pvalue=0.0)
0.500165
0.0
鉴于将大样本数据与其生成样本的确切分布进行比较,我预计无法拒绝零假设。这是测试 1 和 2 中的情况,但在测试 3 中并非如此。我希望能够使用“cdf”参数的数组参数来复制此测试。关于我在测试 3 中做错了什么的任何帮助都会非常有帮助。我的 numpy 是 1.19.2 版本,而 scipy 是 1.5.2。谢谢!
【问题讨论】:
标签: python python-3.x scipy normal-distribution scipy.stats