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