No 5. Beta Diversity Estimates

Script testing different distance metrics to estimate beta diversity using the whole and core fish gut communities across a range of environmental variables.

Next, we turn our attention to beta diversity estimates of fish guts. For both the whole community (i.e., all ASVs) and the core community (i.e., only core ASVs), we assess beta diversity against the following conditions:

  1. Position: inside bay, outside bay
  2. Zone: Inner bay, Inner bay disturbed, Outer bay
  3. Reef Type: disturbed, healthy
  4. Reef: ALR, CCR, PBL, PPR, PST, RNW, ROL, SCR, SIS

For each condition or combination of conditions, we perform the following beta diversity estimates: Jaccard, Modified Gower, Bray Curtis, UNIFRAC, GUNIFRAC, WUNIFRAC. For each diversity metric, we a) calculate a dissimilarity matrix, b) assess beta dispersions, c) run a PERMANOVA, and in some cases, d) look at pairwise comparisons.

Whole Community

First, we load the rarefied whole fish gut microbiome data.

ps.whole <- readRDS("rdata/p3/ps_16S_bocas_fish_final.rds")

Jaccard

Dissimilarity Matrix

All

set.seed(1911)
type.jaccard <- phyloseq::distance(ps.whole, method = "jaccard", binary = T)
sampledf <- data.frame(sample_data(ps.whole))

Inner Only

ps.whole.inner <- subset_samples(ps.whole, Zone != "Outer bay")
type.jaccard.inner <- phyloseq::distance(ps.whole.inner,
                                         method = "jaccard", binary = T)
sampledf.inner <- data.frame(sample_data(ps.whole.inner))

Beta Dispersions

By Zone

beta.jaccard1 <- betadisper(type.jaccard, sampledf$Zone,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.jaccard1, binary = TRUE, pairwise = TRUE,
          permutations = 10000)

By Position

beta.jaccard2 <- betadisper(type.jaccard, sampledf$Position,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.jaccard2, binary = TRUE, pairwise = TRUE,
          permutations = 10000)

By Reef Type (inside bay)

beta.jaccard3 <- betadisper(type.jaccard.inner, sampledf.inner$Reef_type,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.jaccard3, binary = TRUE, pairwise = TRUE,
          permutations = 10000)

PERMANOVA

By Zone

adonis.jaccard0 <- adonis(type.jaccard ~ Zone, data = sampledf,
                          permutations = 10000)

By Reef

adonis.jaccardR <- adonis(type.jaccard ~ Reef, data = sampledf,
                          permutations = 10000)

By Zone nested with Reef

adonis.jaccard1<- adonis(type.jaccard ~ Zone/Reef, data = sampledf,
                         permutations = 10000)

By Position nested with Reef

adonis.jaccard2 <- adonis(type.jaccard ~ Position/Reef, data = sampledf,
                          permutations = 10000)

By Reef Type nested with Reef (inside bay)

The variable reef type is healthy and disturbed (based on level coral cover).

adonis.jaccard3 <- adonis(type.jaccard.inner ~ Reef_type/Reef,
                          data = sampledf.inner, permutations = 10000)

Pairwise comparisons

By Zone

pairwise1 <- pairwise.adonis(type.jaccard, factors = sampledf$Zone)

By Reef

pairwise2 <- pairwise.adonis(type.jaccard, factors = sampledf$Reef)

Modified Gower

For the modified Gower, we log transform the data using the microbiome package transformation because it uses the vegan deconstand function. The distance matrix will be created from the log transformed data.

Dissimilarity Matrix

set.seed(1911)
data.log10<- microbiome::transform(ps.whole, transform = "log10p")
sampledf.log10 <- data.frame(sample_data(data.log10))
type.modGower <- phyloseq::distance(data.log10, method = "altGower")

Beta Dispersions

By Zone

beta.Gower1 <- betadisper(type.modGower, sampledf.log10$Zone,
                          type = "centroid", bias.adjust = TRUE)
permutest(beta.Gower1, pairwise = TRUE, permutations = 10000)

By Reef

