gpt4 book ai didi

python - python中的学生t置信区间

转载 作者:太空狗 更新时间:2023-10-29 20:14:28 25 4
gpt4 key购买 nike

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

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

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

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

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

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

最佳答案

我猜你可以使用 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)

关于python - python中的学生t置信区间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17203403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com