Lab on longitudinal analyses of microbiome data

Early warnings (EWS)

Here, we demonstrate the application of early warning indicators from Dakos, V., et al (2012) PLoS ONE 7(7): e41010. doi:10.1371/journal.pone.0041010 based on the earlywarnings R package. This is a technical demonstration of using the toolkit.

Install the package in R with:

library(devtools)
install_github("earlywarningtoolbox/earlywarnings-R/earlywarnings")

Load example data

library(earlywarnings)  
data(foldbif)

Demonstrate EWS for a simulated bifurcation:

out <- generic_ews(foldbif,winsize=50,detrending='gaussian', bandwidth=5,logtransform=FALSE,interpolate=FALSE)

Now let us demonstrate ews for a phyloseq object. We use the MovingPictures example data set from the microbeDS R package (also available on USB).

library(MicrobeDS) # twbattaglia/MicrobeDS
library(microbiome)
library(phyloseq)
library(dplyr)

# Let us pick a subset
ps <- subset_samples(MovingPictures, host_subject_id == "F4" & body_site == "UBERON:tongue") 

# Estimate diversity
sample_data(ps)$diversity <- unlist(microbiome::diversity(ps, "shannon"))

# Tidy up the time point information
sample_data(ps)$timepoint <- as.numeric(as.Date(gsub(" 0:00", "", as.character(sample_data(ps)$collection_timestamp)), "%m/%d/%Y") - as.Date("10/21/08", "%m/%d/%Y"))

# Order the entries by time
d <- meta(ps) %>% arrange(timepoint)

# The visualization shows relation between time and diversity
# The time points are not exactly evenly distributed:
ggplot(d, aes(x = timepoint, y = diversity)) + geom_point() + geom_line()

# Let us calculate the EWS for diversity.
# We ignore here the fact that the time points are not evenly spaced,
# and use this as the first approximation.
out <- generic_ews(d$diversity,winsize=50, detrending='gaussian', bandwidth=5,logtransform=FALSE,interpolate=FALSE)

Question: Does the diversity indicate early warnings of state shift?

Simulating time series from ecological models

Install the seqtime R package. This can be used to simulate microbiome time series from standard ecological models. See Signatures of ecological processes in microbial community time series Faust et al. Microbiome, 6(120) 2018.

install_github("hallucigenia-sparsa/seqtime/")

Set model parameters and initial species abundances.

library(seqtime)
N <- 50
y <- round(generateAbundances(N,mode=5))
names(y) <- c(1:length(y))
barplot(y,main="Initial species abundances",xlab="Species",ylab="Abundance")

Simulate time series from the neutral model, and visualize the output.

library(seqtime)
out.hubbell <- simHubbell(N=N, M=N,I=1500,d=N, m.vector=(y/sum(y)), m=0.1, tskip=500, tend=1000)

# Visualize the time series
tsplot(out.hubbell,main="Hubbell")

Compare the simulations with Taylor’s law.

hubbell.taylor <- seqtime::taylor(out.hubbell, pseudo=0.0001, col="blue", type="taylor")

Question: What is Taylor’s law?

The Hubbell time series is dominated by brown noise:

hubbell.noise=identifyNoisetypes(out.hubbell,smooth=TRUE)
## [1] "Number of taxa below the abundance threshold:  0"
## [1] "Number of taxa with non-significant power spectrum laws:  0"
## [1] "Number of taxa with non-classified power spectrum:  9"
## [1] "Number of taxa with white noise:  0"
## [1] "Number of taxa with pink noise:  0"
## [1] "Number of taxa with brown noise:  41"
## [1] "Number of taxa with black noise:  0"
plotNoisetypes(hubbell.noise)

Task: Next, generate time series from Dirichlet-Multinomial as instructed in the seqtime vignette.

Task (Optional): You can also generate time series from generalized Lotka-Volterra model.

Question: What noise color is generated by this simulation?

Question: What ecological process has been linked to this color?

Question: What is a key difference between Dirichlet-Multinomial and Hubbell model?

Question: What is a key difference between these models and the Lotka-Volterra model?

Simulating noise with different spectra

Task: Generate noise with different colors as instructed in seqtime vignette.

Question: How you can quantify chaos in the time series?

Question: Which noise spectrum is the most chaotic?