简体   繁体   English

学生在python中的置信区间

[英]student t confidence interval in python

I am interested in using python to compute a confidence interval from a student t. 我有兴趣使用python来计算学生t的置信区间。

I am using the StudentTCI() function in Mathematica and now need to code the same function in python http://reference.wolfram.com/mathematica/HypothesisTesting/ref/StudentTCI.html 我在Mathematica中使用StudentTCI()函数,现在需要在python中编写相同的函数http://reference.wolfram.com/mathematica/HypothesisTesting/ref/StudentTCI.html

I am not quite sure how to build this function myself, but before I embark on that, is this function in python somewhere? 我不太确定如何自己构建这个函数,但在我开始之前,这个函数是在python的某个地方吗? Like numpy? 喜欢numpy? (I haven't used numpy and my advisor advised not using numpy if possible). (我没有使用numpy,我的顾问建议如果可能的话不使用numpy)。

What would be the easiest way to solve this problem? 解决这个问题最简单的方法是什么? Can I copy the source code from the StudentTCI() in numpy (if it exists) into my code as a function definition? 我可以将源代码从numpy中的StudentTCI()(如果存在)复制到我的代码中作为函数定义吗?

edit: I'm going to need to build the Student TCI using python code (if possible). 编辑:我将需要使用python代码构建Student TCI(如果可能)。 Installing scipy has turned into a dead end. 安装scipy已经变成了死胡同。 I am having the same problem everyone else is having, and there is no way I can require Scipy for the code I distribute if it takes this long to set up. 我遇到了其他人都遇到的同样问题,如果需要很长时间才能设置,我就无法为我分发的代码提供Scipy。

Anyone know how to look at the source code for the algorithm in the scipy version? 任何人都知道如何在scipy版本中查看算法的源代码? I'm thinking I'll refactor it into a python definition. 我想我会把它重构为python定义。

I guess you could use scipy.stats.t and it's interval method: 我想你可以使用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)

Sure, you can make your own function if you like. 当然,如果你愿意,你可以自己动手。 Let's make it look like in Mathematica : 让它看起来像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)

Result: 结果:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM