This code is associated with the article: 'Predictions of biodiversity are improved by integrating trait-based competition with abiotic filtering' by Loïc Chalmandrier*, Daniel B. Stouffer, Adam S. T. Purcell, William G. Lee, Andrew J. Tanentzap and Daniel C. Laughlin
* main code developper and contact. ([email protected])
The code models species abundances using functional traits, community data and environmental data. It assumes that species abundances are constrained by abiotic filtering (Traitspace model) and then competition (Banquo model). First species carrying capacities are modeled through the Traitspace model (using a trait-environment multivariate linear model) and then pairwise competitive interaction are calibrated using the Banquo model through a nloptr algorithm.
This project has received funding from the European Union’s Horizon 2020 research and innovation programme under the Marie Skłodowska- Curie grant agreement No 840946.
R 4.1.0
BayesianTools, corpcor, DEoptim, extraDistr, ggpubr, mclust, mgcv, plyr, pROC, purrr, tidyverse
'./data/community.cover.23sp.csv': community matrix - site by species matrix
'data/cover_class.txt': contains the names and the minimum and maximum cover associated to each cover class
'data/data_ready.Rdata': contains the formatted data (output of the script data_prep.R)
'kettleholedata.23sp.csv': contains the functional trait data in each site and for each species
'traitspace_objs.Rdata': contains the output of the script traitspace_gen.R
'./lib/abgFunctions.R': functions to calculate community alpha and beta diversity
'./lib/interactionMatrix.R': functions to calculate the pairwise interaction matrix
'./lib/Likelihood.R': functions to calculate the likelihood of the Banquo models
'./lib/traitspace_and_banquo.R': functions to compute Traitspace and to compute Banquo
'./main/analysis_results.R': script using the final output to produce the table and figures of the article
'./main/assembly_models.R': Main script. It uses the output of traitspace_gen.R and compute the different Banquo models.
'./main/data_prep.R': script to prepare the data.
'./main/priors.R': script to create the prior density function, the prior sampling function and parameter bounds
'./main/traitspace_gen.R': script to compute Traitspace from the data.
'./results/\*.eps': Figures of the main article.
'./results/\*.jpg': Figures of the supplementary material.
'./results/tab.csv': Table 1 of the main article
'./results/abio_TRUE/\*/posterior_objs.Rdata': it contains most notably the posterior distribution of the abiotic and the abiotic + biotic models. The objects are saved in subfolder named after the traits used to calibrate biotic interactions (including no interactions in the folder called 'none')
'./results/abio_TRUE/\*/posterior_objs.Rdata': it contains most notably the posterior distribution of the null model and the biotic models. The objects are saved in subfolder named after the traits used to calibrate biotic interactions (including no interactions in the folder called 'none')
'./results/post_models/post_Model_\*.jpg': graphics of the posterior distribution of each assembly model.
- set the working directory to the root of the repository.
- run data_prep.R: from the raw data, this script prepares the 'data/data_ready.Rdata' object
- run traitspace_gen.R: this will use the content of 'data/data_ready.Rdata' to compute Traitspace and create 'data/traitspace_objs.Rdata'
- run assembly_models.R: this script will run the Banquo models (more details of its functioning in the header of the script). after the models are run, the script saves the output in the 'posterior_objs.Rdata' objects
- run analysis_results.R: this script uses the posterior_objs.Rdata, the functions in ./lib/ and the objects in ./data/ to create the figures and the table from the article and the supplementary materials.