gpt4 book ai didi

python - 为什么 scipy 中的 χ² 检验会返回较小的检验统计量?

转载 作者:太空宇宙 更新时间:2023-11-04 00:56:12 24 4
gpt4 key购买 nike

我正在计算一个小型并发表的 chi2 检验统计量:

obs = np.array([
[652, 576],
[1348, 924]
])

当我手工计算时,如图 Wikipedia 所示(Σ (Oᵢ - Eᵢ)²/Eᵢ) 我得到的结果是 ~12.660,但是 scipy.stats.chi2_contingency 函数返回这些结果和另一个测试统计数据:

>>> scipy.stats.chi2_contingency(obs)
(12.40676502094132, 0.00042778128638335943, 1, array([[ 701.71428571, 526.28571429],
[ 1298.28571429, 973.71428571]]))

我将结果的预期频率与我的进行了比较,结果发现它们是相同的。此外,通过将我的数据输入在线计算器,可以得到与我自己相同的结果(例如 http://www.socscistatistics.com/tests/chisquare2/default2.aspx )。

这个函数有什么魔力可以减少测试统计量?

最佳答案

默认情况下,correctionTrue,这意味着 Yates 的连续性校正适用于自由度为 1 的情况(如此处所示)。如果您设置 correction=False 这不会发生,您将得到 12.660... 作为测试统计数据:

>>> scipy.stats.chi2_contingency(obs, correction=False)
(12.660142450795965,
0.00037353375362753034,
1,
array([[ 701.71428571, 526.28571429],
[ 1298.28571429, 973.71428571]])

documentationcorrection 参数提供了以下更多信息并总结了 Yates 的更正:

If True, and the degrees of freedom is 1, apply Yates’ correction for continuity. The effect of the correction is to adjust each observed value by 0.5 towards the corresponding expected value.

关于python - 为什么 scipy 中的 χ² 检验会返回较小的检验统计量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34975115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com