You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Betadiversity.Rmd
+73-43Lines changed: 73 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -23,11 +23,14 @@ output:
23
23
24
24
25
25
26
-
## Beta diversity
26
+
## Beta diversity
27
27
28
-
Some examples on calculating beta diversity and using it to quantify community divergence within a given sample set.
28
+
Beta diversity quantifies dissimilarity in community composition between samples. Dissimilarity can be also quantified by _distance_ or _divergence_. These measures have a broad use in statistical data analysis.
29
+
30
+
The [vegan R package](https://cran.r-project.org/web/packages/vegan/index.html) and the [phyloseq R package](https://bioconductor.org/packages/release/bioc/html/phyloseq.html) implement a number of standard ecological dissimilarity measures implemented in the 'vegdist' function.
31
+
32
+
Here, we show brief examples on how to compare sample heterogeneity between groups and over time.
29
33
30
-
See [Community comparisons](Comparisons.html) page for examples on group-level comparisons based on beta diversity measures, including [limma](limma.html), [PERMANOVA](PERMANOVA.html), [mixed models](Mixedmodels.html), and [negative binomial](Negativebinomial.html).
31
34
32
35
Load example data
33
36
@@ -38,37 +41,15 @@ data(peerj32)
38
41
pseq <- peerj32$phyloseq
39
42
```
40
43
41
-
42
-
## Quantifying group divergence / spread
43
-
44
-
Divergence of a given sample set can be quantified as the average dissimilarity of each sample from the group mean; the dissimilarity can be quantified by beta diversity, for instance. This was applied in group-level comparisons for instance in [Salonen et al. ISME J 2014](http://www.nature.com/ismej/journal/v8/n11/full/ismej201463a.html) (they focused on homogeneity using inverse correlation, whereas here we focus on divergence using correlation but the measure is essentially the same).
45
-
46
-
Calculate group divergences within the LGG (probiotic) and Placebo groups
47
-
48
-
```{r divergence-example2bb, message=FALSE}
49
-
b.pla <- divergence(subset_samples(pseq, group == "Placebo"))
50
-
b.lgg <- divergence(subset_samples(pseq, group == "LGG"))
51
-
```
52
-
53
-
Use these to compare microbiota divergence within each group. The LGG group tends to have smaller values, indicating that the samples are more similar to the group mean, and the LGG group is less heterogeneous (has smaller spread / is more homogeneous):
The **inter- and intra-invididual stability** (or homogeneity) measures are obtained as 1-b where b is the group divergence with the anticorrelation method ([Salonen et al. ISME J 2014](http://www.nature.com/ismej/journal/v8/n11/full/ismej201463a.html)).
60
-
61
-
62
-
63
44
## Intra-individual divergence
64
45
65
-
Quantify beta diversity within subjects over time (as in [Salonen et al. ISME J 2014](http://www.nature.com/ismej/journal/v8/n11/full/ismej201463a.html) for intra-individual stability)
46
+
Divergence within subjects may increase following intervention.
# Beta diversity between the current time point and baseline
119
+
b <- vegdist(rbind(a[, s0], a[, st]), method = "bray")
120
+
# Add to the list
122
121
beta <- rbind(beta, c(tp, b))
123
122
}
124
123
colnames(beta) <- c("time", "beta")
125
124
beta <- as.data.frame(beta)
126
125
126
+
theme_set(theme_bw(20))
127
127
library(ggplot2)
128
128
p <- ggplot(beta, aes(x = time, y = beta)) +
129
-
geom_point() + geom_line()
130
-
print(p)
129
+
geom_point() +
130
+
geom_line() +
131
+
geom_smooth() +
132
+
labs(x = "Time (Days)", y = "Beta diversity (Bray-Curtis)")
133
+
print(p)
131
134
```
135
+
136
+
137
+
## Inter-individual divergence / spread
138
+
139
+
Divergence within a sample set quantifies the overall heterogeneity in community composition across samples or individuals. This is sometimes quantified as the average dissimilarity of each sample from the group mean; the dissimilarity can be quantified by beta diversity as in [Salonen et al. ISME J 2014](http://www.nature.com/ismej/journal/v8/n11/full/ismej201463a.html) (they focused on homogeneity using inverse divergence but the measure is essentially the same).
140
+
141
+
Calculate divergences within the LGG (probiotic) and Placebo groups with respect to the median profile within each group.
142
+
143
+
```{r divergence-example2bb, message=FALSE}
144
+
pseq <- peerj32$phyloseq
145
+
146
+
b.pla <- divergence(subset_samples(pseq, group == "Placebo"),
147
+
apply(abundances(subset_samples(pseq, group == "Placebo")), 1, median))
148
+
149
+
b.lgg <- divergence(subset_samples(pseq, group == "LGG"),
150
+
apply(abundances(subset_samples(pseq, group == "LGG")), 1, median))
151
+
```
152
+
153
+
154
+
The group with larger values has a more heterogeneous community composition.
0 commit comments