• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python distance.mantel函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skbio.stats.distance.mantel函数的典型用法代码示例。如果您正苦于以下问题:Python mantel函数的具体用法?Python mantel怎么用?Python mantel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mantel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:7,代码来源:test_mantel.py


示例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]])
开发者ID:RNAer,项目名称:scikit-bio,代码行数:8,代码来源:test_mantel.py


示例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)
开发者ID:gblanchard4,项目名称:scikit-bio,代码行数:10,代码来源:test_mantel.py


示例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)
开发者ID:josenavas,项目名称:scikit-bio,代码行数:11,代码来源:test_mantel.py


示例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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:12,代码来源:test_mantel.py


示例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)
开发者ID:josenavas,项目名称:scikit-bio,代码行数:13,代码来源:test_mantel.py


示例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)
开发者ID:josenavas,项目名称:scikit-bio,代码行数:14,代码来源:test_mantel.py


示例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))
开发者ID:josenavas,项目名称:scikit-bio,代码行数:15,代码来源:test_mantel.py


示例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)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:16,代码来源:test_mantel.py


示例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()
开发者ID:zorino,项目名称:ray,代码行数:33,代码来源:treeclust-compare.py


示例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)
开发者ID:josenavas,项目名称:scikit-bio,代码行数:17,代码来源:test_mantel.py


示例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)
开发者ID:gblanchard4,项目名称:scikit-bio,代码行数:17,代码来源:test_mantel.py


示例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)
开发者ID:ttimbers,项目名称:scikit-bio,代码行数:8,代码来源:test_hommola.py


示例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)
开发者ID:JTFouquier,项目名称:ghost-tree,代码行数:8,代码来源:util.py


示例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)
开发者ID:josenavas,项目名称:scikit-bio,代码行数:8,代码来源:test_mantel.py


示例16: test_distance_matrix_instances_as_input

    def test_distance_matrix_instances_as_input(self):
        # Matrices with all matching IDs in the same order.
        np.random.seed(0)

        obs = mantel(self.minx_dm, self.miny_dm, alternative='less')

        self.assertAlmostEqual(obs[0], self.exp_x_vs_y)
        self.assertAlmostEqual(obs[1], 0.843)
        self.assertEqual(obs[2], 3)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:9,代码来源:test_mantel.py


示例17: test_invalid_input

    def test_invalid_input(self):
        # invalid correlation method
        with self.assertRaises(ValueError):
            mantel([[1]], [[1]], method='brofist')

        # invalid permutations
        with self.assertRaises(ValueError):
            mantel([[1]], [[1]], permutations=-1)

        # invalid alternative
        with self.assertRaises(ValueError):
            mantel([[1]], [[1]], alternative='no cog yay')

        # mismatched shape
        with self.assertRaises(ValueError):
            mantel(self.minx, [[0, 2], [2, 0]])

        # too small dms
        with self.assertRaises(ValueError):
            mantel([[0, 3], [3, 0]], [[0, 2], [2, 0]])
开发者ID:gblanchard4,项目名称:scikit-bio,代码行数:20,代码来源:test_mantel.py


示例18: test_distance_matrix_instances_with_lookup

    def test_distance_matrix_instances_with_lookup(self):
        self.minx_dm.ids = ("a", "b", "c")
        self.miny_dm.ids = ("d", "e", "f")
        lookup = {"a": "A", "b": "B", "c": "C", "d": "A", "e": "B", "f": "C"}

        np.random.seed(0)

        obs = mantel(self.minx_dm, self.miny_dm, alternative="less", lookup=lookup)
        self.assertAlmostEqual(obs[0], self.exp_x_vs_y)
        self.assertAlmostEqual(obs[1], 0.843)
        self.assertEqual(obs[2], 3)
开发者ID:josenavas,项目名称:scikit-bio,代码行数:11,代码来源:test_mantel.py


示例19: test_distance_matrix_instances_as_input

    def test_distance_matrix_instances_as_input(self):
        # IDs shouldn't matter -- the function should only care about the
        # matrix data
        dmx = DistanceMatrix(self.minx)
        dmy = DistanceMatrix(self.miny, ['no', 'cog', 'yay'])

        np.random.seed(0)

        obs = mantel(dmx, dmy, alternative='less')

        self.assertAlmostEqual(obs[0], self.exp_x_vs_y)
        self.assertAlmostEqual(obs[1], 0.843)
开发者ID:gblanchard4,项目名称:scikit-bio,代码行数:12,代码来源:test_mantel.py


示例20: test_distance_matrix_instances_with_lookup

    def test_distance_matrix_instances_with_lookup(self):
        self.minx_dm.ids = ('a', 'b', 'c')
        self.miny_dm.ids = ('d', 'e', 'f')
        lookup = {'a': 'A', 'b': 'B', 'c': 'C',
                  'd': 'A', 'e': 'B', 'f': 'C'}

        np.random.seed(0)

        obs = mantel(self.minx_dm, self.miny_dm, alternative='less',
                     lookup=lookup)
        self.assertAlmostEqual(obs[0], self.exp_x_vs_y)
        self.assertAlmostEqual(obs[1], 0.843)
        self.assertEqual(obs[2], 3)
开发者ID:RNAer,项目名称:scikit-bio,代码行数:13,代码来源:test_mantel.py



注:本文中的skbio.stats.distance.mantel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python distance.pwmantel函数代码示例发布时间:2022-05-27
下一篇:
Python composition.closure函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap