考虑下面的示例dataframe:
d = {'Gender': [1,1,0,1,0], 'Employed': [1,0,0,1,1]}
运行以下五个表将为我提供一个应急表
import statsmodels.api as sm
import pandas as pd
d=pd.DataFrame(d)
table = sm.stats.Table.from_data(d)
这给了我表格中的应急表。
A 2x2 contingency table with counts:
[[1. 1.]
[1. 2.]]
我希望能够将“表”直接放入fisher精确函数中,但这会产生一个错误,因为fisher精确函数需要这样的表格:
stats.fisher_Exact[[1,1],[1,2]]
如何以正确的格式自动创建应急表,这样就不必以正确的方式重写它了?
发布于 2021-12-03 10:18:22
这很好,但是您有几个排字:
d = {'Gender': [1,1,0,1,0], 'Employed': [1,0,0,1,1]}
import statsmodels.api as sm
import pandas as pd
d=pd.DataFrame(d)
table = sm.stats.Table.from_data(d)
from scipy import stats
oddsratio, pvalue = stats.fisher_exact(table.table)
print(oddsratio, pvalue)
输出:2.0 1.0
https://stackoverflow.com/questions/70212630
复制相似问题