Beyond single-species models: leveraging multispecies forecasts to navigate the dynamics of ecological predictability
This repository contains R code to extract data and replicate analyses in the manuscript titled Beyond single-species models: leveraging multispecies forecasts to navigate the dynamics of ecological predictability (currently in In-Press; a preprint of a previous version is hosted on biorxiv at the following DOI: https://doi.org/10.32942/X2TS34). This work shows how to build and interrogate multivariate Dynamic Generalized Additive Models (DGAMs) that can simultaneously learn useful multispecies dependencies and shared environmental effects, while also producing reliable probabilistic forecasts (the core model of the paper is presented in its full mathematical form above).
portalcasting
tidyverse
forecast
cmdstanr
(and Cmdstan
)
mvgam
scoringRules
extraDistr
nleqslv
Raw rodent capture and covariate data have already been downloaded from the latest version of the portalr
database and extracted to the data
directory. Data can be prepared for analysis / modeling following instructions in the 1.prep_data.R
script. Models are built using the mvgam
R package in the 2.models.R
script. Note that a working version of Stan
is required to condition models on observed data, along with either the cmdstanr
or rstan
interface. This script will produce large model objects (stored as class mvgam
) that unfortunately cannot be uploaded to Github
due to their size. Analysis of these models is completed in the 3.analysis.R
script. Figures are produced throughout the workflow. All of these figures are stored in the Figures
directory.
If you are interested in using the mvgam
package to build similar analyses, you may be interested in looking over some of the other resources that are publically available. A series of vignettes cover data formatting, forecasting and several extended case studies of DGAMs. A number of other examples have also been compiled:
- Ecological Forecasting with Dynamic Generalized Additive Models
- Distributed lags (and hierarchical distributed lags)
using
mgcv
andmvgam
- State-Space Vector Autoregressions in
mvgam
- Ecological Forecasting with Dynamic GAMs; a tutorial and detailed case study
- How to interpret and report nonlinear effects from Generalized Additive Models
- Introduction to Stan and Hamiltonian Monte Carlo
- Phylogenetic smoothing using
mgcv
- Incorporating time-varying seasonality in forecast models