def r2p(r,n):
"""
Given a value of the Pearson r coefficient, this method gives the
corresponding p-value of the null hypothesis (i.e. no correlation).
Code copied from scipy.stats.pearsonr source.
Usage:
>>> p=r2p(r,n)
where 'r' is the Pearson coefficient and n is the number of data
points.
:returns: p-value of the null hypothesis.
"""
df = n-2
if abs(r) == 1.0:
prob = 0.0
else:
t_squared = r*r * (df / ((1.0 - r) * (1.0 + r)))
prob = scipy.stats.betai(0.5*df, 0.5, df / (df + t_squared))
return prob
评论列表
文章目录