Skip to content

Latest commit

 

History

History
57 lines (41 loc) · 2.33 KB

README.md

File metadata and controls

57 lines (41 loc) · 2.33 KB

jsdmstan: joint Species Distribution Models in Stan

R-CMD-check Codecov test coverage Lifecycle: experimental

This is an R package for running joint Species Distribution Models (jSDM) in Stan. jSDMs are models where multiple response variables (i.e. species) are fit at the same time, and the covariance between these species are used to inform the model results. For a review of jSDMs see Warton et al. (2015) So many variables: joint modelling in community ecology. TREE, 30:766-779 DOI: 10.1016/j.tree.2015.09.007.

This package can fit data to a Multivariate Generalised Linear Mixed Model (MGLMM) or a Generalised Linear Latent Variable Model (GLLVM), and also provides functionality for simulating data under these scenarios and an interface to the bayesplot package for a wide variety of plotting options.

Installation

This package can be installed using the remotes package using the following code:

# install.packages("remotes")
remotes::install_github("NERC-CEH/jsdmstan")

Using jsdmstan

Example code:

library(jsdmstan)

Simulate data:

nsites <- 200
nspecies <- 9
ncovar <- 2
mglmm_test_data <- mglmm_sim_data(N = nsites, S = nspecies, 
                                  K = ncovar, family = "pois")

Fit Stan model:

dat <- as.data.frame(mglmm_test_data$X)
mglmm_fit <- stan_jsdm(~ V1 + V2, data = dat, Y = mglmm_test_data$Y, 
                       family = "pois", method = "mglmm")

Plot results:

plot(mglmm_fit)
mcmc_plot(mglmm_fit, plotfun = "rhat_hist")

This work was funded by the Natural Environment Research Council (part of UK Research and Innovation) under the UK-SCAPE Programme delivering National Capability (Grant Reference NE/R016429/1).

UKCEH logo UKSCAPE logo