首页 > 解决方案 > 如果使用不同的包,为什么我会得到不同的 P 值

问题描述

我正在尝试比较两组的分类数据。

       Yes  No
GrpA: [152, 220]
GrpB: [187, 350]

但是,当使用不同的方法时,我会得到不同的 P 值结果:

count = [152, 220]
nobs = [187, 350]

import statsmodels
import scipy.stats

# USING STATSMODELS PACKAGE: 
res = statsmodels.stats.proportion.proportions_chisquare(count, nobs)
print("P value =", res[1])
res = statsmodels.stats.proportion.proportions_ztest(count, nobs)
print("P value =", res[1])

# USING SCIPY.STATS PACKAGE:
res = scipy.stats.chi2_contingency([count, nobs], correction=True)
print("P value =", res[1])
res = scipy.stats.chi2_contingency([count, nobs], correction=False)
print("P value =", res[1])

输出是:

P value using proportions_chisquare = 1.037221289479458e-05
P value using proportions_ztest= 1.0372212894794536e-05

P value using chi2_contingency with correction= 0.0749218380702875
P value using chi2_contingency without correction= 0.06421435896354544

前 2 个相同(并且非常重要),但它们与后 2 个不同(不重要)。

为什么结果不一样?进行此分析的正确方法是什么?

标签: scipystatisticsstatsmodelshypothesis-test

解决方案


推荐阅读