本文整理汇总了Python中skbio.stats.distance.mantel函数的典型用法代码示例。如果您正苦于以下问题:Python mantel函数的具体用法?Python mantel怎么用?Python mantel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mantel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_comparing_same_matrices
def test_comparing_same_matrices(self):
for method in self.methods:
obs = mantel(self.minx, self.minx, method=method)[0]
self.assertAlmostEqual(obs, 1)
obs = mantel(self.miny, self.miny, method=method)[0]
self.assertAlmostEqual(obs, 1)
示例2: test_invalid_distance_matrix
def test_invalid_distance_matrix(self):
# Single asymmetric, non-hollow distance matrix.
with self.assertRaises(DissimilarityMatrixError):
mantel([[1, 2], [3, 4]], [[0, 0], [0, 0]])
# Two asymmetric distance matrices.
with self.assertRaises(DistanceMatrixError):
mantel([[0, 2], [3, 0]], [[0, 1], [0, 0]])
示例3: test_one_sided_greater
def test_one_sided_greater(self):
np.random.seed(0)
obs = mantel(self.minx, self.miny, alternative='greater')
self.assertAlmostEqual(obs[0], self.exp_x_vs_y)
self.assertAlmostEqual(obs[1], 0.324)
obs = mantel(self.minx, self.minx, alternative='greater')
self.assertAlmostEqual(obs[0], 1)
self.assertAlmostEqual(obs[1], 0.172)
示例4: test_no_variation_spearman
def test_no_variation_spearman(self):
exp = (np.nan, np.nan, 3)
for alt in self.alternatives:
obs = mantel(self.miny, self.no_variation, method="spearman", alternative=alt)
npt.assert_equal(obs, exp)
obs = mantel(self.no_variation, self.miny, method="spearman", alternative=alt)
npt.assert_equal(obs, exp)
obs = mantel(self.no_variation, self.no_variation, method="spearman", alternative=alt)
npt.assert_equal(obs, exp)
示例5: test_no_side_effects
def test_no_side_effects(self):
minx = np.asarray(self.minx, dtype='float')
miny = np.asarray(self.miny, dtype='float')
minx_copy = np.copy(minx)
miny_copy = np.copy(miny)
mantel(minx, miny)
# Make sure we haven't modified the input.
npt.assert_equal(minx, minx_copy)
npt.assert_equal(miny, miny_copy)
示例6: test_zero_permutations
def test_zero_permutations(self):
for alt in self.alternatives:
for method, exp in (("pearson", self.exp_x_vs_y), ("spearman", 0.5)):
obs = mantel(self.minx, self.miny, permutations=0, method=method, alternative=alt)
self.assertAlmostEqual(obs[0], exp)
npt.assert_equal(obs[1], np.nan)
self.assertEqual(obs[2], 3)
# swapping order of matrices should give same result
obs = mantel(self.miny, self.minx, permutations=0, method=method, alternative=alt)
self.assertAlmostEqual(obs[0], exp)
npt.assert_equal(obs[1], np.nan)
self.assertEqual(obs[2], 3)
示例7: test_vegan_example
def test_vegan_example(self):
np.random.seed(0)
# pearson
obs = mantel(self.veg_dm_vegan, self.env_dm_vegan, alternative="greater")
self.assertAlmostEqual(obs[0], 0.3047454)
self.assertAlmostEqual(obs[1], 0.002)
self.assertEqual(obs[2], 24)
# spearman
obs = mantel(self.veg_dm_vegan, self.env_dm_vegan, alternative="greater", method="spearman")
self.assertAlmostEqual(obs[0], 0.283791)
self.assertAlmostEqual(obs[1], 0.003)
self.assertEqual(obs[2], 24)
示例8: test_no_variation_pearson
def test_no_variation_pearson(self):
# Output doesn't match vegan::mantel with method='pearson'. Consider
# revising output and this test depending on outcome of
# https://github.com/scipy/scipy/issues/3728
for alt in self.alternatives:
# test one or both inputs having no variation in their
# distances
obs = mantel(self.miny, self.no_variation, method="pearson", alternative=alt)
npt.assert_equal(obs, (0.0, 1.0, 3))
obs = mantel(self.no_variation, self.miny, method="pearson", alternative=alt)
npt.assert_equal(obs, (0.0, 1.0, 3))
obs = mantel(self.no_variation, self.no_variation, method="pearson", alternative=alt)
npt.assert_equal(obs, (1.0, 1.0, 3))
示例9: test_distance_matrix_instances_with_reordering_and_nonmatching
def test_distance_matrix_instances_with_reordering_and_nonmatching(self):
x = self.minx_dm_extra.filter(['1', '0', 'foo', '2'])
y = self.miny_dm.filter(['0', '2', '1'])
# strict=True should disallow IDs that aren't found in both matrices
with self.assertRaises(ValueError):
mantel(x, y, alternative='less', strict=True)
np.random.seed(0)
# strict=False should ignore IDs that aren't found in both matrices
obs = mantel(x, y, alternative='less', strict=False)
self.assertAlmostEqual(obs[0], self.exp_x_vs_y)
self.assertAlmostEqual(obs[1], 0.843)
self.assertEqual(obs[2], 3)
示例10: compare_clusters
def compare_clusters(args):
ref_df = pd.read_table(args['ref'], sep='\t', skipinitialspace=True, index_col=0).as_matrix()
check_symmetry(ref_df)
linkage_ref = linkage(ref_df, 'average')
c_ref, coph_dists_ref = cophenet(linkage_ref, pdist(ref_df))
outfile = open(args['output'],"w")
outfile.write("Tree_cluster\tMantel_Correlation_Coefficient\tManter_P-value\tCophenetic_Pearson\tCophenetic_P-value\n")
for i in args['all']:
fst_df = pd.read_table(i, sep='\t', skipinitialspace=True, index_col=0).as_matrix()
check_symmetry(fst_df)
mantel_coeff = 0.0
p_value_mantel = 0.0
cophenetic_pearson = 0.0
p_value_cophenetic = 0.0
n = 0
try:
mantel_coeff, p_value_mantel, n = mantel(ref_df, fst_df)
linkage_fst = linkage(fst_df, 'average')
c_fst, coph_dists_fst = cophenet(linkage_fst, pdist(fst_df))
cophenetic_pearson, p_value_cophenetic = pearsonr(coph_dists_ref, coph_dists_fst)
except Exception as e:
print("Error : %s" % str(e))
mantel_coeff = "Failed"
p_value_manel = "Failed"
cophenetic_pearson = "Failed"
p_value_cophenetic = "Failed"
outfile.write(i+"\t"+str(mantel_coeff)+"\t"+str(p_value_mantel)+"\t"+str(cophenetic_pearson)+"\t"+str(p_value_cophenetic)+"\n")
outfile.close()
示例11: test_two_sided
def test_two_sided(self):
np.random.seed(0)
obs = mantel(self.minx, self.minx, method="spearman", alternative="two-sided")
self.assertEqual(obs[0], 1)
self.assertAlmostEqual(obs[1], 0.328)
self.assertEqual(obs[2], 3)
obs = mantel(self.minx, self.miny, method="spearman", alternative="two-sided")
self.assertAlmostEqual(obs[0], 0.5)
self.assertAlmostEqual(obs[1], 1.0)
self.assertEqual(obs[2], 3)
obs = mantel(self.minx, self.minz, method="spearman", alternative="two-sided")
self.assertAlmostEqual(obs[0], -1)
self.assertAlmostEqual(obs[1], 0.322)
self.assertEqual(obs[2], 3)
示例12: test_one_sided_less
def test_one_sided_less(self):
# no need to seed here as permuted test statistics will all be less
# than or equal to the observed test statistic (1.0)
for method in self.methods:
obs = mantel(self.minx, self.minx, method=method,
alternative='less')
self.assertEqual(obs, (1, 1))
np.random.seed(0)
obs = mantel(self.minx, self.miny, alternative='less')
self.assertAlmostEqual(obs[0], self.exp_x_vs_y)
self.assertAlmostEqual(obs[1], 0.843)
obs = mantel(self.minx, self.minz, alternative='less')
self.assertAlmostEqual(obs[0], self.exp_x_vs_z)
self.assertAlmostEqual(obs[1], 0.172)
示例13: test_hommola_vs_mantel
def test_hommola_vs_mantel(self):
# we don't compare p-values because the two methods use different
# permutation strategies
r_mantel, p_mantel, _ = mantel(self.hdist, self.pdist, method="pearson", permutations=0, alternative="greater")
r_hommola, p_hommola, _ = hommola_cospeciation(self.hdist, self.pdist, self.interact_1to1, permutations=0)
self.assertAlmostEqual(r_hommola, r_mantel)
npt.assert_equal(p_hommola, p_mantel)
示例14: compare_tip_to_tip_distances
def compare_tip_to_tip_distances(tree_fh1, tree_fh2, method="pearson"):
tree1 = TreeNode.read(tree_fh1)
tree2 = TreeNode.read(tree_fh2)
dm1 = tree1.tip_tip_distances()
dm2 = tree2.tip_tip_distances()
return mantel(dm1, dm2, strict=False, method=method)
示例15: test_statistic_same_across_alternatives_and_permutations
def test_statistic_same_across_alternatives_and_permutations(self):
# Varying permutations and alternative hypotheses shouldn't affect the
# computed test statistics.
for n in (0, 99, 999):
for alt in self.alternatives:
for method, exp in (("pearson", self.exp_x_vs_y), ("spearman", 0.5)):
obs = mantel(self.minx, self.miny, method=method, permutations=n, alternative=alt)[0]
self.assertAlmostEqual(obs, exp)