What am I doing wrong here? Below is the code and here is the error I'm getting:
AttributeError: 'module' object has no attribute 'chi2_contingency'
The fisher test works just fine and prints the oddsration and p value but the chi2 test is not. Done some looking around here and changed the way I was importing packages/modules but no luck. Any help appreciated. Probably something simple I'm missing. Thanks in advance.
import sys
import numpy as np
import scipy
from scipy import stats
oddsratio, pvalue = scipy.stats.fisher_exact([[56, 891], [48, 12873]])
print oddsratio
print pvalue
obs = np.array([[56, 891], [48, 12873]])
print obs
g, p, dof, expctd = scipy.stats.chi2_contingency(obs, correction=True)
print p
While this looks like a quirk, it's a side-effect of the layout of scipy
being a package containing a module stats
. Try:
import scipy.stats
g, p, dof, e = scipy.stats.chi2_contingency([[56, 891], [48, 12873]], correction=True)
print p # 1.4896896046343034e-79
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.