前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >你的adonis用对了吗?不同因素的顺序竟然对结果有很大影响

你的adonis用对了吗?不同因素的顺序竟然对结果有很大影响

作者头像
生信宝典
发布2022-01-18 21:17:08
发布2022-01-18 21:17:08
2.6K00
代码可运行
举报
文章被收录于专栏:生信宝典生信宝典
运行总次数:0
代码可运行

前情回顾

方差分析基本概念:方差分析中的“元”和“因素”是什么?

PERMANOVA原理解释:这个统计检验可用于判断PCA/PCoA等的分群效果是否显著!

实战1:画一个带统计检验的PCoA分析结果

配对检验:画一个带统计检验的PcOA分析结果 (再进一步,配对比较)

新问题来了?

假如我们关注不同的管理风格 (Management)和土壤厚度 (A1)对物种组成是否有显著影响?,应该怎么检验呢?

代码语言:javascript
代码运行次数:0
运行
复制
library(vegan)
# 数据的解释和准备见前面的推文
data(dune)
data(dune.env)

A1在前,Moisture在后。这个情况下,A1Moisture都与群体结构有显著关系。A1可以解释16.8%的总体差异,Moisture解释27.6%的总体差异。

代码语言:javascript
代码运行次数:0
运行
复制
adonis(dune ~ A1 + Moisture, data=dune.env, permutations=9999)

## 
## Call:
## adonis(formula = dune ~ A1 + Moisture, data = dune.env, permutations = 9999) 
## 
## Permutation: free
## Number of permutations: 9999
## 
## Terms added sequentially (first to last)
## 
##           Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    
## A1         1    0.7230 0.72295  4.5393 0.16817 0.0003 ***
## Moisture   3    1.1871 0.39569  2.4845 0.27613 0.0061 ** 
## Residuals 15    2.3890 0.15927         0.55571           
## Total     19    4.2990                 1.00000           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Moisture在前,A1在后。这个情况下,只有Moisture与群体结构有显著关系。Moisture可以解释40.2%的总体差异,A1解释0.04%的总体差异。

For adonis and sequential tests in general, the order of terms should be meaningful. If it is not meaningful, the tests are hardly meaningful.

代码语言:javascript
代码运行次数:0
运行
复制
adonis(dune ~ Moisture + A1, data=dune.env, permutations=9999)

## 
## Call:
## adonis(formula = dune ~ Moisture + A1, data = dune.env, permutations = 9999) 
## 
## Permutation: free
## Number of permutations: 9999
## 
## Terms added sequentially (first to last)
## 
##           Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)    
## Moisture   3    1.7282 0.57606  3.6169 0.40199 0.0002 ***
## A1         1    0.1819 0.18186  1.1419 0.04230 0.3181    
## Residuals 15    2.3890 0.15927         0.55571           
## Total     19    4.2990                 1.00000           
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

输出结果中Terms added sequentially (first to last)这一句话很关键,表明环境因子的顺序对结果是有影响的,尤其是环境因子之间存在相关性时。

As there is some linear dependency, which ones goes into the model first determines how much variation is left to be explained by the second of the pair of covariates.

这时可以使用dbrda (基于距离的冗余分析),或者通过adonis2计算边缘概率 (by="margin")。

代码语言:javascript
代码运行次数:0
运行
复制
adonis2(dune ~ Moisture + A1, data=dune.env, permutations=9999, by="margin")

## Permutation test for adonis under reduced model
## Marginal effects of terms
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = dune ~ Moisture + A1, data = dune.env, permutations = 9999, by = "margin")
##          Df SumOfSqs      R2      F Pr(>F)   
## Moisture  3   1.1871 0.27613 2.4845 0.0052 **
## A1        1   0.1819 0.04230 1.1419 0.3228   
## Residual 15   2.3890 0.55571                 
## Total    19   4.2990 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

adonis2(dune ~ A1 + Moisture, data=dune.env, permutations=9999, by="margin")

## Permutation test for adonis under reduced model
## Marginal effects of terms
## Permutation: free
## Number of permutations: 9999
## 
## adonis2(formula = dune ~ A1 + Moisture, data = dune.env, permutations = 9999, by = "margin")
##          Df SumOfSqs      R2      F Pr(>F)   
## A1        1   0.1819 0.04230 1.1419 0.3257   
## Moisture  3   1.1871 0.27613 2.4845 0.0066 **
## Residual 15   2.3890 0.55571                 
## Total    19   4.2990 1.00000                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

ord <- dbrda(dune ~ A1 + Moisture, data = dune.env, dist = 'bray')
anova(ord, by = 'margin')

## Permutation test for dbrda under reduced model
## Marginal effects of terms
## Permutation: free
## Number of permutations: 999
## 
## Model: dbrda(formula = dune ~ A1 + Moisture, data = dune.env, distance = "bray")
##          Df SumOfSqs      F Pr(>F)   
## A1        1  0.18186 1.1419  0.329   
## Moisture  3  1.18708 2.4845  0.009 **
## Residual 15  2.38899                 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

