使用 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 (将#修改为@)