beta.GowerR <- betadisper(type.modGower, sampledf.log10$Reef,
                          type = "centroid", bias.adjust = TRUE)
permutest(beta.GowerR, pairwise = TRUE, permutations = 10000)

By Position

beta.Gower2 <- betadisper(type.modGower, sampledf.log10$Position,
                          type = "centroid", bias.adjust = TRUE)
permutest(beta.Gower2, pairwise = TRUE, permutations = 10000)

By Reef Type (inside bay)

data.log10.inner <- subset_samples(data.log10, Zone != "Outer bay")
type.modGower.inner <- phyloseq::distance(data.log10.inner, method = "altGower")
sampledf.inner <- data.frame(sample_data(data.log10.inner))
beta.Gower3 <- betadisper(type.modGower.inner, sampledf.inner$Reef_type,
                          type = "centroid", bias.adjust = TRUE)
permutest(beta.Gower3, binary = TRUE, pairwise = TRUE,
          permutations = 10000)

PERMANOVA

By Zone

set.seed(1911)
adonis.modGower0 <- adonis(type.modGower ~ Zone, data = sampledf.log10,
                           permutations = 10000)

By Reef

adonis.modGowerR <- adonis(type.modGower ~ Reef, data = sampledf.log10,
                           permutations = 10000)

By Zone nested with Reef

adonis.modGower1 <- adonis(type.modGower ~ Zone/Reef, data = sampledf.log10,
                           permutations = 10000)

By Position nested with Reef

adonis.modGower2 <- adonis(type.modGower ~ Position/Reef, data = sampledf.log10,
                           permutations = 10000)

By Reef Type nested with Reef (inside bay)

data.log10.inner <- subset_samples(data.log10, Zone != "Outer bay")
type.modGower.inner <- phyloseq::distance(data.log10.inner, method = "altGower")
sampledf.inner.log10 <- data.frame(sample_data(data.log10.inner))
adonis.modGower3 <- adonis(type.modGower.inner ~ Reef_type/Reef,
                           data = sampledf.inner.log10, permutations = 10000)

Pairwise comparisons

By Zone

set.seed(1911)
pairwise.adonis(type.modGower, factors = sampledf$Zone)

By Reef

set.seed(1911)
pairwise.adonis(type.modGower, factors = sampledf$Reef)

Bray Curtis

Dissimilarity Matrix

set.seed(1911)
type.bray <- phyloseq::distance(ps.whole, method = "bray")
sampledf <- data.frame(sample_data(ps.whole))

Beta Dispersions

By Zone

beta.bray1 <- betadisper(type.bray, sampledf$Zone,
                         type = "centroid", bias.adjust = TRUE)
permutest(beta.bray1, pairwise = TRUE, permutations = 10000)

By Reef

beta.brayR <- betadisper(type.bray, sampledf$Reef,
                         type = "centroid", bias.adjust = TRUE)
permutest(beta.brayR, pairwise = TRUE, permutations = 10000)

By Position

beta.bray2 <- betadisper(type.bray, sampledf$Position,
                         type = "centroid", bias.adjust = TRUE)
permutest(beta.bray2, pairwise = TRUE, permutations = 10000)

By Reef Type (inside bay)

ps.whole.inner <- subset_samples(ps.whole, Zone != "Outer bay")
type.bray.inner <- phyloseq::distance(ps.whole.inner, method = "bray")
beta.bray3 <- betadisper(type.bray.inner, sampledf.inner$Reef_type,
                         type = "centroid", bias.adjust = TRUE)
