python中的学生t置信区间 [英] student t confidence interval in python

查看:151
本文介绍了python中的学生t置信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am interested in using python to compute a confidence interval from a student t.

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

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

我不太确定如何自己构建此函数,但是在我着手之前,python中的该函数是否在某个地方?像numpy? (我没有使用过numpy,我的顾问建议尽可能不要使用numpy.)

I am not quite sure how to build this function myself, but before I embark on that, is this function in python somewhere? Like numpy? (I haven't used numpy and my advisor advised not using numpy if possible).

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

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?

edit:我将需要使用python代码(如果可能)构建Student TCI.安装scipy变成了死胡同.我遇到了其他所有人都遇到的相同问题,并且如果花费很长时间来设置,我将无法要求Scipy来分发我的代码.

edit: I'm going to need to build the Student TCI using python code (if possible). Installing scipy has turned into a dead end. 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版本中算法的源代码吗?我想将其重构为python定义.

Anyone know how to look at the source code for the algorithm in the scipy version? I'm thinking I'll refactor it into a python definition.

推荐答案

我想您可以使用

I guess you could use scipy.stats.t and it's interval method:

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中:

Sure, you can make your own function if you like. Let's make it look like in 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中的学生t置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