本文整理匯總了Python中scipy.stats.ranksums方法的典型用法代碼示例。如果您正苦於以下問題:Python stats.ranksums方法的具體用法?Python stats.ranksums怎麽用?Python stats.ranksums使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy.stats
的用法示例。
在下文中一共展示了stats.ranksums方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rank_test
# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import ranksums [as 別名]
def rank_test(covariates, groups):
"""
Wilcoxon rank sum test for the distribution of treatment and control covariates.
Parameters
----------
covariates : DataFrame
Dataframe with one covariate per column.
If matches are with replacement, then duplicates should be
included as additional rows.
groups : array-like
treatment assignments, must be 2 groups
Returns
-------
A list of p-values, one for each column in covariates
"""
colnames = list(covariates.columns)
J = len(colnames)
pvalues = np.zeros(J)
for j in range(J):
var = covariates[colnames[j]]
res = ranksums(var[groups == 1], var[groups == 0])
pvalues[j] = res.pvalue
return pvalues
示例2: compare_by_position
# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import ranksums [as 別名]
def compare_by_position(bed1,bed2,xmfa):
pos_dict = {}
for i,bed in enumerate([bed1,bed2]):
pos_dict[i] = {}
with open(bed,'r') as fi:
for line in fi:
#2 1892198 1892199 TCMMTMTTMMM 0.5 - 16
csome,start,end,motif,perc_meth,strand,num_reads,probabilities = tuple(line.split('\t'))
pos_dict[i][(csome,start,end,strand)] = ((perc_meth,num_reads),np.asarray([float(p) for p in probabilities.strip().split(',')]))
for pos in pos_dict[0]:
if pos in pos_dict[1]:
try:
u,pval = mannwhitneyu(pos_dict[0][pos][1],pos_dict[0][pos][1],alternative='two-sided')
except ValueError:
u,pval = 'none','identical'
u2,pval2 = ranksums(pos_dict[0][pos][1],pos_dict[0][pos][1])
try:
t,pval3 = ttest_ind(pos_dict[0][pos][1],pos_dict[0][pos][1])
except:
t,pval3 = 'none','missing df'
d,pval4 = ks_2samp(pos_dict[0][pos][1],pos_dict[0][pos][1])
if pval4 < 0.9:
print pos, pos_dict[0][pos][0], pos_dict[1][pos][0], pval, pval2, pval3, pval4
示例3: test_ranksums_result_attributes
# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import ranksums [as 別名]
def test_ranksums_result_attributes(self):
res = stats.ranksums(np.arange(5), np.arange(25))
attributes = ('statistic', 'pvalue')
check_named_results(res, attributes)
示例4: getParent
# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import ranksums [as 別名]
def getParent(self,A,TP):
#A is the cluster,we are trying to find the parent for cluster A.
#TP is the parent level
#PL is the cluste list in parent level
PL=[item for item in self.Nodes if (item.T==TP and item.ST<=A.ST)]
PL=sorted(PL,key=lambda item:sum([getDistance(item,ck) for ck in A.cells])/len(A.cells))
#pdb.set_trace()
#---------------------------------------------------------------
# if time sync is disabled, output the closest node in parent level
if self.dsync=='True' or self.dsync=='1':
if len(PL)>0:
return PL[0]
return None
#--------------------------------------------------------------
pvcut=0.1
if len(PL)>1:
X=[getDistance(PL[0],item) for item in A.cells]
Y=[getDistance(PL[-1],item) for item in A.cells]
# Length adjustment if Vector is too short
SizeFactor=50 # Used for length adjustment
X=X*int(SizeFactor/len(X)) if len(X)<SizeFactor else X
Y=Y*int(SizeFactor/len(Y)) if len(Y)<SizeFactor else Y
pv=ranksums(X,Y)[-1]
if pv<pvcut:
return PL[0]
else:
return self.getParent(A,TP-1)
elif len(PL)==1:
if PL[0]==self.Nodes[0]:
return PL[0]
else:
PLL=[item for item in self.Nodes if (item.T==TP-1 and item.ST<=A.ST)]
if len(PLL)==1:
return PL[0]
else:
return self.getParent(A,TP-1)
else:
if A!=self.Nodes[0]:
return self.getParent(A,TP-1)
示例5: ranksum_test
# 需要導入模塊: from scipy import stats [as 別名]
# 或者: from scipy.stats import ranksums [as 別名]
def ranksum_test(self, metric_name=None):
"""
Non-parametric test for testing consistent differences between pairs
of obeservations.
The test counts the number of observations that are greater, smaller
and equal to the mean
`<http://en.wikipedia.org/wiki/Wilcoxon_rank-sum_test>`_.
"""
self._check_is_evaluated()
metric_name = self._validate_metric_name(metric_name)
metrics_per_estimator_dataset = \
self._get_metrics_per_estimator_dataset(
metric_name)
ranksum_df = pd.DataFrame()
perms = itertools.product(metrics_per_estimator_dataset.keys(),
repeat=2)
values = np.array([])
for perm in perms:
x = metrics_per_estimator_dataset[perm[0]]
y = metrics_per_estimator_dataset[perm[1]]
t_stat, p_val = ranksums(x, y)
ranksum = {
"estimator_1": perm[0],
"estimator_2": perm[1],
"t_stat": t_stat,
"p_val": p_val
}
ranksum_df = ranksum_df.append(ranksum, ignore_index=True)
values = np.append(values, t_stat)
values = np.append(values, p_val)
index = ranksum_df["estimator_1"].unique()
values_names = ["t_stat", "p_val"]
col_idx = pd.MultiIndex.from_product([index, values_names])
values_reshaped = values.reshape(len(index),
len(values_names) * len(index))
values_df_multiindex = pd.DataFrame(values_reshaped, index=index,
columns=col_idx)
return ranksum_df, values_df_multiindex