python中p-value的实现方式

yipeiwu_com5年前Python基础

案例:

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的实现方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python Threading 线程/互斥锁/死锁/GIL锁

导入线程包 import threading 准备函数线程,传参数 t1 = threading.Thread(target=func,args=(args,)) 类继承线程,创建线程对...

python中的tcp示例详解

python中的tcp示例详解

TCP简介 TCP介绍 TCP协议,传输控制协议(英语:Transmission Control Protocol,缩写为 TCP)是一种面向连接的、可靠的、基于字节流的传输层通信协...

解决python3 urllib 链接中有中文的问题

环境python3,开发平台pycharm,使用urllib时,当url中存在中文时会出现以下错误: UnicodeEncodeError: 'ascii' codec can't...

深入了解Python数据类型之列表

一.基本数据类型 整数:int 字符串:str(注:\t等于一个tab键) 布尔值: bool 列表:list (元素的集合) 列表用[] 元祖:tuple 元祖用() 字典:dict...

python-序列解包(对可迭代元素的快速取值方法)

一般情况下 x,y,z = 1,2,3 print("x:",x) print("y:",y) print("z:",z) #运行结果 x: 1 y: 2 z: 3 对元祖序...