R actual combat | Replacement multivariate analysis of variance (take PCoA's PERMANOVA analysis as an example)

e9c46a77b5af14ba894df0039b8598bb.jpeg

adonis-cover

Permutational multivariate analysis of variance (PERMANOVA), also known as nonparametric multivariate analysis of variance, or ADONIS analysis. It uses the distance matrix (such as Euclidean distance, Bray-Curtis distance) to decompose the total variance, analyzes the explanation degree of different grouping factors or different environmental factors to the sample differences, and uses the "permutation test" to analyze the statistical significance of each variable explanation . Significant analysis.

one example

PCAFor example, after // dimensionality reduction visualization of species abundance data detected by metagenomics , there is some NMDSoverlap PCoAbetween samples in different groups, so how to judge whether there are significant differences in sample composition between these groups? This requires PERMANOVAa test to test whether the center points of samples in different groups overlap.

d9de597e398ca7f685e61ce6a1636010.png
example
9df37981a3a75055637f60e55b243524.png 0ab0b31f8a4d7dfc70d2efe9f93c6f29.png

Taking the above PCoApicture as an example, the four groups of sample points circled by ellipses correspond to the four altitude groups. Are the community differences among these four groups of samples significant? The essence of testing community differences between groups is to test the differences between distance matrices, and ordinary ANOVA analysis is powerless. The analysis based on the distance matrix PerMANOVAshowed that the difference between these four groups was significant (p<0.05).

Rui J, Li J, Wang S, et al. Responses of Bacterial Communities to Simulated Climate Changes in Alpine Meadow Soil of the Qinghai-Tibet Plateau. Appl Environ Microbiol. 2015;81(17):6070-6077. doi:10.1128/AEM.00557-15

Sample data and code collection

点赞, 在看This article, share it in the circle of friends 集赞20个and 保留30分钟send the screenshot to WeChat mzbj0002to receive it.

"Chuzhou Notes 2022 VIP can receive it for free" .

"Note:" 2022 will be over soon, for the convenience of readers and friends, it is now launched 木舟笔记永久VIPat a price 169¥. 2022VIPOnly pay the difference to upgrade. 木舟笔记永久VIPEnjoy all the resources of this account (except for limited courses), and no VIP plans will be launched in the future.

Muzhou Notes 2022 VIP Plan

"rights and interests:"

  1. "2022" Muzhou Notes all tweet sample data and codes ( "updated in real time in the VIP group" ).

    b6c549e9eb8905e7d02c83c992ed0b1d.png
    data+code
  2. Muzhou Notes "Scientific Research Exchange Group" .

  3. "Half price" purchase 跟着Cell学作图系列合集(free tutorial + code collection) | Follow Cell to learn drawing series collection .

"TOLL:"

"99¥/person" . You can add WeChat: mzbj0002transfer, or directly reward at the end of the article.

3df820fdad1861517894fe36e6933581.png

combat

PCoA

# Load package
library(vegan)
library(ggplot2)
library(ggthemes)
# Load data
otu <- read.table('otu.txt',row.names = 1,header = T)
group <- read.table('group.txt',header = T)
#pcoa
# vegdist函数,计算距离;method参数,选择距离类型
distance <- vegdist(otu, method = 'bray')
# 对加权距离进行PCoA分析
pcoa <- cmdscale(distance, k = (nrow(otu) - 1), eig = TRUE)
## plot data
# 提取样本点坐标
plot_data <- data.frame({pcoa$point})[1:2]

# 提取列名,便于后面操作。
plot_data$ID <- rownames(plot_data)
names(plot_data)[1:2] <- c('PCoA1', 'PCoA2')

# eig记录了PCoA排序结果中,主要排序轴的特征值(再除以特征值总和就是各轴的解释量)
eig = pcoa$eig

#为样本点坐标添加分组信息
plot_data <- merge(plot_data, group, by = 'ID', all.x = TRUE)
head(plot_data)

# 计算加权bray-curtis距离
dune_dist <- vegdist(otu, method="bray", binary=F)
dune_pcoa <- cmdscale(dune_dist, k=(nrow(otu) - 1), eig=T)

dune_pcoa_points <- as.data.frame(dune_pcoa$points)
sum_eig <- sum(dune_pcoa$eig)
eig_percent <- round(dune_pcoa$eig/sum_eig*100,1)

colnames(dune_pcoa_points) <- paste0("PCoA", 1:3)

dune_pcoa_result <- cbind(dune_pcoa_points, group)

head(dune_pcoa_result)
library(ggplot2)

ggplot(dune_pcoa_result, aes(x=PCoA1, y=PCoA2, fill=group)) +
  geom_point(shape = 21,color = 'black',size=4) +
  stat_ellipse(level=0.95)+
  scale_fill_manual(values = c('#73bbaf','#d15b64','#592c93'))+
  labs(x=paste("PCoA 1 (", eig_percent[1], "%)", sep=""),
       y=paste("PCoA 2 (", eig_percent[2], "%)", sep=""))  +
  theme_classic()
b83a0694f240c35406aba601830b24c7.png

PERMANOVA

# 基于bray-curtis距离进行计算
dune.div <- adonis2(otu ~ group, data = group, permutations = 999, method="bray")

dune.div
library(ggalt)
dune_adonis <- paste0("adonis R2: ",round(dune.div$R2,2), "; P-value: ", dune.div$`Pr(>F)`)

p <- ggplot(dune_pcoa_result, aes(x=PCoA1, y=PCoA2, fill=group)) +
  geom_point(shape = 21,color = 'black',size=4) +
  stat_ellipse(level=0.95)+
  scale_fill_manual(values = c('#73bbaf','#d15b64','#592c93'))+
  labs(x=paste("PCoA 1 (", eig_percent[1], "%)", sep=""),
       y=paste("PCoA 2 (", eig_percent[2], "%)", sep=""),
       title=dune_adonis)  +
  theme_classic()
p
88204c44f1f6aa19dd47031705165681.png
image-20221228004115608

Pair Adonis

# 配对Adonis确定两两分组之间对物种组成差异的影响
#devtools::install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis")
library(pairwiseAdonis)
dune.pairwise.adonis <- pairwise.adonis(x=otu, factors=group$group, 
                                        sim.function = "vegdist",
                                        sim.method = "bray",
                                        p.adjust.m = "BH",
                                        reduce = NULL,
                                        perm = 999)

library(ggpubr)
library(patchwork)
tab2 <- ggtexttable(dune.pairwise.adonis[,c("pairs","R2","p.value","p.adjusted")], rows = NULL, 
                    theme = ttheme("blank")) %>% 
  tab_add_hline(at.row = 1:2, row.side = "top", linewidth = 1)  %>% 
  tab_add_hline(at.row = nrow(dune.pairwise.adonis)+1, row.side = "bottom", linewidth = 1)  

p + tab2  + plot_layout(design=c(area(1,1), area(2,1)))
77f5b84c81d9f598fbaa95bf03f29336.png

previous content

  1. CNS Chart Reappearance | Biological Information Analysis | R Drawing Resource Sharing & Discussion Group!

  2. How to draw this picture | A bit complicated scatter plot

  3. How to draw this picture | Correlation Analysis Lollipop Chart

  4. Group student letter | Front Immunol | A simple routine for screening early diagnostic markers based on serum proteome

  5. (Free tutorial + code collection) | Follow Cell to learn drawing series collection

  6. Q&A | How to draw beautiful illustrations in papers?

  7. Follow Cell to learn drawing | Mulberry map (ggalluvial)

  8. R actual combat | Lasso regression model establishment and variable screening

  9. Follow NC to map | Advanced interaction network diagram (protein + enrichment pathway) (Cytoscape)

  10. R actual combat | Add a circle to the clustering (ggunchull)

  11. R actual combat | NGS data time series analysis (maSigPro)

  12. Learn to draw with Cell | Venn Diagram (ggVennDiagram)


cb3b060d5977f37dc20927ef3ac60a4c.png
Canoe Notes Matrix

Guess you like

Origin blog.csdn.net/weixin_45822007/article/details/128471298