本文整理汇总了Python中scipy.stats.ttest_ind方法的典型用法代码示例。如果您正苦于以下问题:Python stats.ttest_ind方法的具体用法?Python stats.ttest_ind怎么用?Python stats.ttest_ind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats
的用法示例。
在下文中一共展示了stats.ttest_ind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getDiffGeneTTest
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def getDiffGeneTTest(self):
cut=5e-2
AE=[item.E for item in self.fromNode.cells]
BE=[item.E for item in self.toNode.cells]
G=range(len(AE[0]))
#pdb.set_trace()
TT=[]
for i in G:
X=[item[i] for item in AE]
Y=[item[i] for item in BE]
pxy=ttest_ind(X,Y)[-1]
TT.append([pxy,i])
TT.sort()
TT=[item for item in TT if item[0]<cut]
DG=[[self.GL[item[1]],item[0]] for item in TT if self.GL[item[1]]]
return DG
#-------------------------------------------------------------------
示例2: test_knn
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def test_knn(datasets_dimred, genes, labels, idx, distr, xlabels):
knns = [ 5, 10, 50, 100 ]
len_distr = len(distr)
for knn in knns:
integrated = assemble(datasets_dimred[:], knn=knn, sigma=150)
X = np.concatenate(integrated)
distr.append(sil(X[idx, :], labels[idx]))
for d in distr[:len_distr]:
print(ttest_ind(np.ravel(X[idx, :]), np.ravel(d)))
xlabels.append(str(knn))
print('')
plt.figure()
plt.boxplot(distr, showmeans=True, whis='range')
plt.xticks(range(1, len(xlabels) + 1), xlabels)
plt.ylabel('Silhouette Coefficient')
plt.ylim((-1, 1))
plt.savefig('param_sensitivity_{}.svg'.format('knn'))
示例3: test_sigma
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def test_sigma(datasets_dimred, genes, labels, idx, distr, xlabels):
sigmas = [ 10, 50, 100, 200 ]
len_distr = len(distr)
for sigma in sigmas:
integrated = assemble(datasets_dimred[:], sigma=sigma)
X = np.concatenate(integrated)
distr.append(sil(X[idx, :], labels[idx]))
for d in distr[:len_distr]:
print(ttest_ind(np.ravel(X[idx, :]), np.ravel(d)))
xlabels.append(str(sigma))
print('')
plt.figure()
plt.boxplot(distr, showmeans=True, whis='range')
plt.xticks(range(1, len(xlabels) + 1), xlabels)
plt.ylabel('Silhouette Coefficient')
plt.ylim((-1, 1))
plt.savefig('param_sensitivity_{}.svg'.format('sigma'))
示例4: test_alpha
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def test_alpha(datasets_dimred, genes, labels, idx, distr, xlabels):
alphas = [ 0, 0.05, 0.20, 0.50 ]
len_distr = len(distr)
for alpha in alphas:
integrated = assemble(datasets_dimred[:], alpha=alpha, sigma=150)
X = np.concatenate(integrated)
distr.append(sil(X[idx, :], labels[idx]))
for d in distr[:len_distr]:
print(ttest_ind(np.ravel(X[idx, :]), np.ravel(d)))
xlabels.append(str(alpha))
print('')
plt.figure()
plt.boxplot(distr, showmeans=True, whis='range')
plt.xticks(range(1, len(xlabels) + 1), xlabels)
plt.ylabel('Silhouette Coefficient')
plt.ylim((-1, 1))
plt.savefig('param_sensitivity_{}.svg'.format('alpha'))
示例5: test_approx
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def test_approx(datasets_dimred, genes, labels, idx, distr, xlabels):
integrated = assemble(datasets_dimred[:], approx=False, sigma=150)
X = np.concatenate(integrated)
distr.append(sil(X[idx, :], labels[idx]))
len_distr = len(distr)
for d in distr[:len_distr]:
print(ttest_ind(np.ravel(X[idx, :]), np.ravel(d)))
xlabels.append('Exact NN')
print('')
plt.figure()
plt.boxplot(distr, showmeans=True, whis='range')
plt.xticks(range(1, len(xlabels) + 1), xlabels)
plt.ylabel('Silhouette Coefficient')
plt.ylim((-1, 1))
plt.savefig('param_sensitivity_{}.svg'.format('approx'))
示例6: test_perplexity
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def test_perplexity(datasets_dimred, genes, labels, idx,
distr, xlabels):
X = np.concatenate(datasets_dimred)
perplexities = [ 10, 100, 500, 2000 ]
len_distr = len(distr)
for perplexity in perplexities:
embedding = fit_tsne(X, perplexity=perplexity)
distr.append(sil(embedding[idx, :], labels[idx]))
for d in distr[:len_distr]:
print(ttest_ind(np.ravel(X[idx, :]), np.ravel(d)))
xlabels.append(str(perplexity))
print('')
plt.figure()
plt.boxplot(distr, showmeans=True, whis='range')
plt.xticks(range(1, len(xlabels) + 1), xlabels)
plt.ylabel('Silhouette Coefficient')
plt.ylim((-1, 1))
plt.savefig('param_sensitivity_{}.svg'.format('perplexity'))
示例7: stat_tests
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def stat_tests(ref_cors, exp_cors, alternative):
_, mwp = mannwhitneyu(ref_cors, exp_cors, alternative=alternative)
tt, tp = ttest_ind(ref_cors, exp_cors)
if alternative == 'less':
if tt > 0:
tp = 1 - (1-tp)/2
else:
tp /= 2
elif alternative == 'greater':
if tt <= 0:
tp /= 2
else:
tp = 1 - (1-tp)/2
return mwp, tp
################################################################################
# __main__
################################################################################
示例8: tTestVoxelization
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def tTestVoxelization(group1, group2, signed = False, removeNaN = True, pcutoff = None):
"""t-Test on differences between the individual voxels in group1 and group2, group is a array of voxelizations"""
g1 = self.readDataGroup(group1);
g2 = self.readDataGroup(group2);
tvals, pvals = stats.ttest_ind(g1, g2, axis = 0, equal_var = True);
#remove nans
if removeNaN:
pi = numpy.isnan(pvals);
pvals[pi] = 1.0;
tvals[pi] = 0;
pvals = self.cutoffPValues(pvals, pcutoff = pcutoff);
#return
if signed:
return pvals, numpy.sign(tvals);
else:
return pvals;
示例9: tTestPointsInRegions
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def tTestPointsInRegions(pointCounts1, pointCounts2, labeledImage = lbl.DefaultLabeledImageFile, signed = False, removeNaN = True, pcutoff = None, equal_var = False):
"""t-Test on differences in counts of points in labeled regions"""
#ids, p1 = countPointsGroupInRegions(pointGroup1, labeledImage = labeledImage, withIds = True);
#p2 = countPointsGroupInRegions(pointGroup2, labeledImage = labeledImage, withIds = False);
tvals, pvals = stats.ttest_ind(pointCounts1, pointCounts2, axis = 1, equal_var = equal_var);
#remove nans
if removeNaN:
pi = numpy.isnan(pvals);
pvals[pi] = 1.0;
tvals[pi] = 0;
pvals = self.cutoffPValues(pvals, pcutoff = pcutoff);
#pvals.shape = (1,) + pvals.shape;
#ids.shape = (1,) + ids.shape;
#pvals = numpy.concatenate((ids.T, pvals.T), axis = 1);
if signed:
return pvals, numpy.sign(tvals);
else:
return pvals;
示例10: test_weightstats_1
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def test_weightstats_1(self):
x1, x2 = self.x1, self.x2
w1, w2 = self.w1, self.w2
w1_ = 2. * np.ones(len(x1))
w2_ = 2. * np.ones(len(x2))
d1 = DescrStatsW(x1)
# print ttest_ind(x1, x2)
# print ttest_ind(x1, x2, usevar='unequal')
# #print ttest_ind(x1, x2, usevar='unequal')
# print stats.ttest_ind(x1, x2)
# print ttest_ind(x1, x2, usevar='unequal', alternative='larger')
# print ttest_ind(x1, x2, usevar='unequal', alternative='smaller')
# print ttest_ind(x1, x2, usevar='unequal', weights=(w1_, w2_))
# print stats.ttest_ind(np.r_[x1, x1], np.r_[x2,x2])
assert_almost_equal(ttest_ind(x1, x2, weights=(w1_, w2_))[:2],
stats.ttest_ind(np.r_[x1, x1], np.r_[x2, x2]))
示例11: compare_different_objectivefunctions
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def compare_different_objectivefunctions(like1,like2):
"""
Performs the Welch’s t-test (aka unequal variances t-test)
:like1: objectivefunction values
:type: list
:like2: Other objectivefunction values
:type: list
:return: p Value
:rtype: list
"""
from scipy import stats
out = stats.ttest_ind(like1, like2, equal_var=False)
print(out)
if out[1]>0.05:
print('like1 is NOT signifikant different to like2: p>0.05')
else:
print('like1 is signifikant different to like2: p<0.05' )
return out
示例12: t_test
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def t_test(covariates, groups):
"""
Two sample t 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 = ttest_ind(var[groups == 1], var[groups == 0])
pvalues[j] = res.pvalue
return pvalues
示例13: test_ttest_ind_nan_2nd_arg
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def test_ttest_ind_nan_2nd_arg():
# regression test for gh-6134: nans in the second arg were not handled
x = [np.nan, 2.0, 3.0, 4.0]
y = [1.0, 2.0, 1.0, 2.0]
r1 = stats.ttest_ind(x, y, nan_policy='omit')
r2 = stats.ttest_ind(y, x, nan_policy='omit')
assert_allclose(r2.statistic, -r1.statistic, atol=1e-15)
assert_allclose(r2.pvalue, r1.pvalue, atol=1e-15)
# NB: arguments are not paired when NaNs are dropped
r3 = stats.ttest_ind(y, x[1:])
assert_allclose(r2, r3, atol=1e-15)
# .. and this is consistent with R. R code:
# x = c(NA, 2.0, 3.0, 4.0)
# y = c(1.0, 2.0, 1.0, 2.0)
# t.test(x, y, var.equal=TRUE)
assert_allclose(r2, (-2.5354627641855498, 0.052181400457057901), atol=1e-15)
示例14: ttest
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def ttest(df, fields, indep, dep):
# Ensure single field
dep_field_name = dep[0]
indep_field_name = indep[0]
unique_indep_values = get_unique(df[indep_field_name])
subsets = {}
for v in unique_indep_values:
subsets[v] = np.array(df[df[indep_field_name] == v][dep_field_name])
result = {}
for (x, y) in combinations(unique_indep_values, 2):
(statistic, pvalue) = ttest_ind(subsets[x], subsets[y])
result[str([x, y])] = {
'statistic': statistic,
'pvalue': pvalue
}
return result
##################
#Functions to determine which tests could be run
##################
示例15: tellDifference
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import ttest_ind [as 别名]
def tellDifference(nodeCells,nodePCells,geneIndex,fcut=0.6):
if len(nodePCells)==0:
return [0,1,0]
X=[item.E[geneIndex] for item in nodeCells]
Y=[item.E[geneIndex] for item in nodePCells]
fc=sum(X)/len(X)-sum(Y)/len(Y)
pv=ttest_ind(X,Y)[1]
pcut=0.05
if pv<pcut and fc>fcut:
return [1,pv,fc]
if pv<pcut and fc<-1*fcut:
return [-1,pv,fc]
return [0,pv,fc]
#-----------------------------------------------------------------------------
# filter X