在控制A1的情况下,Moisture对菌群的影响是显著的。反之,在控制Moisture的情况下,A1对菌群的影响是不显著的。

adonis和adonis2的区别

vegan包提供了两个函数adonisadonis2来进行PERMANOVA分析,这两个函数有什么区别呢?

  • adonis函数对提供的变量执行的是序贯检验 (sequential test)。也就是说变量的顺序会对结果有影响(尤其是变量之间存在相关时)。系统会先评估第一个变量解释的差异比例,再评估后续变量解释的剩余总体差异的比例。后面会有一个例子展示差异。这等同于adonis2使用参数by="terms" (默认参数)。这通常被称为I型误差平方和 (Type I sums of squares),此时,
    • 对于模型Y ~ A + B来讲,变量A的误差平方和为SS(A); 变量B的误差平方和是在给定A的基础上的平方和SS(B|A) = SS(A, B) - SS(A)
    • 对于模型Y ~ B + A来讲,变量B的误差平方和为SS(B); 变量A的误差平方和是在给定B的基础上的平方和SS(A|B) = SS(A, B) - SS(B)
  • 如果你希望变量的顺序不影响结果,那么需要使用adonis2,并且设置参数by="margin"。这时计算显著性时会考虑公式中其它所有变量,而不只是当前变量前面的那些变量。这通常被称为II型误差平方和 (Type II sums of squares),此时
    • 对于模型Y ~ A + B来讲,变量A的误差平方和为SS(A|B) = SS(A, B) - SS(B); 变量B的误差平方和SS(B|A) = SS(A, B) - SS(A)
    • 对于模型Y ~ B + A来讲,变量A的误差平方和为SS(A|B) = SS(A, B) - SS(B); 变量B的误差平方和SS(B|A) = SS(A, B) - SS(A)
  • 或者你想看整体模型是否显著,也需要使用adonis2,并且设置参数by="null"

Order does not matter when by="margin" because the significance is tested against a model that includes all other variables not just the ones preceding it in the formula. It seems that strata is now deprecated in favor of defining blocks in the permutations argument now (see adonis help). Anyway, these arguments allow you to specify how to restrict which rows can be exchanged during the permutation procedure used to calculate p values. adonis performs a sequential test of terms。adonis2 can perform sequential, marginal and overall tests. Function adonis2 also allows using additive constants or squareroot of dissimilarities to avoid negative eigenvalues,but both functions can handle semimetric indices (such as Bray-Curtis) that produce negative eigenvalues. Functionadonis2 can be much slower than adonis, in particular with several terms.

参考

  1. https://www.scribbr.com/frequently-asked-questions/one-way-vs-two-way-anova/
  2. MANOVA的前提假设 https://www.real-statistics.com/multivariate-statistics/multivariate-analysis-of-variance-manova/manova-assumptions/ https://www.statology.org/manova-assumptions/
  3. https://statistics.laerd.com/statistical-guides/one-way-anova-statistical-guide.php
  4. https://www.yunbios.net/h-nd-570.html
  5. https://mp.weixin.qq.com/s/v_k4Yhe9rBWM9y9A3P3wQw
  6. https://mp.weixin.qq.com/s?__biz=MzUzMjA4Njc1MA==&mid=2247484678&idx=1&sn=f95418a311e639704e9848545efc7fd7&scene=21#wechat_redirect
  7. https://chrischizinski.github.io/rstats/vegan-ggplot2/
  8. https://chrischizinski.github.io/rstats/adonis/
  9. https://chrischizinski.github.io/rstats/ordisurf/
  10. https://www.rdocumentation.org/packages/vegan/versions/1.11-0/topics/adonis
  11. https://www.jianshu.com/p/dfa689f7cafd
  12. https://stats.stackexchange.com/questions/312302/adonis-in-vegan-order-of-variables-non-nested-with-one-degree-of-freedom-for
  13. https://stats.stackexchange.com/questions/188519/adonis-in-vegan-order-of-variables-or-use-of-strata?noredirect=1
  14. https://github.com/vegandevs/vegan/issues/229
  15. https://stats.stackexchange.com/questions/476256/adonis-vs-adonis2
  16. 清晰解释Type I, Type II, Type III https://mcfromnz.wordpress.com/2011/03/02/anova-type-iiiiii-ss-explained/
  17. 清晰解释Type I, Type II, Type III https://stats.stackexchange.com/questions/60362/choice-between-type-i-type-ii-or-type-iii-anova
  18. https://thebiobucket.blogspot.com/2011/08/two-way-permanova-adonis-with-custom.html#more
  19. adonis的前提条件 https://thebiobucket.blogspot.com/2011/04/assumptions-for-permanova-with-adonis.html#more
  20. 作者的论文 https://static1.squarespace.com/static/580e3c475016e191c523a0e2/t/5813ba8b5016e1a5b61f454a/1477687949842/Anderson_et_al-2013-ANOSIM+vs.+PERMANOVA.pdf
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-09-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 生信宝典 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前情回顾
  • adonis和adonis2的区别
  • 参考
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档