Advanced Search
Last updated date: Oct 30, 2020 Views: 837 Forks: 0
Statistical analysis
CHC data
Microbiome data
Both CHC and Microbiome
Run pairwise comparisons with FDR p-value correction if more than two groups are compared.
Example R code for Pairwise PerMANOVA, taken from https://www.researchgate.net/post/How_can_I_do_PerMANOVA_pairwise_contrasts_in_R
x = C[,2:20] #Include only data in your dataframe, no text.
factors= C$group
pairwise.adonis <- function(x,factors, sim.method, p.adjust.m)
{
library(vegan)
co = as.matrix(combn(unique(factors),2))
pairs = c()
F.Model =c()
R2 = c()
p.value = c()
for(elem in 1:ncol(co)){
ad = adonis(x[factors %in%
c(as.character(co[1,elem]),as.character(co[2,elem])),] ~
factors[factors %in%
c(as.character(co[1,elem]),as.character(co[2,elem]))] , method =sim.method);
pairs = c(pairs,paste(co[1,elem],'vs',co[2,elem]));
F.Model =c(F.Model,ad$aov.tab[1,4]);
R2 = c(R2,ad$aov.tab[1,5]);
p.value = c(p.value,ad$aov.tab[1,6])
}
p.adjusted = p.adjust(p.value,method=p.adjust.m)
pairw.res = data.frame(pairs,F.Model,R2,p.value,p.adjusted)
return(pairw.res)
}
PW.Adonis.fdr=pairwise.adonis(x,factors,sim.method="bray",p.adjust.m = "fdr")
Visualize data using non-metric multidimensional scaling using Bray-Curtis dissimilarity, and either 2 or three dimensions in order to minimize stress to <0.1.
Example R code:
library(vegan)
C.2 <- C[,2:20] #Just the data from your dataframe, no text.
C.NMDS <- metaMDS(C.2, k=3, trymax= 100) #k represents dimensions
C.NMDS
stressplot(C.NMDS)
plot(C.NMDS)
text(C.NMDS, display= "sites")
Example R code:
C.s <- stack(C[,4:22]) #Must stack your data before you can run the test.
write.csv(C.s, "data.csv") #Write as a .csv and then edit to include your group information
C.s2 <- read.csv("data.csv", header=T)
for(i in unique(C.s2$Compound)) {
c <- subset(C.s2, C.s2$Compound == i)
print(i)
print(kruskal.test(Proportion ~ group, data = c))}
Behavioral data
Strain comparisons
Example R code:
KW <- kruskal.test(T$prop, T$group)
require(PMCMR)
print(posthoc.kruskal.dunn.test(x=T$prop, g=T$group, p.adjust="fdr"))
Example R code:
ggplot(T, aes(x=group, y = SNPs)) +
geom_violin() +
stat_summary(mapping = aes(x = group, y = SNPs),
fun.ymin = function(z) { quantile(z,0.25) },
fun.ymax = function(z) { quantile(z,0.75) },
fun.y = median) +
theme_classic()
Do you have any questions about this protocol?
Post your question to gather feedback from the community. We will also invite the authors of this article to respond.
Share
Bluesky
X
Copy link