R code and packages
MRFcov: Markov Random Fields with additional covariates in R
I co-developed and maintain the MRFcov R package (described by Clark et al, published in Ecology’s Statistical Reports Section), which provides some of the best statistical tools for detecting how network interactions change over time or across environmental gradients. You can download the article PDF here. In short, the package’s primary functions are used for approximating interaction parameters of nodes in undirected Markov Random Fields (MRF) graphical networks. Models can incorporate covariates (a class of models known as Conditional Random Fields; CRFs; following methods developed by Cheng et al 2014), allowing users to estimate how interactions between nodes are predicted to change across covariate gradients.
In principle, MRFcov models that use species' occurrences as outcome variables are similar to joint species distribution models (see here for a nice review of these models, and here for an example that my coauthors and I published) in that variance in occurrences can be partitioned among abiotic and biotic drivers. However, key differences are that MRFcov models can:
(1) Produce directly interpretable coefficients that allow users to determine the relative importances (i.e. effect sizes) of species' interactions and environmental covariates in driving occurrence probabilities
(2) Identify interaction strengths, rather than simply determining whether they are "significantly different from zero"
(3) Estimate how interactions are predicted to change across environmental gradients
MRF and CRF interaction parameters are approximated using separate regressions for individual species within a joint modelling framework. Because all combinations of covariates and additional species are included as predictor variables in node-specific regressions, variable selection is required to reduce overfitting and add sparsity. This is accomplished through LASSO penalization using functions in the penalized and glmnet R packages. Methods such as this could be increasingly important as habitat modification and climate change continue to disrupt natural communities. You can easily install the package from GitHub (make sure that the devtools package is installed first) using:
Then, follow the vignettes to get started:
vignette("CRF_data_prep") and vignette("Bird_Parasite_CRF")
Please give the package a run and start gleaning additional insights from your multi-species community datasets!
MalAvi Global Biogeography R Code
Here at my figshare account, I have provided all R code (including a range of useful functions) that I developed for my recent paper in Global Ecology and Biogeography (get the PDF here). These functions build on code written by Dr Vincenzo Ellis for the malaviR package to download avian blood parasite occurrence and cytochrome-b sequence data from the MalAvi database. I then demonstrate how to estimate phylogenetic diversity for parasite communities and use hierarchical linear models to carry out global-scale analyses of community phylogenetic turnover.
In my view, this packaging of all R code, including the functions needed to download data, represents a much-needed step forward to generating more reproducible research. Please let me know if you have comments or plan to use the functions in your own research, I’m very happy to chat about ideas for projects.