我如何针对 Benford 分布累积分布函数进行 Kolmogorov-Smirnov 检验以找到 p 值?

问题描述

我有一个数组,一个随机变量观测值的一维数组。我想使用 Kolmogorov-Smirnov 检验检查这些观测值是否遵循 Benford 分布。

我应用了 benford 包,使用带有 KS=True 的 first_digits 函数,但它不返回 p_value。因此我尝试使用 scipy 包。但是我没有找到与 benford 包相比的正确统计值。

代码是:

import benford as bf
import numpy as np
import scipy.stats as scs

# A 1-D array of observations of random variables
my_data = np.array([1,2,3,4,5,6,7,8,9])

# Confidence value,alfa=0.05
confidenceValue = 95

# Compare my_data with Benford distribution (it only regards the first digit to Benford,so digs=1) using Kolmogorov-Smirnof test
fd = bf.first_digits(my_data,digs=1,confidence=confidenceValue,KS=True,show_plot=False)

# Here are the counted values (fd.Counts),the founded values ()fd.Found,and the Benford distribution (fd.Expected):

fd

scs.ks_2samp(fd.Found,fd.Expected.cumsum(),mode='auto',alternative = 'two-sidded')

scs.kstest(fd.Counts,cdf=fd.Expected.cumsum(),N=len(my_data),alternative='two-sided',mode='auto')

如您所见,三个函数的值是不同的。只有第一个是正确的统计数据。

那么,我如何使用 scipy 对本福德分布(累积分布函数)的计数(或建立值)进行 Kolmogorov-Smirnov 检验?因为我需要 P 值。

注意:我知道它使用 R:

ks.benftest(my_data,pvalsims = 10)

有什么建议吗?

提前致谢, 罗莎:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...