def correlation(x,y,name="Pearson"):
# Linear or rank correlation
# Returns:
# r,rho, or tau (float) = the test statistic
# pvalue (float) = the p-value for the test
assert len(x)==len(y), "Arrays x & y must be equal length."
if name == "Pearson":
(r,pvalue) = scipy.stats.pearsonr(x,y)
return r,pvalue
elif name == "Spearman":
(rho,pvalue) = scipy.stats.spearmanr(x,y)
return rho,pvalue
elif name == "Kendall":
(tau,pvalue) = scipy.stats.kendalltau(x,y)
return tau,pvalue
else:
error = ("The {} correlation is not available."
"Please use 'Pearson', 'Spearman', or 'Kendall.'")
error.format(name)
raise ValueError(error)
评论列表
文章目录