美文网首页
R: adonis进行permannova

R: adonis进行permannova

作者: 胡童远 | 来源:发表于2021-11-11 10:04 被阅读0次

    adonis文档:
    https://www.rdocumentation.org/packages/vegan/versions/2.4-2/topics/adonis

    vegdist文档:
    https://www.rdocumentation.org/packages/vegan/versions/2.4-2/topics/vegdist

    依赖包

    library("vegan")
    

    1 输入数据

    多样本变量矩阵

    data=data.frame(matrix(rnorm(100, 100, 10), 10, 10))
    rownames(data)=paste("sample", 1:10, sep="_")
    colnames(data)=paste("var", 1:10, sep="_")
    

    表型数据

    env = data.frame(sample = paste("sample", 1:10, sep="_"), 
                                group = c(rep("A", 5), rep("B", 5)))
    

    2 permannova:表型与矩阵的关联

    adonis(data ~ group,  # 矩阵 ~ 表型变量
           data = env,  # 表型表格
           distance = "bray",   # 距离算法
           permutations = 999)  # 排列次数
    

    3 提取p值

    # 循环所有算法
    algo = c("manhattan", "euclidean", "canberra", "bray", "kulczynski", "jaccard", "gower", "altGower", "morisita", "horn", "mountford", "raup", "binomial", "chao", "cao", "mahalanobis")
    p=c()
    for(title in algo)
    {
        res = adonis(data ~ group, data = env, 
                     distance = title, permutations = 999)
        # 提取P value并保存
        p = c(p, res$aov.tab$Pr[1])
        print(title)
    }
    perm = data.frame(algo, p)
    

    更多:
    带统计学的PCoA完美解决打样本量多组数据不好区分

    相关文章

      网友评论

          本文标题:R: adonis进行permannova

          本文链接:https://www.haomeiwen.com/subject/ffmwzltx.html