我正在使用以下代码:
from statsmodels.stats.contingency_tables import cochrans_q
res = cochrans_q([[1,4,5],[9,6,8]])
print(res)
输出为:
df 2
pvalue 0.36787944117144245
statistic 2.0
但是[[10,4,5],[9,6,8]]
、[[55,88,77],[99,46,88]]
等的输出保持不变
statsmodels文档页面为here,科克伦Q测试的维基百科页面为here
问题在哪里?如何解决?谢谢你的帮助
以下是每个结果的定义:
如您所见,定义与每个元素的值无关,重要的是数量
您的程序为您的用户返回相同的内容
[[1,4,5],[9,6,8]]
、[[10,4,5],[9,6,8]]
、[[55,88,77],[99,46,88]]
等因为每个列表中有3个元素
Cochran的Q检验是一种非参数方法,用于在三个或三个以上频率或比例的匹配集合中发现差异。这意味着,当执行Cochran的Q测试时,每个元素的值并不重要
cochrans_q采用二进制数据,不进行计数
在statsmodels中,文档通常不是很明确,但是可以从单元测试中看到预期的行为
下面的单元测试演示如何将频率数据转换为statsmodels所需的格式
资料来源:https://github.com/statsmodels/statsmodels/blob/master/statsmodels/stats/tests/test_nonparametric.py#L190
相关问题 更多 >
编程相关推荐