python中student和student_python中的学生t置信区间

I am interested in using python to compute a confidence interval from a student 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

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).

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

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)

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)

Result:

(-3.4562777039298762, 5.4562777039298762)

(-5.338545334351676, 7.338545334351676)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值