This function use coefficients $$(\lambda_{jl}$$ with $$j=1,\dots,n_{species}$$ and $$l=1,\dots,n_{latent})$$, corresponding to latent variables fitted using jSDM package, to calculate the variance-covariance matrix which controls correlation between species.

get_residual_cor(mod, prob = 0.95, type = "mean")

## Arguments

mod

An object of class "jSDM"

prob

A numeric scalar in the interval $$(0,1)$$ giving the target probability coverage of the highest posterior density (HPD) intervals, by which to determine whether the correlations are "significant". Defaults to 0.95.

type

A choice of either the posterior median (type = "median") or posterior mean (type = "mean"), which are then treated as estimates and the fitted values are calculated from. Default is posterior mean.

## Value

results A list including :

cov.mean

Average over the MCMC samples of the variance-covariance matrix, if type = "mean".

cov.median

Median over the MCMC samples of the variance-covariance matrix, if type = "median".

cov.lower

A $$n_{species} \times n_{species}$$ matrix containing the lower limits of the ($$100 \times prob \%$$) HPD interval of variance-covariance matrices over the MCMC samples.

cov.upper

A $$n_{species} \times n_{species}$$ matrix containing the upper limits of the ($$100 \times prob \%$$) HPD interval of variance-covariance matrices over the MCMC samples.

cov.sig

A $$n_{species} \times n_{species}$$ matrix containing the value 1 corresponding to the “significant" co-variances and the value 0 corresponding to "non-significant" co-variances, whose ($$100 \times prob \%$$) HPD interval over the MCMC samples contain zero.

cor.mean

Average over the MCMC samples of the residual correlation matrix, if type = "mean".

cor.median

Median over the MCMC samples of the residual correlation matrix, if type = "median".

cor.lower

A $$n_{species} \times n_{species}$$ matrix containing the lower limits of the ($$100 \times prob \%$$) HPD interval of correlation matrices over the MCMC samples.

cor.upper

A $$n_{species} \times n_{species}$$ matrix containing the upper limits of the ($$100 \times prob \%$$) HPD interval of correlation matrices over the MCMC samples.

cor.sig

A $$n_{species} \times n_{species}$$ matrix containing the value $$1$$ corresponding to the “significant" correlations and the value $$0$$ corresponding to "non-significant" correlations, whose ($$100 \times prob \%$$) HPD interval over the MCMC samples contain zero.

## Details

After fitting the jSDM with latent variables, the fullspecies residual correlation matrix : $$R=(R_{ij})$$ with $$i=1,\ldots, n_{species}$$ and $$j=1,\ldots, n_{species}$$ can be derived from the covariance in the latent variables such as : $$\Sigma_{ij}=\lambda_i' .\lambda_j$$, in the case of a regression with probit, logit or poisson link function and

 $$\Sigma_{ij}$$ $$= \lambda_i' .\lambda_j + V$$ if i=j $$= \lambda_i' .\lambda_j$$ else,

, in the case of a linear regression with a response variable such as $$y_{ij} \sim \mathcal{N}(\theta_{ij}, V)$$. Then we compute correlations from covariances : $$R_{ij} = \frac{\Sigma_{ij}}{\sqrt{\Sigma_ii\Sigma _jj}}$$.

## References

Hui FKC (2016). “boral: Bayesian Ordination and Regression Analysis of Multivariate Abundance Data in R.” Methods in Ecology and Evolution, 7, 744–750.

Ovaskainen et al. (2016). Using latent variable models to identify large networks of species-to-species associations at different spatial scales. Methods in Ecology and Evolution, 7, 549-555.

Pollock et al. (2014). Understanding co-occurrence by modelling species simultaneously with a Joint Species Distribution Model (JSDM). Methods in Ecology and Evolution, 5, 397-406.

get_enviro_cor cov2cor jSDM-package jSDM_binomial_probit
jSDM_binomial_logit jSDM_poisson_log

## Author

Jeanne Clément <jeanne.clement16@laposte.net>

## Examples