permutest(beta.bray3, pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone

set.seed(1911)
adonis.bray0 <- adonis(type.bray ~ Zone, data = sampledf,
                            permutations = 10000)

By Reef

adonis.brayR <- adonis(type.bray ~ Reef, data = sampledf,
                               permutations = 10000)

By Zone nested with in Reef

adonis.bray1 <- adonis(type.bray ~ Zone/Reef, data = sampledf,
                            permutations = 10000)

By Position nested with Reef

adonis.bray2 <- adonis(type.bray ~ Position/Reef, data = sampledf,
                            permutations = 10000)

By Reef Type nested with Reef (inside bay)

ps.whole.inner <- subset_samples(ps.whole, Zone != "Outer bay")
type.bray.inner <- phyloseq::distance(ps.whole.inner, method = "bray")
sampledf.inner <- data.frame(sample_data(ps.whole.inner))
adonis.bray3 <- adonis(type.bray.inner ~ Reef_type/Reef, data = sampledf.inner,
                           permutations = 10000)

Pairwise comparisons

By Zone

set.seed(1911)
pairwise.adonis(type.bray, factors = sampledf$Zone)

By Reef

set.seed(1911)
pairwise.adonis(type.bray, factors = sampledf$Reef)

UNIFRAC

Dissimilarity Matrix

set.seed(1911)
type.unifrac <- phyloseq::distance(ps.whole, method = "unifrac", weighted = F)
sampledf <- data.frame(sample_data(ps.whole))

Beta Dispersions

By Zone

beta.unifrac1 <- betadisper(type.unifrac, sampledf$Zone,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.unifrac1, pairwise = TRUE, permutations = 10000)

By Reef

beta.unifracR <- betadisper(type.unifrac, sampledf$Reef,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.unifracR, pairwise = TRUE, permutations = 10000)

By Position

beta.unifrac2 <- betadisper(type.unifrac, sampledf$Position,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.unifrac2, pairwise = TRUE, permutations = 10000)

By Reef Type (inside bay)

ps.whole.inner <- subset_samples(ps.whole, Zone != "Outer bay")
type.unifrac.inner <- phyloseq::distance(ps.whole.inner, method = "unifrac")
sampledf.whole.inner <- data.frame(sample_data(ps.whole.inner))
beta.unifrac3 <- betadisper(type.unifrac.inner, sampledf.whole.inner$Reef_type,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.unifrac3, pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone

set.seed(1911)
adonis.unifrac0 <- adonis(type.unifrac ~ Zone, data = sampledf,
                               permutations = 10000)

By Reef

adonis.unifracR <- adonis(type.unifrac ~ Reef, data = sampledf,
                                  permutations = 10000)

By Zone nested with Reef

adonis.unifrac1 <- adonis(type.unifrac ~ Zone/Reef, data = sampledf,
                             permutations = 10000)

By Position nested with Reef

adonis.unifrac2 <- adonis(type.unifrac ~ Position/Reef, data = sampledf,
                               permutations = 10000)

By Reef Type nested with Reef (inside bay)

ps.whole.inner <- subset_samples(ps.whole, Zone != "Outer bay")
type.unifrac.inner <- phyloseq::distance(ps.whole.inner, method = "unifrac")
sampledf.inner <- data.frame(sample_data(ps.whole.inner))

adonis.unifrac3 <- adonis(type.unifrac.inner ~ Reef_type/Reef,
                          data = sampledf.inner, permutations = 10000)

Pairwise comparisons

By Zone

set.seed(1911)
pairwise.adonis(type.unifrac, factors = sampledf$Zone)

By Reef

set.seed(1911)
pairwise.adonis(type.unifrac, factors = sampledf$Reef)

GUNIFRAC

Dissimilarity Matrix

asv.tab<-otu_table(ps.whole)
ps.whole.inner <- subset_samples(ps.whole, Zone != "Outer bay")
asv.tab.inner <- otu_table(ps.whole.inner)

tree.fish<-phy_tree(ps.whole)
tree.fish.inner<-phy_tree(ps.whole.inner)

fish.sample<-sample_data(ps.whole)
fish.sample.inner<-sample_data(ps.whole.inner)

groups2.whole <- fish.sample$Zone
groupsR.whole <- fish.sample$Reef
groups.inner <- fish.sample.inner$Zone
position.whole <- fish.sample$Position
unifracs <- GUniFrac(asv.tab, tree.fish,
                     alpha=c(0, 0.5, 1))$unifracs
unifracs.inner <- GUniFrac(asv.tab.inner, tree.fish.inner,
                           alpha=c(0, 0.5, 1))$unifracs

d5.all <- unifracs[, , "d_0.5"]
d5.inner <- unifracs.inner[, , "d_0.5"]
type.gunifrac <- as.dist(d5.all)
type.gunifrac.inner <- as.dist(d5.inner)

Beta Dispersion

set.seed(1911)
beta.gunifrac1 <- betadisper(as.dist(d5.all), groups2.whole,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.gunifrac1, pairwise = TRUE, permutations = 10000)

By Reef

beta.gunifracR <- betadisper(as.dist(d5.all), groupsR.whole,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.gunifracR, pairwise = TRUE, permutations = 10000)

By Position

beta.gunifrac2 <- betadisper(as.dist(d5.all), position.whole,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.gunifrac2, pairwise = TRUE, permutations = 10000)

By Reef Type (inner bay only)

beta.gunifrac.inner <- betadisper(as.dist(d5.inner), groups.inner,
                                  type = "centroid", bias.adjust = TRUE)
permutest(beta.gunifrac.inner, pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone nested with Reef

sampledf <- data.frame(sample_data(ps.whole))
sampledf.inner <- data.frame(sample_data(ps.whole.inner))
adonis.gunifrac1<- adonis(type.gunifrac ~ Zone/Reef, data = sampledf,
                           permutations = 10000)

By Position nested with Reef

adonis.gunifrac2<- adonis(type.gunifrac ~ Position/Reef, data = sampledf,
                                    permutations = 10000)

By Reef Type nested with Reef (inside bay)

adonis.gunifrac3<- adonis(type.gunifrac.inner ~ Reef_type/Reef,
                          data = sampledf.whole.inner, permutations = 10000)

Pairwise comparisons

as a substitute for posthoc test of PERMANOVA

By Zone

pairwise.adonis(type.gunifrac, factors = sampledf$Zone,
                p.adjust.m = "bonferroni")

By Reef

pairwise.adonis(type.gunifrac, factors = sampledf$Reef,
                p.adjust.m = "bonferroni")

WUNIFRAC

Dissimilarity Matrix

set.seed(1911)
type.wunifrac <- phyloseq::distance(ps.whole, method = "wunifrac")
sampledf <- data.frame(sample_data(ps.whole))

Beta Dispersions

By Zone

beta.wunifrac1 <- betadisper(type.wunifrac, sampledf$Zone,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.wunifrac1, pairwise = TRUE, permutations = 10000)

By Reef

beta.wunifracR <- betadisper(type.wunifrac, sampledf$Reef,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.wunifracR, pairwise = TRUE, permutations = 10000)

By Position

beta.wunifrac2 <- betadisper(type.wunifrac, sampledf$Position,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.wunifrac2, pairwise = TRUE, permutations = 10000)

By Zone (inside bay only)

ps.whole.inner <- subset_samples(ps.whole, Zone != "Outer bay")
type.wunifrac.inner <- phyloseq::distance(ps.whole.inner, method = "wunifrac")
sampledf.inner <- data.frame(sample_data(ps.whole.inner))

By Reef Type (inside bay)

beta.wunifrac3 <- betadisper(type.wunifrac.inner, sampledf.inner$Reef_type,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.wunifrac3, pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone

set.seed(1911)
adonis.wunifrac0 <- adonis(type.wunifrac ~ Zone, data = sampledf,
                                permutations = 10000)

By Reef

adonis.wunifracR <- adonis(type.wunifrac ~ Reef, data = sampledf,
                                permutations = 10000)

By Zone nested with Reef

adonis.wunifrac1 <- adonis(type.wunifrac ~ Zone/Reef, data = sampledf,
                                permutations = 10000)

By Position nested with Reef

adonis.wunifrac2 <- adonis(type.wunifrac ~ Position/Reef, data = sampledf,
                                permutations = 10000)

Pairwise comparisons

By Zone

set.seed(1911)
pairwise.adonis(type.wunifrac, factors = sampledf$Zone)

By Reef

set.seed(1911)
pairwise.adonis(type.wunifrac, factors = sampledf$Reef)

Whole Community Summary



Core Community

First, we load the unrarefied core fish gut microbiome data.

ps.core <- readRDS("rdata/p1/ps_indv01_core_fish.rds")
ps.core

Jaccard

Dissimilarity Matrix

All

set.seed(1911)
type.jaccard <- phyloseq::distance(ps.core, method = "jaccard", binary = T)
sampledf <- data.frame(sample_data(ps.core))

Inner Only

ps.core.inner <- subset_samples(ps.core, Zone != "Outer bay")
type.jaccard.inner <- phyloseq::distance(ps.core.inner,
                                         method = "jaccard", binary=T)
sampledf.inner <- data.frame(sample_data(ps.core.inner))

Beta Dispersions

By Zone

beta.jaccard1 <- betadisper(type.jaccard, sampledf$Zone,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.jaccard1, binary = TRUE, pairwise = TRUE, permutations = 10000)

By Position

beta.jaccard2 <- betadisper(type.jaccard, sampledf$Position,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.jaccard2,  binary = TRUE,  pairwise = TRUE, permutations = 10000)

By Reef Type (inside bay)

beta.jaccard3 <- betadisper(type.jaccard.inner, sampledf.inner$Reef_type,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.jaccard3,  binary = TRUE,  pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone

adonis.jaccard0<- adonis(type.jaccard ~ Zone, data = sampledf,
                         permutations = 10000)

By Reef

adonis.jaccardR<- adonis(type.jaccard ~ Reef, data = sampledf,
                         permutations = 10000)
#by Zone with Reef nested in Zone
adonis.jaccard1<- adonis(type.jaccard ~ Zone/Reef, data = sampledf,
                         permutations = 10000)

By Position nested with Reef

adonis.jaccard2 <- adonis(type.jaccard ~ Position/Reef, data = sampledf,
                          permutations = 10000)

By Reef Type nested with Reef (inside bay)

adonis.jaccard3 <- adonis(type.jaccard.inner ~ Reef_type/Reef,
                          data = sampledf.inner, permutations = 10000)

Pairwise comparisons

By Zone

set.seed(1911)
pairwise1 <- pairwise.adonis(type.jaccard, factors = sampledf$Zone)

By Reef

pairwise2 <- pairwise.adonis(type.jaccard, factors = sampledf$Reef)

Modified Gower

Again, for the modified Gower, we log transform the data using the microbiome package transformation because it uses the vegan deconstand function. The distance matrix will be created from the log transformed data.

Dissimilarity Matrix

set.seed(1911)
data.log10<- microbiome::transform(ps.core, transform = "log10p")
sampledf.log10 <- data.frame(sample_data(data.log10))
type.modGower <- phyloseq::distance(data.log10, method = "altGower")

Beta Dispersions

by Zone

beta.Gower1 <- betadisper(type.modGower, sampledf.log10$Zone,
                          type = "centroid", bias.adjust = TRUE)
permutest(beta.Gower1,  pairwise = TRUE, permutations = 10000)

By Reef

beta.GowerR <- betadisper(type.modGower, sampledf.log10$Reef,
                          type = "centroid", bias.adjust = TRUE)
permutest(beta.GowerR,  pairwise = TRUE, permutations = 10000)

by Position

beta.Gower2 <- betadisper(type.modGower, sampledf.log10$Position,
                          type = "centroid", bias.adjust = TRUE)
permutest(beta.Gower2,  pairwise = TRUE, permutations = 10000)

By Reef Type (inside bay)

data.log10.inner <- subset_samples(data.log10, Zone != "Outer bay")
type.modGower.inner <- phyloseq::distance(data.log10.inner,
                                          method = "altGower")
sampledf.inner <- data.frame(sample_data(data.log10.inner))
beta.Gower3 <- betadisper(type.modGower.inner, sampledf.inner$Reef_type,
                          type = "centroid", bias.adjust = TRUE)
permutest(beta.Gower3,  binary = TRUE,  pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone

set.seed(1911)
adonis.modGower0 <- adonis(type.modGower ~ Zone, data = sampledf.log10,
                           permutations = 10000)

By Reef

adonis.modGowerR <- adonis(type.modGower ~ Reef, data = sampledf.log10,
                           permutations = 10000)

By Zone nested with Reef

adonis.modGower1 <- adonis(type.modGower ~ Zone/Reef, data = sampledf.log10,
                           permutations = 10000)

By Position nested with Reef

adonis.modGower2 <- adonis(type.modGower ~ Position/Reef, data = sampledf.log10,
                           permutations = 10000)

By Reef Type nested with Reef (inside bay)

data.log10.inner <- subset_samples(data.log10, Zone != "Outer bay")
type.modGower.inner <- phyloseq::distance(data.log10.inner, method = "altGower")
sampledf.inner.log10 <- data.frame(sample_data(data.log10.inner))
adonis.modGower3 <- adonis(type.modGower.inner ~ Reef_type/Reef,
                           data = sampledf.inner.log10, permutations = 10000)

Pairwise comparisons

By Zone

pairwise.adonis(type.modGower, factors = sampledf$Zone)

By Reef

pairwise.adonis(type.modGower, factors = sampledf$Reef)

Bray Curtis

Dissimilarity Matrix

set.seed(1911)
type.bray <- phyloseq::distance(ps.core, method = "bray")
sampledf <- data.frame(sample_data(ps.core))

Beta Dispersions

By Zone

beta.bray1 <- betadisper(type.bray, sampledf$Zone,
                         type = "centroid", bias.adjust = TRUE)
permutest(beta.bray1,  pairwise = TRUE, permutations = 10000)

By Reef

beta.brayR <- betadisper(type.bray, sampledf$Reef,
                         type = "centroid", bias.adjust = TRUE)
permutest(beta.brayR,  pairwise = TRUE, permutations = 10000)

By Position

beta.bray2 <- betadisper(type.bray, sampledf$Position,
                         type = "centroid", bias.adjust = TRUE)
permutest(beta.bray2,  pairwise = TRUE, permutations = 10000)

By Reef Type (inside bay)

ps.core.inner <- subset_samples(ps.core, Zone != "Outer bay")
type.bray.inner <- phyloseq::distance(ps.core.inner, method = "bray")
beta.bray3 <- betadisper(type.bray.inner, sampledf.inner$Reef_type,
                         type = "centroid", bias.adjust = TRUE)
permutest(beta.bray3,  pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone

set.seed(1911)
adonis.bray0 <- adonis(type.bray ~ Zone, data = sampledf,
                       permutations = 10000)

By Reef

adonis.brayR <- adonis(type.bray ~ Reef, data = sampledf,
                       permutations = 10000)

By Zone nested with in Reef

adonis.brayR
adonis.bray1 <- adonis(type.bray ~ Zone/Reef, data = sampledf,
                       permutations = 10000)

By Position nested with Reef

adonis.bray2 <- adonis(type.bray ~ Position/Reef, data = sampledf,
                       permutations = 10000)

By Reef Type nested with Reef (inside bay)

ps.core.inner <- subset_samples(ps.core, Zone != "Outer bay")
type.bray.inner <- phyloseq::distance(ps.core.inner, method = "bray")
sampledf.inner <- data.frame(sample_data(ps.core.inner))
adonis.bray3 <- adonis(type.bray.inner ~ Reef_type/Reef, data = sampledf.inner,
                       permutations = 10000)

Pairwise comparisons

By Zone

set.seed(1911)
pairwise.adonis(type.bray, factors = sampledf$Zone)

By Reef

set.seed(1911)
pairwise.adonis(type.bray, factors = sampledf$Reef)

UNIFRAC

Dissimilarity Matrix

set.seed(1911)
type.unifrac <- phyloseq::distance(ps.core, method = "unifrac", weighted=F)
sampledf <- data.frame(sample_data(ps.core))

Beta Dispersions

By Zone

beta.unifrac1 <- betadisper(type.unifrac, sampledf$Zone,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.unifrac1,  pairwise = TRUE, permutations = 10000)

By Reef

beta.unifracR <- betadisper(type.unifrac, sampledf$Reef,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.unifracR,  pairwise = TRUE, permutations = 10000)

By Position

beta.unifrac2 <- betadisper(type.unifrac, sampledf$Position,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.unifrac2, pairwise = TRUE, permutations = 10000)

By Reef Type (inside bay)

ps.core.inner <- subset_samples(ps.core, Zone != "Outer bay")
type.unifrac.inner <- phyloseq::distance(ps.core.inner, method = "unifrac")
sampledf.core.inner <- data.frame(sample_data(ps.core.inner))
beta.unifrac3 <- betadisper(type.unifrac.inner, sampledf.core.inner$Reef_type,
                            type = "centroid", bias.adjust = TRUE)
permutest(beta.unifrac3,  pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone

set.seed(1911)
adonis.unifrac0 <- adonis(type.unifrac ~ Zone, data = sampledf,
                          permutations = 10000)

By Reef

adonis.unifracR <- adonis(type.unifrac ~ Reef, data = sampledf,
                          permutations = 10000)

By Zone nested with Reef

adonis.unifrac1 <- adonis(type.unifrac ~ Zone/Reef, data = sampledf,
                          permutations = 10000)

By Position nested with Reef

adonis.unifrac2 <- adonis(type.unifrac ~ Position/Reef, data = sampledf,
                          permutations = 10000)

By Reef Type nested with Reef (inside bay)

ps.core.inner <- subset_samples(ps.core, Zone != "Outer bay")
type.unifrac.inner <- phyloseq::distance(ps.core.inner, method = "unifrac")
sampledf.inner <- data.frame(sample_data(ps.core.inner))
adonis.unifrac3 <- adonis(type.unifrac.inner ~ Reef_type/Reef,
                          data = sampledf.inner,
                          permutations = 10000)

Pairwise comparisons

By Zone

set.seed(1911)
pairwise.adonis(type.unifrac, factors = sampledf$Zone)

By Reef

set.seed(1911)
pairwise.adonis(type.unifrac, factors = sampledf$Reef)

GUNIFRAC

Dissimilarity Matrix

asv.tab<-otu_table(ps.core)
ps.core.inner <- subset_samples(ps.core, Zone != "Outer bay")
asv.tab.inner <- otu_table(ps.core.inner)
tree.fish.core<-phy_tree(ps.core)
tree.fish.core.inner<-phy_tree(ps.core.inner)
fish.sample.core<-sample_data(ps.core)
fish.sample.core.inner<-sample_data(ps.core.inner)
groups2.core <- fish.sample.core$Zone
groupsR.core <- fish.sample.core$Reef
groups.inner.core <- fish.sample.core.inner$Zone
position.core <- fish.sample.core$Position
unifracs <- GUniFrac(asv.tab, tree.fish.core,
                     alpha=c(0, 0.5, 1))$unifracs
unifracs2 <- GUniFrac(asv.tab.inner, tree.fish.core.inner,
                      alpha=c(0, 0.5, 1))$unifracs
d5.all <- unifracs[, , "d_0.5"]
d5.inner <- unifracs2[, , "d_0.5"]
type.gunifrac <- as.dist(d5.all)
type.gunifrac.inner <- as.dist(d5.inner)

Beta Dispersions

By Zone

set.seed(1911)
beta.gunifrac1 <- betadisper(as.dist(d5.all), groups2.core,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.gunifrac1, pairwise = TRUE, permutations = 10000)

By Reef

beta.gunifracR <- betadisper(as.dist(d5.all), groupsR.core,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.gunifracR, pairwise = TRUE, permutations = 10000)

By Position

beta.gunifrac2 <- betadisper(as.dist(d5.all), position.core,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.gunifrac2, pairwise = TRUE, permutations = 10000)

By Zone (Position, inside bay)

beta.gunifrac.inner <- betadisper(as.dist(d5.inner), groups.inner.core,
                                  type = "centroid", bias.adjust = TRUE)
permutest(beta.gunifrac.inner, pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone nested with Reef

sampledf <- data.frame(sample_data(ps.core))
sampledf.inner <- data.frame(sample_data(ps.core.inner))

By Zone

adonis.gunifrac0<- adonis(type.gunifrac ~ Zone, data = sampledf,
                          permutations = 10000)

By Reef

adonis.gunifracR<- adonis(type.gunifrac ~ Zone, data = sampledf,
                          permutations = 10000)

By Zone nested with in Reef

adonis.gunifrac1<- adonis(type.gunifrac ~ Zone/Reef, data = sampledf,
                          permutations = 10000)

By Position nested with Reef

adonis.gunifrac2<- adonis(type.gunifrac ~ Position/Reef, data = sampledf,
                          permutations = 10000)

By Reef Type nested with Reef (inside bay)

adonis.gunifrac3<- adonis(type.gunifrac.inner ~ Reef_type/Reef,
                          data = sampledf.core.inner, permutations = 10000)

Pairwise comparisons

By Zone

pairwise.adonis(type.gunifrac, factors = sampledf$Zone,
                p.adjust.m = "bonferroni")

By Reef

pairwise.adonis(type.gunifrac, factors = sampledf$Reef,
                p.adjust.m = "bonferroni")

WUNIFRAC

Dissimilarity Matrix

set.seed(1911)
type.wunifrac <- phyloseq::distance(ps.core, method = "wunifrac")
sampledf <- data.frame(sample_data(ps.core))

Beta Dispersions

By Zone

beta.wunifrac1 <- betadisper(type.wunifrac, sampledf$Zone,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.wunifrac1,  pairwise = TRUE, permutations = 10000)
ps.core.inner <- subset_samples(ps.core, Zone != "Outer bay")
type.wunifrac.inner <- phyloseq::distance(ps.core.inner, method = "wunifrac")
sampledf.inner <- data.frame(sample_data(ps.core.inner))

By Reef

beta.wunifracR <- betadisper(type.wunifrac, sampledf$Reef,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.wunifracR,  pairwise = TRUE, permutations = 10000)

By Position

beta.wunifrac2 <- betadisper(type.wunifrac, sampledf$Position,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.wunifrac2,  pairwise = TRUE, permutations = 10000)

By Reef Type (inside bay)

beta.wunifrac3 <- betadisper(type.wunifrac.inner, sampledf.inner$Reef_type,
                             type = "centroid", bias.adjust = TRUE)
permutest(beta.wunifrac3,  pairwise = TRUE, permutations = 10000)

PERMANOVA

By Zone

set.seed(1911)
adonis.wunifrac0 <- adonis(type.wunifrac ~ Zone, data = sampledf,
                           permutations = 10000)

By Reef

adonis.wunifracR <- adonis(type.wunifrac ~ Reef, data = sampledf,
                           permutations = 10000)

By Zone nested with Reef

adonis.wunifrac1 <- adonis(type.wunifrac ~ Zone/Reef, data = sampledf,
                           permutations = 10000)

By Position nested with Reef

adonis.wunifrac2 <- adonis(type.wunifrac ~ Position/Reef, data = sampledf,
                           permutations = 10000)

By Reef Type nested with Reef (inside bay)

ps.core.inner <- subset_samples(ps.core, Zone != "Outer bay")
type.wunifrac.inner <- phyloseq::distance(ps.core.inner, method = "wunifrac")
sampledf.inner <- data.frame(sample_data(ps.core.inner))
adonis.wunifrac3 <- adonis(type.wunifrac.inner ~ Reef_type/Reef,
                           data = sampledf.inner, permutations = 10000)

Pairwise comparisons

By Zone

pairwise.adonis(type.wunifrac, factors = sampledf$Zone)

By Reef

pairwise.adonis(type.wunifrac, factors = sampledf$Reef)

Core Community Summary


That’s the end of Script 5. In the next Script we assess Beta Dispersion for all beta diversity estimates.


Previous

Next

Source Code

The source code for this page can be accessed on GitHub by clicking this link.

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/bocasbiome/web/, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".