如何解决使用 scipy.stats 库计算 95% 置信区间的问题
我需要使用 python 计算矩阵 2x2 的 p 值、ods 比率和 95% 置信区间。我找到了 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% 置信区间时遇到问题。我found 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,**kwds)
AttributeError: 'list' object has no attribute 'ppf'
我怎样才能得到想要的结果?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。