library(BiodiversityR) # import filtered data otu_table<-read.csv("otu_table.csv",header=T,row.names=1) sample_meta<-read.csv("sample_meta.csv",header=T,row.names=1) # total species abundance sum_col<-apply(otu_table,2,sum) # eliminate species with abundance of 0 otu_table<-otu_table[,sum_col>0] # calculate total OTU abundance per sample sum_otu<-apply(otu_table,1,sum,na.rm=T) # what is the minimum min(sum_otu) # Calculate diversity by treatment # S diversitycomp(otu_table,y = sample_meta,index="richness",method="pooled",factor1 = "Treatment") # Shannon diversitycomp(otu_table,y = sample_meta,index="Shannon",method="pooled",factor1 = "Treatment") # Jevenness diversitycomp(otu_table,y = sample_meta,index="Jevenness",method="pooled",factor1 = "Treatment") # Species accumulation spec_accum<-specaccum(otu_table,"random") plot(spec_accum) # rarefy the data using rrarefy, sample size will be the minimum number of OTU by sample above otu_rarefied<-rrarefy(otu_table,sample=6850) # repeate the same analyses with the rarefied matrix # S diversitycomp(otu_rarefied,y = sample_meta,index="richness",method="pooled",factor1 = "Treatment") # Shannon diversitycomp(otu_rarefied,y = sample_meta,index="Shannon",method="pooled",factor1 = "Treatment") # Jevenness diversitycomp(otu_rarefied,y = sample_meta,index="Jevenness",method="pooled",factor1 = "Treatment") # Species accumulation spec_accum<-specaccum(otu_rarefied,"random") plot(spec_accum) # rank abundance plot for the rarefied data, by treatment rankabuncomp(otu_rarefied,y=sample_meta,factor="Treatment") # bray curtis braycurt<-vegdist(otu_rarefied) mean(braycurt) braycurt<-vegdist(otu_table) mean(braycurt)