get_residual_cor {jSDM} | R Documentation |
Calculate the residual correlation matrix from a latent variable model (LVM)
Description
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.
Usage
get_residual_cor(mod, prob = 0.95, type = "mean")
Arguments
mod |
An object of class |
prob |
A numeric scalar in the interval |
type |
A choice of either the posterior median ( |
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}}
.
Value
results A list including :
cov.mean |
Average over the MCMC samples of the variance-covariance matrix, if |
cov.median |
Median over the MCMC samples of the variance-covariance matrix, if |
cov.lower |
A |
cov.upper |
A |
cov.sig |
A |
cor.mean |
Average over the MCMC samples of the residual correlation matrix, if |
cor.median |
Median over the MCMC samples of the residual correlation matrix, if |
cor.lower |
A |
cor.upper |
A |
cor.sig |
A |
Author(s)
Ghislain Vieilledent <ghislain.vieilledent@cirad.fr>
Jeanne Clément <jeanne.clement16@laposte.net>
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 and 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 and al. (2014). Understanding co-occurrence by modelling species simultaneously with a Joint Species Distribution Model (JSDM). Methods in Ecology and Evolution, 5, 397-406.
See Also
get_enviro_cor
cov2cor
jSDM-package
jSDM_binomial_probit
jSDM_binomial_logit
jSDM_poisson_log
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)
# Calcul of residual correlation between species
result <- get_residual_cor(mod, prob=0.95, type="mean")
# Residual variance-covariance matrix
result$cov.mean
## All non-significant co-variances are set to zero.
result$cov.mean * result$cov.sig
# Residual correlation matrix
result$cor.mean
## All non-significant correlations are set to zero.
result$cor.mean * result$cor.sig