【问题标题】:student t confidence interval in pythonpython中的学生t置信区间
【发布时间】:2013-06-16 16:56:03
【问题描述】:

我有兴趣使用 python 计算学生 t 的置信区间。

我在 Mathematica 中使用 StudentTCI() 函数,现在需要在 python http://reference.wolfram.com/mathematica/HypothesisTesting/ref/StudentTCI.html 中编写相同的函数

我不太确定如何自己构建这个函数,但在我开始之前,这个函数在 python 中的某个地方吗?像麻木? (我没有使用过 numpy,我的顾问建议尽可能不要使用 numpy)。

解决这个问题最简单的方法是什么?我可以将 numpy 中 StudentTCI() 中的源代码(如果存在)复制到我的代码中作为函数定义吗?

编辑:我将需要使用 python 代码构建学生 TCI(如果可能的话)。安装 scipy 变成了死胡同。我遇到了其他人都遇到的同样问题,如果设置需要这么长时间,我就无法要求 Scipy 分发我分发的代码。

有人知道如何查看scipy版本中算法的源代码吗?我在想我会将它重构为 python 定义。

【问题讨论】:

    标签: python numpy distribution


    【解决方案1】:

    我猜你可以使用scipy.stats.t,它是interval 方法:

    In [1]: from scipy.stats import t
    In [2]: t.interval(0.95, 10, loc=1, scale=2)  # 95% confidence interval
    Out[2]: (-3.4562777039298762, 5.4562777039298762)
    In [3]: t.interval(0.99, 10, loc=1, scale=2)  # 99% confidence interval
    Out[3]: (-5.338545334351676, 7.338545334351676)
    

    当然,如果您愿意,您可以制作自己的函数。让我们让它看起来像Mathematica

    from scipy.stats import t
    
    
    def StudentTCI(loc, scale, df, alpha=0.95):
        return t.interval(alpha, df, loc, scale)
    
    print StudentTCI(1, 2, 10)
    print StudentTCI(1, 2, 10, 0.99)
    

    结果:

    (-3.4562777039298762, 5.4562777039298762)
    (-5.338545334351676, 7.338545334351676)
    

    【讨论】:

    • 谢谢。这就是我需要的。我正在尝试安装 scipy (win7 64x),它并不像应有的那么简单??我正在使用 32 位 python,所以我相信我也想要 32 位 scipy,但我不知道如何获得它。我现在正在安装一个名为 anaconda 的东西,我想它应该可以完成工作吗?没有任何方法可以安装 scipy 我接受它?
    • Anaconda 完成了,但没有安装 scipy。第 29 行,在 from scipy.stats import t ImportError: No module named scipy.stats
    • @SwimBikeRun,我建议你安装Enthought Canopy。它提供了一种简单直接的方式来安装和管理 python 包。 Scipy 包含在 Express 版本中,因此您无需为此付费。还有pythonxy scipy 自带的,但我从来没有真正使用过。
    • 为了未来的用户,我花了太多时间安装 virtual box + linux 和几个双启动 linux(ubuntu,mint),现在我回到了 windows 7 64 位,但运行一切都是32 位工具。现在一切都很好。
    • @SwimBikeRun, loc 是位置参数或平均值 μ。在这种情况下,尺度是方差 σ。如果你不想使用SciPy,你可以找到分发的源代码和它的方法hereSciPy 但是依赖于 NumPy,因此您的用户必须安装它。
    猜你喜欢
    • 2015-10-24
    • 2018-07-13
    • 2015-09-15
    • 1970-01-01
    • 2023-03-25
    • 2020-10-06
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多