library(jSDM)
# frogs data
data(frogs, package="jSDM")
# Arranging data
PA_frogs <- frogs[,4:12]
# Normalized continuous variables
Env_frogs <- cbind(scale(frogs[,1]),frogs[,2],scale(frogs[,3]))
colnames(Env_frogs) <- colnames(frogs[,1:3])
Env_frogs <- as.data.frame(Env_frogs)
# Parameter inference
# Increase the number of iterations to reach MCMC convergence
mod <- jSDM_binomial_probit(# Response variable
presence_data=PA_frogs,
# Explanatory variables
site_formula = ~.,
site_data = Env_frogs,
n_latent=2,
site_effect="random",
# Chains
burnin=100,
mcmc=100,
thin=1,
# Starting values
alpha_start=0,
beta_start=0,
lambda_start=0,
W_start=0,
V_alpha=1,
# Priors
shape=0.5, rate=0.0005,
mu_beta=0, V_beta=10,
mu_lambda=0, V_lambda=10,
# Various
seed=1234, verbose=1)
#>
#> Running the Gibbs sampler. It may be long, please keep cool :)
#>
#> **********:10.0%
#> **********:20.0%
#> **********:30.0%
#> **********:40.0%
#> **********:50.0%
#> **********:60.0%
#> **********:70.0%
#> **********:80.0%
#> **********:90.0%
#> **********:100.0%
# Calcul of residual correlation between species
result <- get_residual_cor(mod, prob=0.95, type="mean")
# Residual variance-covariance matrix
result$cov.mean #> Species_1 Species_2 Species_3 Species_4 Species_5 #> Species_1 0.028882131 -0.007876559 0.08220418 0.18384738 -0.008027271 #> Species_2 -0.007876559 0.367200198 0.82346255 0.01437305 0.379920798 #> Species_3 0.082204178 0.823462549 3.35852148 1.71555915 1.038780504 #> Species_4 0.183847379 0.014373054 1.71555915 2.89713642 0.116703121 #> Species_5 -0.008027271 0.379920798 1.03878050 0.11670312 0.779678995 #> Species_6 -0.380756673 1.202074627 1.04783316 -4.01290471 1.801916964 #> Species_7 0.036067746 0.786744431 2.78418552 1.10364837 1.030318732 #> Species_8 0.123436082 -0.574512512 -1.31553229 0.76552561 -0.824785809 #> Species_9 -0.132112143 0.921255028 1.95813704 -1.01358469 1.423499466 #> Species_6 Species_7 Species_8 Species_9 #> Species_1 -0.3807567 0.03606775 0.1234361 -0.1321121 #> Species_2 1.2020746 0.78674443 -0.5745125 0.9212550 #> Species_3 1.0478332 2.78418552 -1.3155323 1.9581370 #> Species_4 -4.0129047 1.10364837 0.7655256 -1.0135847 #> Species_5 1.8019170 1.03031873 -0.8247858 1.4234995 #> Species_6 13.1758198 1.95292660 -4.8547872 6.5710297 #> Species_7 1.9529266 2.55760755 -1.4172268 2.1176336 #> Species_8 -4.8547872 -1.41722685 2.4062094 -2.9009848 #> Species_9 6.5710297 2.11763361 -2.9009848 4.3619168 ## All non-significant co-variances are set to zero. result$cov.mean * result$cov.sig #> Species_1 Species_2 Species_3 Species_4 Species_5 Species_6 #> Species_1 0.02888213 0.0000000 0.08220418 0.1838474 0.000000 -0.3807567 #> Species_2 0.00000000 0.3672002 0.00000000 0.0000000 0.000000 0.0000000 #> Species_3 0.08220418 0.0000000 3.35852148 1.7155592 0.000000 0.0000000 #> Species_4 0.18384738 0.0000000 1.71555915 2.8971364 0.000000 -4.0129047 #> Species_5 0.00000000 0.0000000 0.00000000 0.0000000 0.779679 0.0000000 #> Species_6 -0.38075667 0.0000000 0.00000000 -4.0129047 0.000000 13.1758198 #> Species_7 0.00000000 0.7867444 2.78418552 1.1036484 0.000000 0.0000000 #> Species_8 0.00000000 -0.5745125 0.00000000 0.0000000 0.000000 -4.8547872 #> Species_9 -0.13211214 0.0000000 1.95813704 -1.0135847 0.000000 6.5710297 #> Species_7 Species_8 Species_9 #> Species_1 0.0000000 0.0000000 -0.1321121 #> Species_2 0.7867444 -0.5745125 0.0000000 #> Species_3 2.7841855 0.0000000 1.9581370 #> Species_4 1.1036484 0.0000000 -1.0135847 #> Species_5 0.0000000 0.0000000 0.0000000 #> Species_6 0.0000000 -4.8547872 6.5710297 #> Species_7 2.5576076 -1.4172268 2.1176336 #> Species_8 -1.4172268 2.4062094 -2.9009848 #> Species_9 2.1176336 -2.9009848 4.3619168 # Residual correlation matrix result$cor.mean
#>            Species_1  Species_2  Species_3   Species_4   Species_5  Species_6
#> Species_1  1.0000000 -0.1157965  0.3637105  0.94087343 -0.13250838 -0.8370988
#> Species_2 -0.1157965  1.0000000  0.7610573  0.11203503  0.73890278  0.5629377
#> Species_3  0.3637105  0.7610573  1.0000000  0.59980324  0.67624278  0.1655734
#> Species_4  0.9408734  0.1120350  0.5998032  1.00000000  0.09156971 -0.6619474
#> Species_5 -0.1325084  0.7389028  0.6762428  0.09156971  1.00000000  0.5139653
#> Species_6 -0.8370988  0.5629377  0.1655734 -0.66194740  0.51396526  1.0000000
#> Species_7  0.1865062  0.8292752  0.9651355  0.44529188  0.75206487  0.3439489
#> Species_8  0.5742101 -0.7128102 -0.5101016  0.33582748 -0.66523534 -0.8892332
#> Species_9 -0.6094300  0.7456524  0.4947714 -0.35522034  0.71225801  0.9091314
#>            Species_7  Species_8  Species_9
#> Species_1  0.1865062  0.5742101 -0.6094300
#> Species_2  0.8292752 -0.7128102  0.7456524
#> Species_3  0.9651355 -0.5101016  0.4947714
#> Species_4  0.4452919  0.3358275 -0.3552203
#> Species_5  0.7520649 -0.6652353  0.7122580
#> Species_6  0.3439489 -0.8892332  0.9091314
#> Species_7  1.0000000 -0.6457013  0.6451032
#> Species_8 -0.6457013  1.0000000 -0.9473237
#> Species_9  0.6451032 -0.9473237  1.0000000
## All non-significant correlations are set to zero.
result$cor.mean * result$cor.sig
#>            Species_1  Species_2  Species_3  Species_4 Species_5  Species_6
#> Species_1  1.0000000  0.0000000  0.3637105  0.9408734 0.0000000 -0.8370988
#> Species_2  0.0000000  1.0000000  0.0000000  0.0000000 0.0000000  0.0000000
#> Species_3  0.3637105  0.0000000  1.0000000  0.5998032 0.0000000  0.0000000
#> Species_4  0.9408734  0.0000000  0.5998032  1.0000000 0.0000000 -0.6619474
#> Species_5  0.0000000  0.0000000  0.0000000  0.0000000 1.0000000  0.0000000
#> Species_6 -0.8370988  0.0000000  0.0000000 -0.6619474 0.0000000  1.0000000
#> Species_7  0.0000000  0.8292752  0.9651355  0.4452919 0.7520649  0.0000000
#> Species_8  0.0000000 -0.7128102 -0.5101016  0.0000000 0.0000000 -0.8892332
#> Species_9 -0.6094300  0.7456524  0.4947714 -0.3552203 0.0000000  0.9091314
#>            Species_7  Species_8  Species_9
#> Species_1  0.0000000  0.0000000 -0.6094300
#> Species_2  0.8292752 -0.7128102  0.7456524
#> Species_3  0.9651355 -0.5101016  0.4947714
#> Species_4  0.4452919  0.0000000 -0.3552203
#> Species_5  0.7520649  0.0000000  0.0000000
#> Species_6  0.0000000 -0.8892332  0.9091314
#> Species_7  1.0000000 -0.6457013  0.6451032
#> Species_8 -0.6457013  1.0000000 -0.9473237
#> Species_9  0.6451032 -0.9473237  1.0000000