【发布时间】:2021-08-04 15:12:20
【问题描述】:
我已经完成了如下卡方应变检验的练习,但我在如何解释结果方面遇到了问题。 以下测试的结果显示 p-val = 0。 那么这是否意味着两个变量不独立? 由于这是一个小数据,我认为变量是独立的。 p-val 为 0 似乎很奇怪。 我是不是做错了什么??
import pandas as pd
df = pd.DataFrame({
"~60m2" : [54, 577, 143, 782],
"60~85m2" : [2, 735, 1437, 1],
"85m2~" : [0, 142, 44, 0],
})
df.index = ["A", "B", "C", "D"]
df.columns.names = ["size"]
df.index.names = ["city"]
from scipy import stats
stats.chi2_contingency(df)
输出
(2064.576731417199,
0.0,
6,
array([[ 22.24559612, 31.09522594, 2.65917794],
[577.59101353, 807.36533061, 69.04365586],
[645.12228746, 901.76155221, 77.11616033],
[311.04110288, 434.77789124, 37.18100587]]))
【问题讨论】:
-
只是来自docs 的注释:
An often quoted guideline for the validity of this calculation is that the test should be used only if the observed and expected frequencies in each cell are at least 5。可能不是答案,但可能是问题所在。
标签: python scipy.stats