我需要计算p值,ods比率和95%置信区间矩阵2x2 usin python.我发现scipy.stats
库
import scipy.stats as stats
v = [[8, 2], [1, 5]]
oddsratio, pvalue = stats.fisher_exact(v)
print(pvalue, oddsratio, sep="\n") # 0.03496503496503495 and 20.0 (15.47 on R)
字符串
但是我在计算95%置信区间时遇到了问题。我找到了scipy.stats.rv_continuous.interval
方法
v_continuous.interval(self, alpha, *args, **kwds)[source]
Confidence interval with equal areas around the median.
Parameters
alphaarray_like of float
Probability that an rv will be drawn from the returned range. Each value should be in the range [0, 1].
arg1, arg2, …array_like
The shape parameter(s) for the distribution (see docstring of the instance object for more information).
locarray_like, optional
location parameter, Default is 0.
scalearray_like, optional
scale parameter, Default is 1.
Returns
a, bndarray of float
end-points of range that contain 100 * alpha % of the rv’s possible values.
型
我试试下一个
a, b = stats.rv_continuous.interval(v, 0.95)
print(a, b, sep="\n") # ~ 1.00884938039662 and 1049.79144613175 (calculated in R)
型
但出现错误
a = self.ppf(q1, *args, **kwds)
AttributeError: 'list' object has no attribute 'ppf'
型
我如何才能得到想要的结果?
1条答案
按热度按时间thtygnil1#
这个问题没有指出置信区间是什么数量。假设你正在寻找比值比的置信区间,你可以使用
scipy.stats.contingency.odds_ratio
(SciPy 1.10.0中的新功能)。字符串