Crandore Hub

sjSDM

Scalable Joint Species Distribution Modeling

A scalable and fast method for estimating joint Species Distribution Models (jSDMs) for big community data, including eDNA data. The package estimates a full (i.e. non-latent) jSDM with different response distributions (including the traditional multivariate probit model). The package allows to perform variation partitioning (VP) / ANOVA on the fitted models to separate the contribution of environmental, spatial, and biotic associations. In addition, the total R-squared can be further partitioned per species and site to reveal the internal metacommunity structure, see Leibold et al., <doi:10.1111/oik.08618>. The internal structure can then be regressed against environmental and spatial distinctiveness, richness, and traits to analyze metacommunity assembly processes. The package includes support for accounting for spatial autocorrelation and the option to fit responses using deep neural networks instead of a standard linear predictor. As described in Pichler & Hartig (2021) <doi:10.1111/2041-210X.13687>, scalability is achieved by using a Monte Carlo approximation of the joint likelihood implemented via 'PyTorch' and 'reticulate', which can be run on CPUs or GPUs.

README

# sjSDM - Fast and Accurate Joint Species distribution Modeling 

Currently we don't provide specifically a API for joint species distribution models. However, it's just a deep multivariate probit model with one layer (example below).

We provide a R package with an API focused on JSDMs which is available [here](https://github.com/TheoreticalEcology/s-jSDM).

References:
* [Pichler, M., & Hartig, F. (2020). A new method for faster and more accurate inference of species associations from novel community data. arXiv preprint arXiv:2003.05331.](https://arxiv.org/abs/2003.05331)


## Install instructions

Dependencies:
* PyTorch >= 1.7, see [PyTorch](https://pytorch.org/get-started/locally/) for install instructions.

```{python}
pip install sjSDM_py
```

## Example

linear jSDM:
```{python}
import sjSDM_py as sa
import numpy as np
Env = np.random.randn(100, 5)
Occ = np.random.binomial(1, 0.5, [100, 10])

model = sa.Model_base(5) # input_shape == number of environmental predictors
model.add_layer(sa.layers.Layer_dense(hidden=10)) # number of hidden units in the layer == number of species
model.build(df=5, optimizer=sa.optimizer_adamax(lr=0.1, weight_decay = 0.01)) # df = degree of freedom 
model.fit(X = Env, Y = Occ)
print(model.weights_numpy)
print(model.get_cov())
```

* For species intercept, use 'bias=True' in 'Layer_dense(...)'. 
* We recommend setting 'df = number of species / 2.'

Versions across snapshots

VersionRepositoryFileSize
1.0.7 rolling linux/jammy R-4.5 sjSDM_1.0.7.tar.gz 1.1 MiB
1.0.7 rolling linux/noble R-4.5 sjSDM_1.0.7.tar.gz 1.1 MiB
1.0.7 rolling source/ R- sjSDM_1.0.7.tar.gz 1.2 MiB
1.0.7 latest linux/jammy R-4.5 sjSDM_1.0.7.tar.gz 1.1 MiB
1.0.7 latest linux/noble R-4.5 sjSDM_1.0.7.tar.gz 1.1 MiB
1.0.7 latest source/ R- sjSDM_1.0.7.tar.gz 1.2 MiB
1.0.7 2026-04-26 source/ R- sjSDM_1.0.7.tar.gz 1.2 MiB
1.0.7 2026-04-23 source/ R- sjSDM_1.0.7.tar.gz 1.2 MiB
1.0.7 2026-04-09 windows/windows R-4.5 sjSDM_1.0.7.zip 1.1 MiB
1.0.6 2025-04-20 source/ R- sjSDM_1.0.6.tar.gz 1.2 MiB

Dependencies (latest)

Imports

Suggests