python中p-value的实现方式

案例:

tt = (sm-m)/np.sqrt(sv/float(n)) # t-statistic for mean
pval = stats.t.sf(np.abs(tt), n-1)*2 # two-sided pvalue = Prob(abs(t)>tt)
print 't-statistic = %6.3f pvalue = %6.4f' % (tt, pval)
t-statistic = 0.391 pvalue = 0.6955

链接:

https://stackoverflow.com/questions/17559897/python-p-value-from-t-statistic

http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html

可执行代码

# coding: utf-8
from __future__ import division
import numpy as np
from scipy import stats
 
means = [0.0539, 4,8,3,6,9,1]
stds = [5,4,8,3,6,7,9]
mu = [0, 4.1, 7, 2, 5, 8, 0]
n = 20
output = []
for sm, std, m in zip(means, stds, mu):
  # print("value:", sm, std)
  tt = (sm-m)/(std/np.sqrt(float(n)))   # t-statistic for mean
  pval = stats.t.sf(np.abs(tt), n-1)*2 # two-sided pvalue = Prob(abs(t)>tt)
  # print('t-statistic = %6.3f pvalue = %6.4f' % (tt, pval))
  output.append(format(pval))
print("\t".join(output))

以上这篇python中p-value的实现方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持呐喊教程。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。