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.

True values

The simulated data is available in the true_values.RData file.

data_true <- get(load("true_data.RData"))

from which you can extract the true topology and diet matrices

Topo_true <- data_true$Topo_true
Bivalves Cod Crabs Detritus Phytoplankton Pout Sardine Shrimps Worms Zooplankton
Bivalves 0 0 1 0 0 1 0 0 0 0
Cod 0 0 0 0 0 0 0 0 0 0
Crabs 0 1 0 0 0 1 0 0 0 0
Detritus 1 0 1 0 0 0 0 1 1 0
Phytoplankton 1 0 0 0 0 0 1 1 0 1
Pout 0 1 0 0 0 0 0 0 0 0
Sardine 0 1 0 0 0 0 0 0 0 0
Shrimps 0 1 1 0 0 1 1 0 0 0
Worms 0 1 1 0 0 1 0 1 0 0
Zooplankton 0 0 0 0 0 1 1 1 0 0
Diets_true <- data_true$Diets_true
Bivalves Cod Crabs Detritus Phytoplankton Pout Sardine Shrimps Worms Zooplankton
Bivalves 0.00 0.00 0.25 0 0 0.05 0.0 0.00 0 0
Cod 0.00 0.00 0.00 0 0 0.00 0.0 0.00 0 0
Crabs 0.00 0.20 0.00 0 0 0.15 0.0 0.00 0 0
Detritus 0.25 0.00 0.15 0 0 0.00 0.0 0.25 1 0
Phytoplankton 0.75 0.00 0.00 0 0 0.00 0.1 0.10 0 1
Pout 0.00 0.30 0.00 0 0 0.00 0.0 0.00 0 0
Sardine 0.00 0.15 0.00 0 0 0.00 0.0 0.00 0 0
Shrimps 0.00 0.25 0.20 0 0 0.40 0.1 0.00 0 0
Worms 0.00 0.10 0.40 0 0 0.25 0.0 0.10 0 0
Zooplankton 0.00 0.00 0.00 0 0 0.15 0.8 0.55 0 0

Simulated data

The simulated data is available in the simulated_data.RData file.

data_simu <- get(load("simulated_data.RData"))

Select the data you want to apply EcoDiet

You can select a specific Scenario (A, B, C, D; see the Material & Methods in the main manuscript) and replicate. For instance, if you want to run EcoDiet on the first set of replicates simulated following Scenario A, would would first define:

sc<-"A"
replic<-1

and then run:

SCA_data <- data_simu[[paste0("SCA_", sc, "_", replic)]]
SIA_data <- data_simu[[paste0("SIA_", replic)]]

Then you can have a quick look at the data.

kable(SCA_data)
Bivalves Cod Crabs Detritus Phytoplankton Pout Sardine Shrimps Worms Zooplankton
Bivalves 0 0 68 0 0 74 0 0 0 0
Cod 0 0 0 0 0 0 0 0 0 0
Crabs 0 75 0 0 0 83 0 0 0 0
Detritus 65 0 76 0 0 0 0 67 67 0
Phytoplankton 71 0 0 0 0 0 70 66 0 69
Pout 0 71 0 0 0 0 0 0 0 0
Sardine 0 77 0 0 0 0 0 0 0 0
Shrimps 0 71 72 0 0 67 64 0 0 0
Worms 0 66 57 0 0 69 0 73 0 0
Zooplankton 0 0 0 0 0 59 75 67 0 0
full 90 100 100 0 0 100 96 99 67 69
kable(head(SIA_data))
group d13C d15N
Bivalves -15.82111 13.10608
Bivalves -15.06362 13.83079
Bivalves -15.40783 13.29187
Bivalves -15.55041 12.98912
Bivalves -15.51697 13.39435
Bivalves -15.67060 13.23671

Transform the datasets into EcoDiet data input format

First, you should transform the data in the appropriate format required by EcoDiet using the preprocess_data function.

For the simulation-reestimation exercise, EcoDiet was used to explore all links present in the true topology (no false existence of trophic links is allowed).

  input_EcoDiet <- preprocess_data(biotracer_data = SIA_data,
                               trophic_discrimination_factor = c(0.8, 3.4),
                               literature_configuration = FALSE,
                               stomach_data = SCA_data,
                               topology=Topo_true,
                               rescale_stomach = FALSE)
## The model will investigate the following trophic links:
##               Bivalves Cod Crabs Detritus Phytoplankton Pout Sardine Shrimps
## Bivalves             0   0     1        0             0    1       0       0
## Cod                  0   0     0        0             0    0       0       0
## Crabs                0   1     0        0             0    1       0       0
## Detritus             1   0     1        0             0    0       0       1
## Phytoplankton        1   0     0        0             0    0       1       1
## Pout                 0   1     0        0             0    0       0       0
## Sardine              0   1     0        0             0    0       0       0
## Shrimps              0   1     1        0             0    1       1       0
## Worms                0   1     1        0             0    1       0       1
## Zooplankton          0   0     0        0             0    1       1       1
##               Worms Zooplankton
## Bivalves          0           0
## Cod               0           0
## Crabs             0           0
## Detritus          1           0
## Phytoplankton     0           1
## Pout              0           0
## Sardine           0           0
## Shrimps           0           0
## Worms             0           0
## Zooplankton       0           0

Run EcoDiet on the simulated data

Then the model can be run on the formatted data. As no literature data is available for these simulations, 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^4 and 10^6, respectively, to reach the convergence.

  model_string <- write_model(literature_configuration = FALSE)
  
  
  mcmc_output<- run_model(textConnection(model_string),
                       input_EcoDiet,
                       nb_adapt = 1e4, nb_iter = 1e6)

Visualize EcoDiet results

plot_results(mcmc_output, input_EcoDiet)

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