This document provides supplementary material and information to the article:

Hernvann, P.Y., Gascuel, D., Kopp, D., Robert, M., et Rivot, E. (2021). EcoDiet – A hierarchical Bayesian model to combine stomach, biotracer and literature data into diet matrix estimation. Ecological Applications.

Load the EcoDiet package

You can do it from the CRAN or from GitHub

#install.packages("EcoDiet")
library("EcoDiet")

Or you can do it from GitHub

#install.packages("devtools")
devtools::install_github("pyhernvann/EcoDiet", build_vignettes = TRUE, dependencies = TRUE)
library("EcoDiet")

Load the data

The data is available on the SEANOE repository where these .html files are located:

Hernvann, P.Y., Gascuel, D., Kopp, D., Robert, M., et Rivot, E. (2021). Showcasing EcoDiet, a novel hierarchical model to combine stomach, biotracer and literature data into diet matrix estimation: simulated and in situ trophic data. SEANOE.

The Celtic Sea data is available in the Celtic_Sea_data.RData file.

all_datasets_Celtic <- get(load("Celtic_Sea_data.RData"))

The three datasets, stomach content analyses, stables isotope analyses and literature knowledge can be extracted:

SCA_data_CelticSea <- all_datasets_Celtic[["SCA_CelticSea"]]
SIA_data_CelticSea <- all_datasets_Celtic[["SIA_CelticSea"]]
Literature_data_CelticSea <- all_datasets_Celtic[["Literature_CelticSea"]]

Transform the datasets into EcoDiet data input format

This allows pre-processing the Celtic Sea data and parametrizing EcoDiet so that the model can be run.

input_CelticSea <- preprocess_data(biotracer_data = SIA_data_CelticSea,
                        trophic_discrimination_factor = c(0.8, 3.4),
                        literature_configuration = TRUE,
                        stomach_data = SCA_data_CelticSea,
                        literature_diets = Literature_data_CelticSea,
                        nb_literature = 30,
                        literature_slope = 0.5)

A quick look at the data

Stomach content and biotracer analyses:

plot_data(biotracer_data = SIA_data_CelticSea)
## Warning: Use of `biotracer_data$group` is discouraged. Use `group` instead.

# some configurations of R may fail to run the following plot_data() function for stomach data:
# plot_data(biotracer_data = SCA_data_CelticSea)
# if it is the case (this function of the package is currently being repaired), run the following:
SCA_to_plot <- melt(SCA_data_CelticSea)
colnames(SCA_to_plot) <- c("prey", "pred", "value")
SCA_to_plot %>%
  group_by(pred) %>%
  mutate(prop=ifelse(value!=0,value/value[which(prey=="full")],NA)) %>%
  filter(prey!="full") %>%
  ggplot(aes_string(x = "pred", y = "prey", fill = "prop")) + geom_raster() + theme_bw() +
    scale_y_discrete(limits=rev) +
    scale_fill_gradient(low = "white", high = "blue3", limit = c(0, 1)) +
    ggtitle("Relative occurrence in stomachs (occ/nb of stom.)") +
    ylab("Preys") +
    xlab("Predators") +
    theme(panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.title = element_text(size = 15),
          axis.text.x = element_text(size = 12, angle = 20, vjust = 1, hjust = 1),
          axis.text.y = element_text(size = 12),
          legend.title = element_blank(),
          plot.title = element_text(hjust = 0.5))

Literature knowledge

# some configurations of R may fail to run the following plot_prior() function for stomach data:
# plot_prior(input_CelticSea, literature_configuration=T, variable="PI")
# if it is the case (this function of the package is currently being repaired), run the following:
lit_to_plot <- melt(cbind(rownames(Literature_data_CelticSea),Literature_data_CelticSea))
colnames(lit_to_plot) <- c("prey", "pred", "value")
lit_to_plot %>%
    filter(prey!="pedigree") %>%
    mutate(value=ifelse(value!=0,value,NA)) %>%
  ggplot(aes_string(x = "pred", y = "prey", fill = "value")) + geom_raster() + theme_bw() +
    scale_y_discrete(limits=rev) +
    scale_fill_gradient(low = "white", high = "blue3", limit = c(0, 1)) +
    ggtitle("Diet % in the literature") +
    ylab("Preys") +
    xlab("Predators") +
    theme(panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          axis.title = element_text(size = 15),
          axis.text.x = element_text(size = 12, angle = 20, vjust = 1, hjust = 1),
          axis.text.y = element_text(size = 12),
          legend.title = element_blank(),
          plot.title = element_text(hjust = 0.5))

Run EcoDiet on the Celtic Sea data

Then, EcoDiet can be run. As literature data is available for the Celtic Sea food web, this should be specified in write_model. The results, including the estimated diet and topology matrices, are saved in mcmc_output. The number of adaptation steps and iterations were set at 10^5 and 10^7, respectively, to reach the convergence.

model_string <- write_model(literature_configuration = TRUE)

mcmc_output <- run_model(textConnection(model_string),
                         input_CelticSea,
                         nb_adapt = 1e5, nb_iter = 1e7)

For more info on how running the EcoDiet model, please check the package Vignettes available on the CRAN repository or GitHub.

To run IsoWeb on SIA data only, please refer to the R function provided in Supplementary Material of Kadoya et al. (2012) available here